Sha256: 99043e7fe8fe9fbe07ec0224267d67a26dee9af022e2d400d95dba022e950e74

Contents?: true

Size: 969 Bytes

Versions: 2

Compression:

Stored size: 969 Bytes

Contents

require_relative 'common'

module Kontena::Cli::Master::Token
  class CurrentCommand < Kontena::Command

    include Kontena::Cli::Common
    include Common

    requires_current_master
    requires_current_master_token

    option '--token', :flag, "Only output access token"
    option '--refresh-token', :flag, "Only output refresh token"
    option '--expires-in', :flag, "Only output expires in seconds"

    def execute
      if self.token?
        puts current_master.token.access_token
        exit 0
      end

      if self.refresh_token?
        if current_master.token.refresh_token
          puts current_master.token.refresh_token
        end
        exit 0
      end

      if self.expires_in?
        if current_master.token.expires_at.to_i > 0
          puts current_master.token.expires_at - Time.now.utc.to_i
        end
        exit 0
      end

      Kontena.run!(['master', 'token', 'show',  current_master.token.access_token])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kontena-cli-1.4.3 lib/kontena/cli/master/token/current_command.rb
kontena-cli-1.4.3.rc1 lib/kontena/cli/master/token/current_command.rb