Class: Kontena::Cli::Stacks::YAML::Opto::Resolvers::VaultCertPrompt

Inherits:
Opto::Resolver
  • Object
show all
Includes:
Common
Defined in:
lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb

Instance Method Summary collapse

Methods included from Common

#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #caret, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_grid, #current_master_index, #debug?, #display_account_login_info, #display_login_info, display_logo, #display_master_login_info, #error, exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_token, #reset_client, #reset_cloud_client, #running_quiet?, #running_silent?, #running_verbose?, #spin_if, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning

Instance Method Details

#default_indexes(secrets) ⇒ Array<Integer>

Parameters:

  • secrets (Array<Hash>)

Returns:

  • (Array<Integer>)


30
31
32
33
34
35
36
37
# File 'lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb', line 30

def default_indexes(secrets)
  indexes = []
  option.default.to_a.each do |name|
    index = secrets.index { |s| s['name'] == name }
    indexes << index.to_i + 1 if index
  end
  indexes
end

#get_secretsArray<Hash>

Returns secrets.

Returns:

  • (Array<Hash>)

    secrets



22
23
24
25
26
# File 'lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb', line 22

def get_secrets
  client.get("grids/#{current_grid}/secrets")['secrets']
rescue
  []
end

#resolveObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb', line 5

def resolve
  return nil unless current_master && current_grid
  message = hint || 'Select SSL certs'
  secrets = get_secrets.select{ |s|
    s['name'].match(/(ssl|cert)/i)
  }
  if secrets.size > 0
    prompt.multi_select(message) do |menu|
      menu.default(*default_indexes(secrets)) if option.default
      secrets.each do |s|
        menu.choice s['name']
      end
    end
  end
end