Class: Puppet::HTTP::Service::Ca

Inherits:
Puppet::HTTP::Service show all
Defined in:
lib/puppet/http/service/ca.rb

Constant Summary collapse

HEADERS =
{ 'Accept' => 'text/plain' }.freeze

Instance Attribute Summary

Attributes inherited from Puppet::HTTP::Service

#url

Instance Method Summary collapse

Methods inherited from Puppet::HTTP::Service

#connect, #initialize, #with_base_url

Constructor Details

This class inherits a constructor from Puppet::HTTP::Service

Instance Method Details

#get_certificate(name, ssl_context: nil) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/puppet/http/service/ca.rb', line 4

def get_certificate(name, ssl_context: nil)
  response = @client.get(
    with_base_url("/certificate/#{name}"),
    headers: HEADERS,
    ssl_context: ssl_context
  )

  return response.body.to_s if response.success?

  raise Puppet::HTTP::ResponseError.new(response)
end

#get_certificate_revocation_list(if_modified_since: nil, ssl_context: nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/http/service/ca.rb', line 16

def get_certificate_revocation_list(if_modified_since: nil, ssl_context: nil)
  request_headers = if if_modified_since
                      h = HEADERS.dup
                      h['If-Modified-Since'] = if_modified_since.httpdate
                      h
                    else
                      HEADERS
                    end

  response = @client.get(
    with_base_url("/certificate_revocation_list/ca"),
    headers: request_headers,
    ssl_context: ssl_context
  )

  return response.body.to_s if response.success?

  raise Puppet::HTTP::ResponseError.new(response)
end

#put_certificate_request(name, csr, ssl_context: nil) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet/http/service/ca.rb', line 36

def put_certificate_request(name, csr, ssl_context: nil)
  response = @client.put(
    with_base_url("/certificate_request/#{name}"),
    headers: HEADERS,
    content_type: 'text/plain',
    body: csr.to_pem,
    ssl_context: ssl_context
  )

  return response.body.to_s if response.success?

  raise Puppet::HTTP::ResponseError.new(response)
end