Class: Aspera::Cli::VaultManager
- Inherits:
-
Object
- Object
- Aspera::Cli::VaultManager
- Defined in:
- lib/aspera/cli/vault_manager.rb
Overview
Secrets of the vault, shared in Context#vault: read by @vault:, managed by config vault, written by presets.
Option vault: named stores (stores), the name of the default store (default) and the cache of references (cache_ttl), see Secret::Resolver.
<label>.<field>: secret of the default store, unlocked with optionvault_password, managed by label//<store>/<path>[?<options>][#<field>]: reference to a secret of a store, read only
Values @file:<path> in these options (e.g. token) are read by Secret::Bootstrap, not by ExtendedValue:
they are checked here as extended value @file:, so that option security applies (e.g. in MCP server mode).
Constant Summary collapse
- REFERENCE_PREFIX =
Beginning of a reference after
@vault:,secret://withoutsecret: '//'
Class Method Summary collapse
-
.convert_option(value) ⇒ Hash
Value of option
vaultwhen set (convertof option): the parameters of one store (deprecated) are a store named after its type, which is the default store.
Instance Method Summary collapse
-
#fields(label) ⇒ Array<String>
Field names of a secret of the default store, without values.
-
#initialize(options, main_folder) ⇒ VaultManager
constructor
A new instance of VaultManager.
-
#metadata(name) ⇒ Hash
Checks that a reference can be read, without its value.
-
#store(mandatory: false) ⇒ Secret::Store::Base?
Default store, opened when first used.
-
#stores ⇒ Array<Hash>
Stores of option
vault, without their parameters. -
#value(name) ⇒ String
Value of
@vault:, declared as read from the configuration: a secret of the vault can be sent only to a URL of the configuration, seeSecurity#check_credential_host.
Constructor Details
#initialize(options, main_folder) ⇒ VaultManager
Returns a new instance of VaultManager.
55 56 57 58 59 60 61 62 63 |
# File 'lib/aspera/cli/vault_manager.rb', line 55 def initialize(, main_folder) @options = @main_folder = main_folder @resolver = nil # Name of the default store, `nil` if none @default = nil # Name and type of stores, without parameters (may contain secrets) @stores = [] end |
Class Method Details
.convert_option(value) ⇒ Hash
Value of option vault when set (convert of option): the parameters of one store (deprecated) are
a store named after its type, which is the default store.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aspera/cli/vault_manager.rb', line 40 def convert_option(value) value = value.transform_keys(&:to_s) params = value.except(*OPTION_KEYS) return value if params.empty? params['type'] ||= 'file' name = params['type'].to_s Log.log.warn do "option vault: parameters of one store are #{Deprecation.new(last: '4.28.0', message: "set a store in #{STORES_KEY}, and its name in #{DEFAULT_KEY}: {\"#{DEFAULT_KEY}\":\"#{name}\",\"#{STORES_KEY}\":{\"#{name}\":{...}}}")}" end value.slice(*OPTION_KEYS).merge(DEFAULT_KEY => name, STORES_KEY => (value[STORES_KEY] || {}).merge(name => params)) end |
Instance Method Details
#fields(label) ⇒ Array<String>
Field names of a secret of the default store, without values
106 107 108 109 110 |
# File 'lib/aspera/cli/vault_manager.rb', line 106 def fields(label) store(mandatory: true) reference = Secret.reference_text(store: @default, path: label) resolver(mandatory: true).fields(reference)[:fields] end |
#metadata(name) ⇒ Hash
Checks that a reference can be read, without its value
98 99 100 101 |
# File 'lib/aspera/cli/vault_manager.rb', line 98 def (name) Aspera.assert(name.start_with?(REFERENCE_PREFIX), type: BadArgument) { "expecting a reference: @vault:#{REFERENCE_PREFIX}<store>/<path>[?<options>][#<field>]" } resolver(mandatory: true).(reference_text(name)) end |
#store(mandatory: false) ⇒ Secret::Store::Base?
Default store, opened when first used.
75 76 77 78 79 |
# File 'lib/aspera/cli/vault_manager.rb', line 75 def store(mandatory: false) return if resolver(mandatory: mandatory).nil? Aspera.assert(!mandatory || !@default.nil?, type: BadArgument) { "option vault: no default store: set #{DEFAULT_KEY}" } @resolver.store(@default) unless @default.nil? end |
#stores ⇒ Array<Hash>
Stores of option vault, without their parameters
67 68 69 70 |
# File 'lib/aspera/cli/vault_manager.rb', line 67 def stores resolver @stores end |
#value(name) ⇒ String
Value of @vault:, declared as read from the configuration: a secret of the vault can be sent only to a URL of the configuration, see Security#check_credential_host
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/aspera/cli/vault_manager.rb', line 84 def value(name) return Security.instance.add_configured(resolver(mandatory: true).resolve(reference_text(name))) if name.start_with?(REFERENCE_PREFIX) # Label may contain dots (e.g. preset name) label, _, param = name.rpartition('.') Aspera.assert(!label.empty? && !param.empty?, type: BadArgument) { 'vault name shall match <name>.<param>' } info = store(mandatory: true).get(label: label) value = info[param.to_sym] raise "no such entry value: #{param}" if value.nil? Security.instance.add_configured(value) end |