Class: Kontena::Cli::Config::Token

Inherits:
OpenStruct
  • Object
show all
Includes:
ConfigurationInstance, Fields
Defined in:
lib/kontena/cli/config.rb

Instance Method Summary collapse

Methods included from ConfigurationInstance

#config

Methods included from Fields

#keys, #values_at

Instance Method Details

#accountObject



635
636
637
638
639
640
641
642
643
644
645
# File 'lib/kontena/cli/config.rb', line 635

def 
  return @account if @account
  return config.('master') unless parent
  @account =
    case parent_type
    when :master then config.(parent.)
    when :account then parent
    else
      nil
    end
end

#expired?Boolean

Returns:

  • (Boolean)


631
632
633
# File 'lib/kontena/cli/config.rb', line 631

def expired?
  expires? && expires_at && expires_at.to_i < Time.now.utc.to_i
end

#expires?Boolean

Returns:

  • (Boolean)


627
628
629
# File 'lib/kontena/cli/config.rb', line 627

def expires?
  expires_at.nil? ? false : expires_at.to_i > 0
end

#parentObject



647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/kontena/cli/config.rb', line 647

def parent
  return nil unless parent_type
  return nil unless parent_name
  case parent_type
  when :master
    config.find_server(parent_name)
  when :account
    config.(parent_name)
  else
    nil
  end
end

#to_hHash

Hash representation of token data

Returns:

  • (Hash)


619
620
621
622
623
624
625
# File 'lib/kontena/cli/config.rb', line 619

def to_h
  {
    token: self.access_token,
    token_expires_at: self.expires_at,
    refresh_token: self.refresh_token
  }.merge(self.respond_to?(:username) ? {username: self.username} : {})
end