Class: KingslyCertbot::KingslyClient

Inherits:
Object
  • Object
show all
Defined in:
lib/kingsly_certbot/kingsly_client.rb

Class Method Summary collapse

Class Method Details

.get_cert_bundle(kingsly_server_host:, kingsly_server_port:, top_level_domain:, sub_domain:, kingsly_http_read_timeout: 120, kingsly_http_open_timeout: 5) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kingsly_certbot/kingsly_client.rb', line 9

def self.get_cert_bundle(kingsly_server_host:,
                         kingsly_server_port:,
                         top_level_domain:,
                         sub_domain:,
                         kingsly_http_read_timeout: 120,
                         kingsly_http_open_timeout: 5)

  body = {
    'top_level_domain' => top_level_domain,
    'sub_domain' => sub_domain
  }
  uri = URI.parse("http://#{kingsly_server_host}:#{kingsly_server_port}/v1/cert_bundles")

  http = Net::HTTP.new(uri.host, uri.port)

  http.read_timeout = kingsly_http_read_timeout
  http.open_timeout = kingsly_http_open_timeout

  headers = {}
  headers['Content-Type'] = 'application/json'
  resp = http.start do |http_request|
    http_request.post(uri.path, JSON.dump(body), headers)
  end

  raise 'Authentication failure with kingsly, Please check your authentication configuration' if resp.code == '401'

  body = JSON.parse(resp.body)
  CertBundle.new(top_level_domain, sub_domain, body['private_key'], body['full_chain'])
end