Sha256: 76293e8f4d9edbfb04d6dc240cc41bddaceb28e5b18196203d4d74f57fb4a32d

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require 'puppet/rest/route'

module Puppet::Rest
  module Routes
    ACCEPT_ENCODING = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'

    def self.ca
      @ca ||= Route.new(api: '/puppet-ca/v1/',
                        default_server: Puppet[:ca_server],
                        default_port: Puppet[:ca_port],
                        srv_service: :ca)
    end

    # Make an HTTP request to fetch the named certificate, using the given
    # HTTP client.
    # @param [Puppet::Rest::Client] client the HTTP client to use to make the request
    # @param [String] name the name of the certificate to fetch
    # @raise [Puppet::Rest::ResponseError] if the response status is not OK
    # @return [String] the PEM-encoded certificate or certificate bundle
    def self.get_certificate(client, name)
      ca.with_base_url(client.dns_resolver) do |base_url|
        header = { 'Accept' => 'text/plain', 'accept-encoding' => ACCEPT_ENCODING }
        body = ''
        client.get(base_url + "certificate/#{name}", header: header) do |chunk|
          body << chunk
        end
        body
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bolt-0.21.1 vendored/puppet/lib/puppet/rest/routes.rb
bolt-0.21.0 vendored/puppet/lib/puppet/rest/routes.rb
bolt-0.20.7 vendored/puppet/lib/puppet/rest/routes.rb
bolt-0.20.6 vendored/puppet/lib/puppet/rest/routes.rb
bolt-0.20.5 vendored/puppet/lib/puppet/rest/routes.rb