Class: Rancher::ManagementApi::Token

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rancher/management_api/token.rb

Class Method Summary collapse

Class Method Details

.build_manager(host:, username:, password:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rancher/management_api/token.rb', line 17

def self.build_manager(host:, username:, password:)
  conn = Rancher::ManagementApi.connection(host)

  token = create(code: [username, password].join(":"), conn: conn)

  tokened_conn = Rancher::ManagementApi.connection(host) do |faraday|
    faraday.headers["Cookie"] = "token=#{token.jwt}"
  end

  Manager.new(tokened_conn)
end

.create(code:, conn:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rancher/management_api/token.rb', line 6

def self.create(code:, conn:)
  token_response = conn.post do |req|
    req.url "/v1/token"
    req.body = { code: code }.to_json
  end

  data = JSON.parse(token_response.body)

  new(data)
end