Sha256: bd0149f6a44ef5b4d2bed97f3fda3072a159a06c6c3439a0671189d55eca96c0

Contents?: true

Size: 967 Bytes

Versions: 14

Compression:

Stored size: 967 Bytes

Contents

module Kontena::Cli::Stacks::YAML::Opto::Resolvers
  class VaultCertPrompt < ::Opto::Resolver
    include Kontena::Cli::Common

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

    # @return [Array<Hash>] secrets
    def get_secrets
      client.get("grids/#{current_grid}/secrets")['secrets']
    rescue
      []
    end

    # @param [Array<Hash>] secrets
    # @return [Array<Integer>]
    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kontena-cli-1.1.6 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.2.0.pre1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.5 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.5.rc1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.4 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.2.0.dev1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.3 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.2 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb