Module: VaultPlugin::API::Backend

Includes:
VaultPlugin::Authentication, Helpers
Defined in:
lib/smart_proxy_vault/api.rb

Defined Under Namespace

Classes: Client

Instance Method Summary collapse

Methods included from Helpers

#add_token_metadata?, #settings_ttl, #to_seconds, #token_options, #valid_ttl?, #vault_client_configure, #vault_settings

Methods included from VaultPlugin::Authentication

#auth_backend, #auth_module, #authorized?, #create_setting_accessors, #vault_client

Instance Method Details

#creation_ttlObject



55
56
57
# File 'lib/smart_proxy_vault/api.rb', line 55

def creation_ttl
  Client.lookup_self[:data][:creation_ttl]
end

#issue(ttl, role) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/smart_proxy_vault/api.rb', line 46

def issue(ttl, role)
  begin
    opts = options ttl
    role.nil? ? Client.issue_token(opts) : Client.issue_role_token(role, )
  rescue StandardError => e
    log_halt 500, 'Failed to generate Vault token ' + e.message
  end
end

#metadataObject



35
36
37
38
39
# File 'lib/smart_proxy_vault/api.rb', line 35

def 
  return {} unless add_token_metadata?
  { display_name: vault_client,
    meta: { client: vault_client, smartproxy_generated: true } }
end

#options(ttl) ⇒ Object



41
42
43
44
# File 'lib/smart_proxy_vault/api.rb', line 41

def options(ttl)
  options = .merge token_options
  options.merge(ttl: ttl) unless ttl.nil?
end

#renewObject



59
60
61
62
63
64
65
# File 'lib/smart_proxy_vault/api.rb', line 59

def renew
  begin
    Client.renew_self
  rescue StandardError => e
    puts 'Failed to renew Vault token ' + e.message
  end
end

#start_renewalObject



67
68
69
70
71
72
73
74
# File 'lib/smart_proxy_vault/api.rb', line 67

def start_renewal
  Thread.new do
    while true do
      renew
      sleep to_seconds(creation_ttl/3)
    end
  end
end