Class: Kontena::Cli::Config::Token
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Kontena::Cli::Config::Token
- Includes:
- ConfigurationInstance
- Defined in:
- lib/kontena/cli/config.rb
Instance Method Summary collapse
- #account ⇒ Object
- #expired? ⇒ Boolean
- #expires? ⇒ Boolean
- #parent ⇒ Object
-
#to_h ⇒ Hash
Hash representation of token data.
Methods included from ConfigurationInstance
Instance Method Details
#account ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/kontena/cli/config.rb', line 518 def account return @account if @account return config.find_account('master') unless parent @account = case parent_type when :master then config.find_account(parent.account) when :account then parent else nil end end |
#expired? ⇒ Boolean
514 515 516 |
# File 'lib/kontena/cli/config.rb', line 514 def expired? expires? && expires_at && expires_at.to_i < Time.now.utc.to_i end |
#expires? ⇒ Boolean
510 511 512 |
# File 'lib/kontena/cli/config.rb', line 510 def expires? expires_at.nil? ? false : expires_at.to_i > 0 end |
#parent ⇒ Object
530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/kontena/cli/config.rb', line 530 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.find_account(parent_name) else nil end end |
#to_h ⇒ Hash
Hash representation of token data
502 503 504 505 506 507 508 |
# File 'lib/kontena/cli/config.rb', line 502 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 |