Class: Kontena::Cli::Certificate::ListCommand
Constant Summary
collapse
- SEVEN_DAYS =
7 * 24 * 60 * 60
- THREE_DAYS =
3 * 24 * 60 * 60
Instance Attribute Summary
#arguments, #exit_code, #result
Instance Method Summary
collapse
Methods included from Util
included, #longest_string_in_array, #safe_dig, #seconds_to_human, stringify_keys, stringify_keys!, symbolize_keys, symbolize_keys!, #time_ago, #time_until, which
#generate_table, included, #print_table, #table_generator
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
#certificates ⇒ Object
21
22
23
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 21
def certificates
client.get("grids/#{current_grid}/certificates")['certificates']
end
|
#execute ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 65
def execute
print_table(certificates) do |certificate|
expires_in = expires_in(certificate)
certificate['subject'] = status_icon(expires_in) + " " + certificate['subject'] unless quiet?
next if quiet? certificate['expires_in'] = expires_in_human(expires_in)
end
end
|
#expires_in(certificate) ⇒ Object
50
51
52
53
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 50
def expires_in(certificate)
valid_until = Time.parse(certificate['valid_until'])
(valid_until - Time.now).to_i
end
|
#expires_in_human(expires_in) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 55
def expires_in_human(expires_in)
if expires_in > 0
text = seconds_to_human(expires_in)
else
text = seconds_to_human(-1 * expires_in) + ' ago'
end
text.colorize(status_color(expires_in))
end
|
#fields ⇒ Object
17
18
19
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 17
def fields
quiet? ? ['subject'] : {subject: 'subject', "expiration" => 'expires_in', auto_renewable?: 'auto_renewable'}
end
|
#status_color(expires_in) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 36
def status_color(expires_in)
if expires_in < 0
:red
elsif expires_in < THREE_DAYS
:bright_yellow
elsif expires_in < SEVEN_DAYS
:yellow
else
:green
end
end
|
#status_icon(expires_in) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/kontena/cli/certificate/list_command.rb', line 25
def status_icon(expires_in)
icon = '⊛'.freeze
if expires_in < 0
icon.colorize(:red)
else
icon.colorize(:green)
end
end
|