Class: Kontena::Cli::Config::Token
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Kontena::Cli::Config::Token
- Includes:
- ConfigurationInstance, Fields
- 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
Methods included from Fields
Instance Method Details
#account ⇒ Object
635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/kontena/cli/config.rb', line 635 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
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
627 628 629 |
# File 'lib/kontena/cli/config.rb', line 627 def expires? expires_at.nil? ? false : expires_at.to_i > 0 end |
#parent ⇒ Object
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.find_account(parent_name) else nil end end |
#to_h ⇒ Hash
Hash representation of token data
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 |