Class: SettingsReader::VaultResolver::Entry

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'lib/settings_reader/vault_resolver/entry.rb', line 5

def address
  @address
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/settings_reader/vault_resolver/entry.rb', line 5

def data
  @data
end

#secretObject (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

Returns:

  • (Boolean)


30
31
32
# File 'lib/settings_reader/vault_resolver/entry.rb', line 30

def active?
  !expired?
end

#expired?Boolean

Returns:

  • (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_inObject



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_durationObject



61
62
63
# File 'lib/settings_reader/vault_resolver/entry.rb', line 61

def lease_duration
  @secret.lease_duration.to_i
end

#lease_idObject



40
41
42
# File 'lib/settings_reader/vault_resolver/entry.rb', line 40

def lease_id
  @secret.lease_id
end

#leased?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/settings_reader/vault_resolver/entry.rb', line 20

def leased?
  renewable? || @secret.lease_duration&.positive?
end

#renewable?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/settings_reader/vault_resolver/entry.rb', line 16

def renewable?
  @secret.renewable?
end

#to_sObject



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