Module: Aspera::Cli::VaultManager

Included in:
Plugins::Config
Defined in:
lib/aspera/cli/vault_manager.rb

Overview

Mixin providing vault/keychain functionality to Plugin::Config. Depends on options and context.main_folder being available in the including class.

Instance Method Summary collapse

Instance Method Details

#action_vault_create(info:) ⇒ Object



16
17
18
19
# File 'lib/aspera/cli/vault_manager.rb', line 16

def action_vault_create(info:, **)
  vault.set(info.symbolize_keys)
  Result::Status.new('Secret added')
end

#action_vault_delete(label:) ⇒ Object



21
22
23
24
# File 'lib/aspera/cli/vault_manager.rb', line 21

def action_vault_delete(label:, **)
  vault.delete(label: label)
  Result::Status.new("Secret deleted: #{label}")
end

#action_vault_password(new_password:) ⇒ Object



26
27
28
29
30
# File 'lib/aspera/cli/vault_manager.rb', line 26

def action_vault_password(new_password:, **)
  Aspera.assert(vault.respond_to?(:change_password), 'Vault does not support password change')
  vault.change_password(new_password)
  Result::Status.new('Vault password updated')
end

#action_vault_show(label:) ⇒ Object



12
13
14
# File 'lib/aspera/cli/vault_manager.rb', line 12

def action_vault_show(label:, **)
  Result::SingleObject.new(vault.get(label: label))
end

#vaultKeychain::Base

Returns vault instance, lazily created from options.

Returns:

  • vault instance, lazily created from options



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/aspera/cli/vault_manager.rb', line 43

def vault
  return @vault_instance unless @vault_instance.nil?
  info = options.get_option(:vault, mandatory: true).symbolize_keys
  info[:type] ||= 'file'
  require 'aspera/keychain/factory'
  @vault_instance = Keychain::Factory.create(
    info,
    Info::CMD_NAME,
    context.main_folder,
    options.get_option(:vault_password)
  )
end

#vault_value(name) ⇒ String

Returns value from vault matching ..

Returns:

  • value from vault matching .



33
34
35
36
37
38
39
40
# File 'lib/aspera/cli/vault_manager.rb', line 33

def vault_value(name)
  m = name.split('.')
  Aspera.assert(m.length.eql?(2), type: BadArgument){'vault name shall match <name>.<param>'}
  info = vault.get(label: m[0])
  value = info[m[1].to_sym]
  raise "no such entry value: #{m[1]}" if value.nil?
  return value
end