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

Version Path
krates-1.6.1 lib/kontena/cli/master/token/list_command.rb
krates-1.6.0 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.4 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.4.rc1 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.3 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.2 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.1 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.rc1 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.pre5 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.pre4 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.pre3 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.pre2 lib/kontena/cli/master/token/list_command.rb
kontena-cli-1.5.0.pre1 lib/kontena/cli/master/token/list_command.rb