Class: ProxyRb::PasswordFetchers::VaultPasswordFetcher

Inherits:
BasicPasswordFetcher show all
Includes:
Contracts::Builtin, Contracts::Core
Defined in:
lib/proxy_rb/password_fetchers/vault_password_fetcher.rb

Overview

… from HashiCorp Vault

Instance Method Summary collapse

Constructor Details

#initialize(prefix:, client: ::Vault::Client.new(address: ENV['VAULT_ADDR'])) ⇒ VaultPasswordFetcher

Returns a new instance of VaultPasswordFetcher.

Parameters:

  • prefix (String)

    Prefix used to look up password for user name

  • client (Vault::Client) (defaults to: ::Vault::Client.new(address: ENV['VAULT_ADDR']))

    The client used to connect to central “Vault” server



30
31
32
33
# File 'lib/proxy_rb/password_fetchers/vault_password_fetcher.rb', line 30

def initialize(prefix:, client: ::Vault::Client.new(address: ENV['VAULT_ADDR']))
  @prefix = prefix
  @client = client
end

Instance Method Details

#call(user_name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/proxy_rb/password_fetchers/vault_password_fetcher.rb', line 38

def call(user_name)
  client.with_retries(::Vault::HTTPConnectionError, ::Vault::HTTPError) do |_attempt, _e|
    UserPasswords::VaultUserPassword.new(
      fetch_password_for_user(user_name)
    ).to_s
  end
end