Class: Aspera::Cli::SecretFinder

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options, presets) ⇒ SecretFinder

Returns a new instance of SecretFinder.

Parameters:

  • options (Parser)

    CLI options manager (provides :secret)

  • presets (PresetManager)

    preset resolver (provides #lookup_preset)



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

def initialize(options, presets)
  @options = options
  @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.

Parameters:

Returns:



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 = @options.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