class Kontena::Cli::Master::Token::ListCommand

Public Instance Methods

colorize(expires_in) click to toggle source
# File lib/kontena/cli/master/token/list_command.rb, line 27
def colorize(expires_in)
  return expires_in.to_s unless $stdout.tty?
  if expires_in.zero?
    pastel.yellow('never')
  elsif expires_in < 0
    pastel.red(time_ago(Time.now.to_i + expires_in))
  else
    pastel.green(time_until(expires_in))
  end
end
execute() click to toggle source
# File lib/kontena/cli/master/token/list_command.rb, line 18
def execute
  data = Array(client.get("/oauth2/tokens")["tokens"])
  print_table(data) do |row|
    next if quiet?
    row['expires_in'] = colorize(row['expires_in'].to_i)
    row['token_type'] ||= row['grant_type']
  end
end
fields() click to toggle source
# File lib/kontena/cli/master/token/list_command.rb, line 13
def fields
  return ['id'] if quiet?
  { id: 'id', token_type: 'token_type', token_last4: 'access_token_last_four', expires_in: 'expires_in', scopes: 'scopes', description: 'description' }
end