Class: Kontena::Cli::Certificate::ImportCommand
Instance Attribute Summary
#arguments, #exit_code, #result
Instance Method Summary
collapse
Methods included from Common
#show_certificate
included
#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
banner, callback_matcher, #help_requested?, inherited, #instance, load_subcommand, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token
Instance Method Details
#certificate_subject(cert) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/kontena/cli/certificate/import_command.rb', line 38
def certificate_subject(cert)
cert.subject.to_a.each do |name, data|
return data if name == 'CN'
end
exit_with_error "No CN in certificate subject: #{cert.subject}"
end
|
#execute ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/kontena/cli/certificate/import_command.rb', line 46
def execute
cert = load_certificate
subject = self.subject || self.certificate_subject(cert)
certificate = spinner "Importing certificate from #{cert_file.path}..." do
client.put("certificates/#{current_grid}/#{subject}",
certificate: cert.to_pem,
private_key: self.key_file.read(),
chain: chain_file_list.map{|chain_file| chain_file.read() },
)
end
show_certificate(certificate)
end
|
#load_certificate ⇒ Object
32
33
34
35
36
|
# File 'lib/kontena/cli/certificate/import_command.rb', line 32
def load_certificate
OpenSSL::X509::Certificate.new(self.cert_file)
rescue OpenSSL::OpenSSLError => exc
exit_with_error "Invalid certificate at #{self.cert_file.path}: #{exc.class}: #{exc.message}"
end
|
#open_file(path) ⇒ Object
11
12
13
14
15
|
# File 'lib/kontena/cli/certificate/import_command.rb', line 11
def open_file(path)
File.open(path)
rescue Errno::ENOENT
raise ArgumentError, "File not found: #{path}"
end
|