class Kontena::Cli::Certificate::ListCommand
Constants
- SEVEN_DAYS
- THREE_DAYS
Public Instance Methods
certificates()
click to toggle source
# File lib/kontena/cli/certificate/list_command.rb, line 21 def certificates client.get("grids/#{current_grid}/certificates")['certificates'] end
execute()
click to toggle source
# 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? # No need to fiddle with colors when they will not get printed certificate['expires_in'] = expires_in_human(expires_in) end end
expires_in(certificate)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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