Class: SettingsReader::VaultResolver::Refresher
- Inherits:
-
Object
- Object
- SettingsReader::VaultResolver::Refresher
- Includes:
- Logging
- Defined in:
- lib/settings_reader/vault_resolver/refresher.rb
Overview
Vault Lease refresher task
Constant Summary collapse
- DEFAULT_RENEW_DELAY =
200
- REFRESH_INTERVAL =
60
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(cache, config) ⇒ Refresher
constructor
A new instance of Refresher.
- #refresh ⇒ Object
- #refresh_entry(entry) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(cache, config) ⇒ Refresher
Returns a new instance of Refresher.
14 15 16 17 |
# File 'lib/settings_reader/vault_resolver/refresher.rb', line 14 def initialize(cache, config) @cache = cache @config = config end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
12 13 14 |
# File 'lib/settings_reader/vault_resolver/refresher.rb', line 12 def cache @cache end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/settings_reader/vault_resolver/refresher.rb', line 12 def config @config end |
Instance Method Details
#refresh ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/settings_reader/vault_resolver/refresher.rb', line 19 def refresh info { 'Performing Vault leases refresh' } promises = cache.active_entries.map do |entry| debug { "Checking lease for #{entry}. Renewable?: #{entry.renewable?}. Expires in: #{entry.expires_in}s" } refresh_entry(entry) end.compact promises.each(&:wait) promises end |
#refresh_entry(entry) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/settings_reader/vault_resolver/refresher.rb', line 29 def refresh_entry(entry) return unless entry.expires_in < config.lease_renew_delay Concurrent::Promise.execute do debug { "Refreshing lease for #{entry}. Expires in: #{entry.expires_in}" } config.vault_engine_for(entry.address).renew(entry) info { "Lease renewed for #{entry}. Expires in: #{entry.expires_in}" } entry rescue StandardError => e handle_refresh_error(e, entry) end end |