Class: Secret

Inherits:
Object
  • Object
show all
Defined in:
lib/arkana/models/secret.rb

Overview

Model used to hold the metadata for a secret, such as its env var key, its protocol key, its type, and encoded value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, protocol_key:, encoded_value:, type:) ⇒ Secret

Returns a new instance of Secret.



20
21
22
23
24
25
# File 'lib/arkana/models/secret.rb', line 20

def initialize(key:, protocol_key:, encoded_value:, type:)
  @key = key
  @protocol_key = protocol_key
  @encoded_value = encoded_value
  @type = type
end

Instance Attribute Details

#encoded_valueObject (readonly)

Encoded value, formatted as a string of comma-separated hexadecimal numbers, e.g. “0x94, 0x11, 0x1b, 0x6, 0x49, 0, 0xa7”



15
16
17
# File 'lib/arkana/models/secret.rb', line 15

def encoded_value
  @encoded_value
end

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/arkana/models/secret.rb', line 8

def key
  @key
end

#protocol_keyObject

The same string as the key, except without the “environment” suffix. Used in the declaration of the protocol that defines the environment secrets.



12
13
14
# File 'lib/arkana/models/secret.rb', line 12

def protocol_key
  @protocol_key
end

#typeObject (readonly)

The type of the variable, as a language-agnostic enum.



18
19
20
# File 'lib/arkana/models/secret.rb', line 18

def type
  @type
end

Instance Method Details

#environmentObject



27
28
29
30
31
32
# File 'lib/arkana/models/secret.rb', line 27

def environment
  return :global if key == protocol_key
  return key.delete_prefix(protocol_key) if key.start_with?(protocol_key)

  raise("Precondition failure: the protocol_key '#{protocol_key}' is not the same as the key '#{key}' nor is its prefix. This state shouldn't be possible.")
end