def submit
checksum = Digest::SHA1.hexdigest(payload)
for_whom = " for #{certname}" if certname
begin
response = profile("Submit command HTTP post", [:puppetdb, :command, :submit]) do
http = Puppet::Network::HttpPool.http_instance(config.server, config.port)
http.post(Puppet::Util::Puppetdb.url_path(CommandsUrl + "?checksum=#{checksum}"),
payload, headers)
end
Puppet::Util::Puppetdb.log_x_deprecation_header(response)
if response.is_a? Net::HTTPSuccess
result = JSON.parse(response.body)
Puppet.info "'#{command}' command#{for_whom} submitted to PuppetDB with UUID #{result['uuid']}"
result
else
error = "[#{response.code} #{response.message}] #{response.body.gsub(/[\r\n]/, '')}"
if config.soft_write_failure
Puppet.err "'#{command}'command#{for_whom} failed during submission to PuppetDB: #{error}"
else
raise Puppet::Error, error
end
end
rescue => e
error = "Failed to submit '#{command}' command#{for_whom} to PuppetDB at #{config.server}:#{config.port}: #{e}"
if config.soft_write_failure
Puppet.err error
else
puts e, e.backtrace if Puppet[:trace]
raise Puppet::Error, error
end
end
end