class Kontena::Cli::Stacks::YAML::Opto::Resolvers::Certificates

Public Instance Methods

default_indexes(certificates) click to toggle source

@param certificates [Array<Hash>] @return [Array<Integer>]

# File lib/kontena/cli/stacks/yaml/opto/certificates_resolver.rb, line 28
def default_indexes(certificates)
  indexes = []
  option.default.to_a.each do |subject|
    index = certificates.index { |s| s['subject'] == subject }
    indexes << index.to_i + 1 if index
  end
  indexes
end
get_certificates() click to toggle source

@return [Array<Hash>] certificates

# File lib/kontena/cli/stacks/yaml/opto/certificates_resolver.rb, line 20
def get_certificates
  client.get("grids/#{current_grid}/certificates")['certificates']
rescue
  []
end
resolve() click to toggle source
# File lib/kontena/cli/stacks/yaml/opto/certificates_resolver.rb, line 5
def resolve
  return nil unless current_master && current_grid
  message = hint || 'Select SSL certificates'
  certificates = get_certificates
  if certificates.size > 0
    prompt.multi_select(message) do |menu|
      menu.default(*default_indexes(certificates)) if option.default
      certificates.each do |s|
        menu.choice s['subject']
      end
    end
  end
end