Sha256: df35ed5dc4d82a20940375f1be4d8a7bc6eb0e2dddd51d4a7a58a2e3be1f18db

Contents?: true

Size: 1 KB

Versions: 42

Compression:

Stored size: 1 KB

Contents

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

    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

    # @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

42 entries across 42 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.10 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.9 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.8 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.7 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.6 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.5 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.4 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.3 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.2 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.1 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.7.0 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.9 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.8 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.7 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.6 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.5 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.4 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.3 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb
krates-1.6.2 lib/kontena/cli/stacks/yaml/opto/vault_cert_prompt_resolver.rb