Module: VaultPlugin::Helpers
- Included in:
- API::Backend, API::Backend::Client
- Defined in:
- lib/smart_proxy_vault/helpers.rb
Instance Method Summary collapse
- #add_token_metadata? ⇒ Boolean
- #settings_ttl ⇒ Object
- #to_seconds(string) ⇒ Object
- #token_options ⇒ Object
-
#valid_ttl?(ttl) ⇒ Boolean
Only allow clients to specify a TTL that is shorter than the default.
- #vault_client_configure ⇒ Object
- #vault_settings ⇒ Object
Instance Method Details
#add_token_metadata? ⇒ Boolean
15 16 17 |
# File 'lib/smart_proxy_vault/helpers.rb', line 15 def ::VaultPlugin::Plugin.settings. end |
#settings_ttl ⇒ Object
7 8 9 |
# File 'lib/smart_proxy_vault/helpers.rb', line 7 def settings_ttl ::VaultPlugin::Plugin.settings.[:ttl] end |
#to_seconds(string) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smart_proxy_vault/helpers.rb', line 27 def to_seconds(string) case string.slice(-1) when 'd' string.tr('d', '').to_i * 24 * 3600 when 'h' string.tr('h', '').to_i * 3600 when 'm' string.tr('m', '').to_i * 60 when 's' string.tr('s', '').to_i else log_halt 400, "Invalid TTL - #{string}. Must end with 'd', 'h', 'm' or 's'." end end |
#token_options ⇒ Object
11 12 13 |
# File 'lib/smart_proxy_vault/helpers.rb', line 11 def ::VaultPlugin::Plugin.settings. end |
#valid_ttl?(ttl) ⇒ Boolean
Only allow clients to specify a TTL that is shorter than the default
43 44 45 46 47 48 49 |
# File 'lib/smart_proxy_vault/helpers.rb', line 43 def valid_ttl?(ttl) return true if ttl.nil? || settings_ttl.nil? unless (to_seconds(settings_ttl) >= to_seconds(ttl)) log_halt 400, "Invalid TTL - #{ttl}. Must be shorter or equal to #{settings_ttl}." end true end |
#vault_client_configure ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/smart_proxy_vault/helpers.rb', line 19 def vault_client_configure Vault.configure do |config| vault_settings.each do |k, v| config.send("#{k}=", v) end end end |
#vault_settings ⇒ Object
3 4 5 |
# File 'lib/smart_proxy_vault/helpers.rb', line 3 def vault_settings ::VaultPlugin::Plugin.settings.vault end |