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

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

Instance Method Summary collapse

Methods included from ConfigurationInstance

#config

Instance Method Details

#accountObject



518
519
520
521
522
523
524
525
526
527
528
# File 'lib/kontena/cli/config.rb', line 518

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)


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

Returns:

  • (Boolean)


510
511
512
# File 'lib/kontena/cli/config.rb', line 510

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

#parentObject



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.(parent_name)
  else
    nil
  end
end

#to_hHash

Hash representation of token data

Returns:

  • (Hash)


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