-
Notifications
You must be signed in to change notification settings - Fork 310
Replace RestClient with Faraday 2.x for persistent Candlepin connections #11754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
05e81dd
7356ed9
8dc6ebf
2d5ad0f
6fd5610
9a432d4
10771ab
4f4b889
3dedbd4
d73b700
fe02026
09d98e8
09fcd5d
59c7dd7
3b4408a
5080aaf
311d5b3
e20dd3b
3924a65
cf799c9
0a7c1c4
b3b1325
3eb1f95
929729f
c8ab788
988d2cf
bd3f605
2c6b705
77c8da7
07171f9
0aa4c2b
49b7e86
7493d4a
8a86f4c
f603894
7de46e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,15 @@ def finalize(*args) | |
|
|
||
| def propagate_candlepin_errors | ||
| yield | ||
| rescue RestClient::ExceptionWithResponse => e | ||
| error_class = if e.response.request.url.include?('/candlepin') | ||
| ::Katello::Errors::CandlepinError | ||
| else | ||
| ::Katello::Errors::UpstreamCandlepinError | ||
| end | ||
| raise(error_class.from_exception(e) || e) | ||
| rescue ::Katello::Errors::CandlepinError | ||
| raise | ||
| rescue HttpResource::HttpError => e | ||
| display_message = e.message | ||
| if e.response_body.present? | ||
| parsed = JSON.parse(e.response_body) rescue {} | ||
| display_message = parsed['displayMessage'] || display_message | ||
| end | ||
| raise ::Katello::Errors::CandlepinError, display_message | ||
|
Comment on lines
+22
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve upstream-vs-local error typing here. This now rewrites every 🤖 Prompt for AI Agents |
||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| require 'oauth' | ||
|
|
||
| module Katello | ||
| module Concerns | ||
| module OauthRequestSigning | ||
| extend ActiveSupport::Concern | ||
|
|
||
| HTTP_CLASSES = { | ||
| get: Net::HTTP::Get, | ||
| post: Net::HTTP::Post, | ||
| put: Net::HTTP::Put, | ||
| patch: Net::HTTP::Patch, | ||
| delete: Net::HTTP::Delete, | ||
| }.freeze | ||
|
|
||
| class_methods do | ||
| def sign_request(req, url, method) | ||
| fail "#{name}: OAuth consumer_key and consumer_secret required" if self.consumer_key.blank? || self.consumer_secret.blank? | ||
| req.headers['Authorization'] = build_oauth_header(url, method) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def oauth_consumer | ||
| @oauth_consumer ||= OAuth::Consumer.new( | ||
| self.consumer_key, self.consumer_secret, | ||
| :site => self.site, | ||
| :request_token_path => "", | ||
| :authorize_path => "", | ||
| :access_token_path => "", | ||
| :ca_file => self.ssl_ca_file | ||
| ) | ||
| end | ||
|
|
||
| def build_oauth_header(url, method) | ||
| request = HTTP_CLASSES.fetch(method).new(url) | ||
| oauth_consumer.sign!(request) | ||
| request['Authorization'] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised by this mechanism. I know it was already there, but Rails normally uses
respond_to. I think this would be the Rails native mechanism, assuming the CLI setsAccept: application/jsonas a header:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the current Hammer stack and it does reliably send
Accept: application/json;version=...via apipie-bindings, sorespond_toshould work for the maintained CLI path. You're also right thatrequest_from_katello_cli?appears to be legacy behavior tied to the old Python-based Katello CLI rather than modern Hammer. My only hesitation is calling it fully dead code without scoping that claim — the registry endpoints are more likely hit by container tooling (podman, skopeo) and scripts than by Hammer itself. If we're comfortable aligning this with maintained clients rather than preserving the old User-Agent behavior, I thinkrespond_tois reasonable — but I'd do it as a follow-up that updates all the sibling controllers consistently rather than just this one handler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed it belongs in a separate PR.