module VaultPlugin::Helpers

Public Instance Methods

add_token_metadata?() click to toggle source
# File lib/smart_proxy_vault/helpers.rb, line 15
def add_token_metadata?
  ::VaultPlugin::Plugin.settings.add_token_metadata
end
settings_ttl() click to toggle source
# File lib/smart_proxy_vault/helpers.rb, line 7
def settings_ttl
  ::VaultPlugin::Plugin.settings.token_options[:ttl]
end
to_seconds(string) click to toggle source
# 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() click to toggle source
# File lib/smart_proxy_vault/helpers.rb, line 11
def token_options
  ::VaultPlugin::Plugin.settings.token_options
end
valid_ttl?(ttl) click to toggle source

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

# 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() click to toggle source
# 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() click to toggle source
# File lib/smart_proxy_vault/helpers.rb, line 3
def vault_settings
  ::VaultPlugin::Plugin.settings.vault
end