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.7.11 lib/kontena/cli/master/token/list_command.rb
krates-1.7.10 lib/kontena/cli/master/token/list_command.rb
krates-1.7.9 lib/kontena/cli/master/token/list_command.rb
krates-1.7.8 lib/kontena/cli/master/token/list_command.rb
krates-1.7.7 lib/kontena/cli/master/token/list_command.rb
krates-1.7.6 lib/kontena/cli/master/token/list_command.rb
krates-1.7.5 lib/kontena/cli/master/token/list_command.rb
krates-1.7.4 lib/kontena/cli/master/token/list_command.rb
krates-1.7.3 lib/kontena/cli/master/token/list_command.rb
krates-1.7.2 lib/kontena/cli/master/token/list_command.rb
krates-1.7.1 lib/kontena/cli/master/token/list_command.rb
krates-1.7.0 lib/kontena/cli/master/token/list_command.rb
krates-1.6.9 lib/kontena/cli/master/token/list_command.rb
krates-1.6.8 lib/kontena/cli/master/token/list_command.rb
krates-1.6.7 lib/kontena/cli/master/token/list_command.rb
krates-1.6.6 lib/kontena/cli/master/token/list_command.rb
krates-1.6.5 lib/kontena/cli/master/token/list_command.rb
krates-1.6.4 lib/kontena/cli/master/token/list_command.rb
krates-1.6.3 lib/kontena/cli/master/token/list_command.rb
krates-1.6.2 lib/kontena/cli/master/token/list_command.rb