class Puppet::HTTP::Service::Ca

The CA service is used to handle certificate related REST requests.

@api public

Constants

API

@return [String] default API for the ca service

HEADERS

@return [Hash] default headers for the ca service

Public Class Methods

new(client, session, server, port) click to toggle source

Use `Puppet::HTTP::Session.route_to(:ca)` to create or get an instance of this class.

@param [Puppet::HTTP::Client] client @param [Puppet::HTTP::Session] session @param [String] server (`Puppet`) If an explicit server is given,

create a service using that server. If server is nil, the default value
is used to create the service.

@param [Integer] port (`Puppet`) If an explicit port is given, create

a service using that port. If port is nil, the default value is used to
create the service.
Calls superclass method Puppet::HTTP::Service::new
   # File lib/puppet/http/service/ca.rb
23 def initialize(client, session, server, port)
24   url = build_url(API, server || Puppet[:ca_server], port || Puppet[:ca_port])
25   super(client, session, url)
26 end

Public Instance Methods

get_certificate(name, ssl_context: nil) click to toggle source

Submit a GET request to retrieve the named certificate from the server.

@param [String] name name of the certificate to request @param [Puppet::SSL::SSLContext] ssl_context

@return [Array<Puppet::HTTP::Response, String>] An array containing the

request response and the stringified body of the request response

@api public

   # File lib/puppet/http/service/ca.rb
37 def get_certificate(name, ssl_context: nil)
38   response = @client.get(
39     with_base_url("/certificate/#{name}"),
40     headers: add_puppet_headers(HEADERS),
41     options: {ssl_context: ssl_context}
42   )
43 
44   process_response(response)
45 
46   [response, response.body.to_s]
47 end
get_certificate_revocation_list(if_modified_since: nil, ssl_context: nil) click to toggle source

Submit a GET request to retrieve the certificate revocation list from the

server.

@param [Time] if_modified_since If not nil, only download the CRL if it has

been modified since the specified time.

@param [Puppet::SSL::SSLContext] ssl_context

@return [Array<Puppet::HTTP::Response, String>] An array containing the

request response and the stringified body of the request response

@api public

   # File lib/puppet/http/service/ca.rb
60 def get_certificate_revocation_list(if_modified_since: nil, ssl_context: nil)
61   headers = add_puppet_headers(HEADERS)
62   headers['If-Modified-Since'] = if_modified_since.httpdate if if_modified_since
63 
64   response = @client.get(
65     with_base_url("/certificate_revocation_list/ca"),
66     headers: headers,
67     options: {ssl_context: ssl_context}
68   )
69 
70   process_response(response)
71 
72   [response, response.body.to_s]
73 end
put_certificate_request(name, csr, ssl_context: nil) click to toggle source

Submit a PUT request to send a certificate request to the server.

@param [String] name The name of the certificate request being sent @param [OpenSSL::X509::Request] csr Certificate request to send to the

server

@param [Puppet::SSL::SSLContext] ssl_context

@return [Puppet::HTTP::Response] The request response

@api public

    # File lib/puppet/http/service/ca.rb
 85 def put_certificate_request(name, csr, ssl_context: nil)
 86   headers = add_puppet_headers(HEADERS)
 87   headers['Content-Type'] = 'text/plain'
 88 
 89   response = @client.put(
 90     with_base_url("/certificate_request/#{name}"),
 91     csr.to_pem,
 92     headers: headers,
 93     options: {
 94       ssl_context: ssl_context
 95     }
 96   )
 97 
 98   process_response(response)
 99 
100   response
101 end