Skip to content

Commit

Permalink
Use JSON to parse Foreman API responses
Browse files Browse the repository at this point in the history
The PSON parser is deprecated and Foreman doesn't actually send PSON; it
sends JSON.

See https://www.puppet.com/docs/puppet/8/http_api/pson.html
  • Loading branch information
ekohl committed Nov 14, 2023
1 parent b5655ab commit 06bc17d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/functions/foreman/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def foreman(item, search, per_page = "20", foreman_url = "https://localhost", fo
http.use_ssl = true if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
end
results = Timeout::timeout(timeout) { PSON.parse http.request(req).body }
results = Timeout::timeout(timeout) { JSON.parse http.request(req).body }
rescue Exception => e
raise Puppet::ParseError, "Failed to contact Foreman at #{foreman_url}: #{e}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions/foreman/smartvar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def smartvar(var, foreman_url = "http://foreman", foreman_user = "admin", forema
req['Accept'] = 'application/json'

begin
Timeout::timeout(5) { PSON.parse(http.request(req).body)["value"] }
Timeout::timeout(5) { JSON.parse(http.request(req).body)["value"] }
rescue Exception => e
raise Puppet::ParseError, "Failed to contact Foreman #{e}"
end
Expand Down

0 comments on commit 06bc17d

Please sign in to comment.