Module: VaultPlugin::Helpers

Included in:
API::Backend, API::Backend::Client
Defined in:
lib/smart_proxy_vault/helpers.rb

Instance Method Summary collapse

Instance Method Details

#add_token_metadata?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/smart_proxy_vault/helpers.rb', line 15

def add_token_metadata?
  ::VaultPlugin::Plugin.settings.
end

#settings_ttlObject



7
8
9
# File 'lib/smart_proxy_vault/helpers.rb', line 7

def settings_ttl
  ::VaultPlugin::Plugin.settings.token_options[: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_optionsObject



11
12
13
# File 'lib/smart_proxy_vault/helpers.rb', line 11

def token_options
  ::VaultPlugin::Plugin.settings.token_options
end

#valid_ttl?(ttl) ⇒ Boolean

Only allow clients to specify a TTL that is shorter than the default

Returns:

  • (Boolean)


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_configureObject



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_settingsObject



3
4
5
# File 'lib/smart_proxy_vault/helpers.rb', line 3

def vault_settings
  ::VaultPlugin::Plugin.settings.vault
end