lib/legion/crypt/vault.rb in legion-crypt-0.1.0 vs lib/legion/crypt/vault.rb in legion-crypt-0.2.0
- old
+ new
@@ -2,10 +2,11 @@
module Legion
module Crypt
module Vault
attr_accessor :sessions
+
def settings
Legion::Settings[:crypt][:vault]
end
def connect_vault # rubocop:disable Metrics/AbcSize
@@ -21,36 +22,42 @@
require_relative 'vault_renewer'
@renewer = Legion::Crypt::Vault::Renewer.new
end
- def read(path, type = 'kv-v2')
- lease = ::Vault.logical.read(type + '/' + path)
+ def read(path, type = 'legion')
+ full_path = type.nil? || type.empty? ? "#{type}/#{path}" : path
+ lease = ::Vault.logical.read(full_path)
add_session(path: lease.lease_id) if lease.respond_to? :lease_id
lease.data
end
def get(path)
- ::Vault.kv('kv-v2').read(path).data
+ result = ::Vault.kv('legion').read(path)
+ return nil if result.nil?
+
+ result.data
end
def write(path, key, value)
hash = {}
hash[key.to_sym] = value
- ::Vault.kv('kv-v2').write(path, **hash)
+ ::Vault.kv('legion').write(path, **hash)
end
def exist?(path)
- !::Vault.kv('kv-v2').read_metadata(path).nil?
+ !::Vault.kv('legion').read_metadata(path).nil?
end
def add_session(path:)
@sessions.push(path)
end
def close_sessions
Legion::Logging.info 'Closing all Legion::Crypt vault sessions'
+ return if @sessions.nil?
+
@sessions.each do |session|
close_session(session: session)
end
end
@@ -68,10 +75,10 @@
def renew_session(session:)
::Vault.sys.renew(session)
end
- def renew_sessions
+ def renew_sessions(**_opts)
@sessions.each do |session|
renew_session(session: session)
end
end
end