Class: K8y::REST::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/k8y/rest/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path:, transport:, auth:) ⇒ Config

Returns a new instance of Config.



31
32
33
34
35
# File 'lib/k8y/rest/config.rb', line 31

def initialize(base_path:, transport:, auth:)
  @base_path = base_path
  @transport = transport
  @auth = auth
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



10
11
12
# File 'lib/k8y/rest/config.rb', line 10

def auth
  @auth
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



10
11
12
# File 'lib/k8y/rest/config.rb', line 10

def base_path
  @base_path
end

#transportObject (readonly)

Returns the value of attribute transport.



10
11
12
# File 'lib/k8y/rest/config.rb', line 10

def transport
  @transport
end

Class Method Details

.from_kubeconfig(kubeconfig, context: nil, path: "/") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/k8y/rest/config.rb', line 13

def from_kubeconfig(kubeconfig, context: nil, path: "/")
  context = context ? context : kubeconfig.current_context
  ConfigValidator.new(kubeconfig, context: context).validate!

  cluster = kubeconfig.cluster_for_context(context)
  base_path = File.join(cluster.server, path)
  transport = if URI(base_path).scheme == "https"
    Transport.from_kubeconfig(kubeconfig, context: context)
  end
  auth = Auth.from_kubeconfig(kubeconfig, context: context)
  new(
    base_path: base_path,
    transport: transport,
    auth: auth
  )
end