Class: Kontena::Cli::Config::Server

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

Instance Method Summary collapse

Methods included from ConfigurationInstance

#config

Methods included from TokenSerializer

#to_h

Methods included from Fields

#keys, #values_at

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



573
574
575
576
# File 'lib/kontena/cli/config.rb', line 573

def initialize(*args)
  super
  @table[:account] ||= 'master'
end

Instance Method Details

#ssl_certOpenSSL::X509::Certificate?

Returns:

  • (OpenSSL::X509::Certificate, nil)


594
595
596
597
598
599
600
# File 'lib/kontena/cli/config.rb', line 594

def ssl_cert
  if path = self.ssl_cert_path
    return OpenSSL::X509::Certificate.new(File.read(path))
  else
    return nil
  end
end

#ssl_cert_pathString?

Returns path to ~/.kontena/certs/*.pem.

Returns:

  • (String, nil)

    path to ~/.kontena/certs/*.pem



583
584
585
586
587
588
589
590
591
# File 'lib/kontena/cli/config.rb', line 583

def ssl_cert_path
  path = File.join(Dir.home, '.kontena', 'certs', "#{self.uri.host}.pem")

  if File.exist?(path) && File.readable?(path)
    return path
  else
    return nil
  end
end

#ssl_subject_cnString?

Returns ssl cert subject CN=.

Returns:

  • (String, nil)

    ssl cert subject CN=



603
604
605
606
607
608
609
# File 'lib/kontena/cli/config.rb', line 603

def ssl_subject_cn
  if cert = self.ssl_cert
    return cert.subject.to_a.select{|name, data, type| name == 'CN' }.map{|name, data, type| data }.first
  else
    nil
  end
end

#uriObject



578
579
580
# File 'lib/kontena/cli/config.rb', line 578

def uri
  @uri ||= URI.parse(self.url)
end