Class: Aspera::Keychain::HashicorpVault
- Defined in:
- lib/aspera/keychain/hashicorp_vault.rb
Overview
Manage secrets in a Hashicorp Vault
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
- #delete(label:) ⇒ Object
- #get(label:, exception: true) ⇒ Object
- #info ⇒ Object
-
#initialize(url:, token:) ⇒ HashicorpVault
constructor
A new instance of HashicorpVault.
- #list ⇒ Object
-
#set(options) ⇒ Object
Set a secret.
Methods inherited from Base
Constructor Details
#initialize(url:, token:) ⇒ HashicorpVault
Returns a new instance of HashicorpVault.
17 18 19 20 21 22 23 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 17 def initialize(url:, token:) super() Vault.configure do |config| config.address = url config.token = token end end |
Instance Method Details
#delete(label:) ⇒ Object
62 63 64 65 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 62 def delete(label:) path = path(label) Vault.logical.delete(path) end |
#get(label:, exception: true) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 53 def get(label:, exception: true) secret = Vault.logical.read(path(label)) if secret.nil? raise "Secret '#{label}' not found" if exception return end return secret.data[:data] end |
#info ⇒ Object
25 26 27 28 29 30 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 25 def info { url: Vault.address, password: Vault.auth_token } end |
#list ⇒ Object
32 33 34 35 36 37 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 32 def list = STORE_PATH.sub('/data/', '/metadata/') return Vault.logical.list().filter_map do |label| get(label: label).merge(label: label) end end |
#set(options) ⇒ Object
Set a secret
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aspera/keychain/hashicorp_vault.rb', line 41 def set() validate_set() label = .fetch(:label) data = { username: [:username], password: [:password], url: [:url], description: [:description] }.compact Vault.logical.write(path(label), data: data) end |