Sha256: 2996502da48bef711ab11e63182fc99cfd410f91e0332c5190035df5a3c8476f
Contents?: true
Size: 1.04 KB
Versions: 34
Compression:
Stored size: 1.04 KB
Contents
require_relative 'common' module Kontena::Cli::Master::Token class ListCommand < Kontena::Command include Kontena::Util include Kontena::Cli::Common include Kontena::Cli::TableGenerator::Helper include Common requires_current_master requires_current_master_token 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 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 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 end end
Version data entries
34 entries across 34 versions & 2 rubygems