Class: Puppet::Resource::Catalog::Certless
- Inherits:
-
Indirector::REST
- Object
- Indirector::REST
- Puppet::Resource::Catalog::Certless
- Defined in:
- lib/puppet/indirector/catalog/certless.rb
Instance Method Summary collapse
- #find(request) ⇒ Object
-
#headers ⇒ Object
Override the REST indirector headers for the certless catalog indirector as the ‘puppet/pson` header throws of the request body and wraps it in a “value”:<request> which causes a validation error on the v4/catalog endpoint.
Instance Method Details
#find(request) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/indirector/catalog/certless.rb', line 26 def find(request) uri = "/puppet/v4/catalog" body = { "certname": request.key, "persistence": { "facts": true, "catalog": true }, "environment": request.environment.name.to_s, "facts": { "values": request.[:transport_facts] }, "trusted_facts": { "values": request.[:trusted_facts] }, "transaction_uuid": request.[:transaction_uuid], "job_id": request.[:job_id], "options": { "prefer_requested_environment": true, "capture_logs": false } } response = do_request(request) do |req| http_post(req, uri, body.to_json, headers) end if is_http_200?(response) content_type, body = parse_response(response) # the response from the `v4/catalog` endpoint is in the format of # {"catalog": {}} whereas the configurer expects it to be a # flatter structurer, so passing it the catalog contents from the body # is suited as the API is unlikely to change for # this release result = deserialize_find(content_type, JSON.parse(body)['catalog'].to_json) result.name = request.key if result.respond_to?(:name=) result elsif is_http_404?(response) return nil unless request.[:fail_on_404] # 404 can get special treatment as the indirector API can not produce a meaningful # reason to why something is not found - it may not be the thing the user is # expecting to find that is missing, but something else (like the environment). # While this way of handling the issue is not perfect, there is at least an error # that makes a user aware of the reason for the failure. # _, body = parse_response(response) msg = format(_("Find %<uri>s resulted in 404 with the message: %<body>s"), uri: elide(uri, 100), body: body) raise Puppet::Error, msg end end |
#headers ⇒ Object
Override the REST indirector headers for the certless catalog indirector as the ‘puppet/pson` header throws of the request body and wraps it in a “value”:<request> which causes a validation error on the v4/catalog endpoint
16 17 18 19 20 21 22 23 24 |
# File 'lib/puppet/indirector/catalog/certless.rb', line 16 def headers common_headers = { "Content-Type" => 'text/json', "Accept" => 'application/json', Puppet::Network::HTTP::HEADER_PUPPET_VERSION => Puppet.version } add_accept_encoding(common_headers) end |