Class: Aspera::Cli::SecretFinder
- Inherits:
-
Object
- Object
- Aspera::Cli::SecretFinder
- Defined in:
- lib/aspera/cli/secret_finder.rb
Overview
Resolves the secret (password) for a given URL + username pair. Injected into Context as :secret_finder so that any component (plugins, Api::AoC, ...) can look up secrets without going through Plugins::Config.
Constant Summary collapse
- PRESET_MAGIC =
Special value for the :secret option that triggers a preset lookup
'PRESET'
Instance Method Summary collapse
-
#initialize(options, presets) ⇒ SecretFinder
constructor
A new instance of SecretFinder.
-
#lookup(url:, username:) ⇒ String?
Return the secret for the given URL + username.
Constructor Details
#initialize(options, presets) ⇒ SecretFinder
Returns a new instance of SecretFinder.
16 17 18 19 |
# File 'lib/aspera/cli/secret_finder.rb', line 16 def initialize(, presets) = @presets = presets end |
Instance Method Details
#lookup(url:, username:) ⇒ String?
Return the secret for the given URL + username. If the :secret option equals 'PRESET', the preset store is searched for a matching url/username entry and its 'password' field is returned.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aspera/cli/secret_finder.rb', line 27 def lookup(url:, username:) secret = .get_option(:secret) if secret.eql?(PRESET_MAGIC) conf = @presets.lookup_preset(url: url, username: username) if conf.is_a?(Hash) Log.log.debug{"Found preset #{conf} with URL and username"} secret = conf['password'] end end secret end |