Class: CredStash::Secret
- Inherits:
-
Object
- Object
- CredStash::Secret
- Defined in:
- lib/cred_stash/secret.rb
Instance Attribute Summary collapse
-
#encrypted_value ⇒ Object
readonly
Returns the value of attribute encrypted_value.
-
#hmac ⇒ Object
readonly
Returns the value of attribute hmac.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypted_value ⇒ Object
- #encrypt!(kms_key_id: nil) ⇒ Object
- #falsified? ⇒ Boolean
-
#initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil, context: {}) ⇒ Secret
constructor
A new instance of Secret.
- #save ⇒ Object
Constructor Details
#initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil, context: {}) ⇒ Secret
Returns a new instance of Secret.
4 5 6 7 8 9 10 11 |
# File 'lib/cred_stash/secret.rb', line 4 def initialize(name:, value: nil, key: nil, encrypted_value: nil, hmac: nil, context: {}) @name = name @value = value @key = key @encrypted_value = encrypted_value @hmac = hmac @context = context end |
Instance Attribute Details
#encrypted_value ⇒ Object (readonly)
Returns the value of attribute encrypted_value.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def encrypted_value @encrypted_value end |
#hmac ⇒ Object (readonly)
Returns the value of attribute hmac.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def hmac @hmac end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
2 3 4 |
# File 'lib/cred_stash/secret.rb', line 2 def value @value end |
Class Method Details
.find(name, context: {}) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/cred_stash/secret.rb', line 32 def find(name, context: {}) item = repository.get(name) new( name: name, key: CredStash::CipherKey.decrypt(Base64.decode64(item.key), context: context), encrypted_value: Base64.decode64(item.contents), hmac: item.hmac ) end |
.repository ⇒ Object
42 43 44 |
# File 'lib/cred_stash/secret.rb', line 42 def repository CredStash::Repository.instance end |
Instance Method Details
#decrypted_value ⇒ Object
27 28 29 |
# File 'lib/cred_stash/secret.rb', line 27 def decrypted_value @key.decrypt(@encrypted_value) end |
#encrypt!(kms_key_id: nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/cred_stash/secret.rb', line 13 def encrypt!(kms_key_id: nil) @key = CredStash::CipherKey.generate(kms_key_id: kms_key_id, context: @context) @encrypted_value = @key.encrypt(@value) @hmac = @key.hmac(@encrypted_value) end |
#falsified? ⇒ Boolean
23 24 25 |
# File 'lib/cred_stash/secret.rb', line 23 def falsified? @key.hmac(@encrypted_value) == @hmac end |
#save ⇒ Object
19 20 21 |
# File 'lib/cred_stash/secret.rb', line 19 def save self.class.repository.put(to_item) end |