Class: SettingsReader::VaultResolver::Entry
- Inherits:
-
Object
- Object
- SettingsReader::VaultResolver::Entry
- Defined in:
- lib/settings_reader/vault_resolver/entry.rb
Overview
Wrapper around vault secret object
Constant Summary collapse
- MONTH =
30 * 60 * 60
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #expired? ⇒ Boolean
- #expires_in ⇒ Object
-
#initialize(address, secret) ⇒ Entry
constructor
A new instance of Entry.
- #lease_duration ⇒ Object
- #lease_id ⇒ Object
- #leased? ⇒ Boolean
- #renewable? ⇒ Boolean
- #to_s ⇒ Object
- #update_renewed(new_secret) ⇒ Object
- #value_for(attribute) ⇒ Object
Constructor Details
#initialize(address, secret) ⇒ Entry
Returns a new instance of Entry.
9 10 11 12 13 14 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 9 def initialize(address, secret) @address = address @secret = secret @data = extract_data(secret) @lease_started = Time.now end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 5 def address @address end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 5 def data @data end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
5 6 7 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 5 def secret @secret end |
Instance Method Details
#active? ⇒ Boolean
30 31 32 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 30 def active? !expired? end |
#expired? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 24 def expired? return false unless leased? Time.now > @lease_started + lease_duration end |
#expires_in ⇒ Object
34 35 36 37 38 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 34 def expires_in return MONTH unless leased? @lease_started + lease_duration - Time.now end |
#lease_duration ⇒ Object
61 62 63 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 61 def lease_duration @secret.lease_duration.to_i end |
#lease_id ⇒ Object
40 41 42 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 40 def lease_id @secret.lease_id end |
#leased? ⇒ Boolean
20 21 22 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 20 def leased? renewable? || @secret.lease_duration&.positive? end |
#renewable? ⇒ Boolean
16 17 18 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 16 def renewable? @secret.renewable? end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 57 def to_s address.to_s end |
#update_renewed(new_secret) ⇒ Object
44 45 46 47 48 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 44 def update_renewed(new_secret) @secret = new_secret @data = @data.merge(extract_data(new_secret).compact) @lease_started = Time.now end |
#value_for(attribute) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/settings_reader/vault_resolver/entry.rb', line 50 def value_for(attribute) return data[attribute.to_sym] if data.key?(attribute.to_sym) return secret.public_send(attribute) if secret.respond_to?(attribute) nil end |