Method: Puppet::HTTP::Service::Compiler#post_catalog4

Defined in:
lib/puppet/http/service/compiler.rb

#post_catalog4(certname, persistence:, environment:, facts: nil, trusted_facts: nil, transaction_uuid: nil, job_id: nil, options: nil) ⇒ Array<Puppet::HTTP::Response, Puppet::Resource::Catalog, Array<String>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Submit a POST request to request a catalog to the server using v4 endpoint

Parameters:

  • certname (String)

    The name of the node for which to compile the catalog.

  • persistent (Hash)

    A hash containing two required keys, facts and catalog, which when set to true will cause the facts and reports to be stored in PuppetDB, or discarded if set to false.

  • environment (String)

    The name of the environment for which to compile the catalog.

  • facts (Hash) (defaults to: nil)

    A hash with a required values key, containing a hash of all the facts for the node. If not provided, Puppet will attempt to fetch facts for the node from PuppetDB.

  • trusted_facts (Hash) (defaults to: nil)

    A hash with a required values key containing a hash of the trusted facts for a node

  • transaction_uuid (String) (defaults to: nil)

    The id for tracking the catalog compilation and report submission.

  • job_id (String) (defaults to: nil)

    The id of the orchestrator job that triggered this run.

  • options (Hash) (defaults to: nil)

    A hash of options beyond direct input to catalogs. Options:

    • prefer_requested_environment Whether to always override a node’s classified environment with the one supplied in the request. If this is true and no environment is supplied, fall back to the classified environment, or finally, ‘production’.

    • capture_logs Whether to return the errors and warnings that occurred during compilation alongside the catalog in the response body.

    • log_level The logging level to use during the compile when capture_logs is true. Options are ‘err’, ‘warning’, ‘info’, and ‘debug’.

Returns:

  • (Array<Puppet::HTTP::Response, Puppet::Resource::Catalog, Array<String>>)

    An array containing the request response, the deserialized catalog returned by the server and array containing logs (log array will be empty if capture_logs is false)

Raises:

  • (ArgumentError)


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/puppet/http/service/compiler.rb', line 162

def post_catalog4(certname, persistence:, environment:, facts: nil, trusted_facts: nil, transaction_uuid: nil, job_id: nil, options: nil)
  unless persistence.is_a?(Hash) && (missing = [:facts, :catalog] - persistence.keys.map(&:to_sym)).empty?
    raise ArgumentError.new("The 'persistence' hash is missing the keys: #{missing.join(', ')}")
  end
  raise ArgumentError.new("Facts must be a Hash not a #{facts.class}") unless facts.nil? || facts.is_a?(Hash)
  body = {
    certname: certname,
    persistence: persistence,
    environment: environment,
    transaction_uuid: transaction_uuid,
    job_id: job_id,
    options: options
  }
  body[:facts] = { values: facts } unless facts.nil?
  body[:trusted_facts] = { values: trusted_facts } unless trusted_facts.nil?
  headers = add_puppet_headers(
    'Accept' => get_mime_types(Puppet::Resource::Catalog).join(', '),
    'Content-Type' => 'application/json'
  )

  url = URI::HTTPS.build(host: @url.host, port: @url.port, path: Puppet::Util.uri_encode("/puppet/v4/catalog"))
  response = @client.post(
    url,
    body.to_json,
    headers: headers
  )
  process_response(response)
  begin
    response_body = JSON.parse(response.body)
    catalog = Puppet::Resource::Catalog.from_data_hash(response_body['catalog'])
  rescue => err
    raise Puppet::HTTP::SerializationError.new("Failed to deserialize catalog from puppetserver response: #{err.message}", err)
  end
  
  logs = response_body['logs'] || []
  [response, catalog, logs]
end