Class: SettingsReader::VaultResolver::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/settings_reader/vault_resolver/configuration.rb

Overview

Configurations for vault resolver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 45

def initialize
  @logger = Logger.new($stdout, level: Logger::ERROR)
  @retriable_errors = [OpenSSL::SSL::SSLError, Vault::HTTPConnectionError]
  @retrieval_retries = 2
  @lease_refresh_interval = 60
  @lease_renew_delay = 300
  @lease_renew_retries = 4
  @lease_renew_error_listener = ->(_result) {}
  @lease_renew_success_listener = ->(_result) {}
  @vault_initializer = -> {}
  @lease_not_found_handler = ->(_entry) {}
end

Instance Attribute Details

#lease_not_found_handlerObject

Block to be executed when “lease not found” error is raised Default: empty proc



43
44
45
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 43

def lease_not_found_handler
  @lease_not_found_handler
end

#lease_refresh_intervalObject

How often do we check if secret lease is about to expire Default: 60seconds



19
20
21
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 19

def lease_refresh_interval
  @lease_refresh_interval
end

#lease_renew_delayObject

Time before expiration when we try to renew the lease Default: 300seconds



23
24
25
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 23

def lease_renew_delay
  @lease_renew_delay
end

#lease_renew_error_listenerObject

Block to be executed when lease is not refreshed Default: empty proc



35
36
37
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 35

def lease_renew_error_listener
  @lease_renew_error_listener
end

#lease_renew_retriesObject

How many times to retry renew of the secret Default: 4



27
28
29
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 27

def lease_renew_retries
  @lease_renew_retries
end

#lease_renew_success_listenerObject

Block to be executed when lease is refreshed Default: empty proc



31
32
33
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 31

def lease_renew_success_listener
  @lease_renew_success_listener
end

#loggerObject

Logger for gem Default: Logger.new(STDOUT, level: Logger::ERROR)



7
8
9
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 7

def logger
  @logger
end

#retriable_errorsObject

What errors should be retried when connecting to vault Default: ‘Vault::HTTPConnectionError` and `OpenSSL::SSL::SSLError`



11
12
13
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 11

def retriable_errors
  @retriable_errors
end

#retrieval_retriesObject

How many times to retry retrieval of the secret Default: 2



15
16
17
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 15

def retrieval_retries
  @retrieval_retries
end

#vault_initializerObject

Block to be executed for initialization and authorization Default: empty proc



39
40
41
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 39

def vault_initializer
  @vault_initializer
end

Instance Method Details

#setup_lease_refresher(cache, previous_task = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 58

def setup_lease_refresher(cache, previous_task = nil)
  previous_task&.shutdown

  timer_task = Concurrent::TimerTask.new(execution_interval: lease_refresh_interval) do
    SettingsReader::VaultResolver::Refresher.new(cache, self).refresh
  end
  timer_task.add_observer(SettingsReader::VaultResolver::RefresherObserver.new(self))
  timer_task.execute
  timer_task
end

#vault_engine_for(address) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 78

def vault_engine_for(address)
  unless (engine = vault_engines.detect { |e| e.retrieves?(address) })
    raise SettingsReader::VaultResolver::Error, "Unknown engine for #{address}"
  end

  engine
end

#vault_enginesObject



69
70
71
72
73
74
75
76
# File 'lib/settings_reader/vault_resolver/configuration.rb', line 69

def vault_engines
  @vault_engines ||= [
    SettingsReader::VaultResolver::Engines::KV2.new(self),
    SettingsReader::VaultResolver::Engines::Database.new(self),
    SettingsReader::VaultResolver::Engines::Aws.new(self),
    SettingsReader::VaultResolver::Engines::Auth.new(self)
  ]
end