-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add the ability to wrap the http.RoundTripper from Go code #7180
Add the ability to wrap the http.RoundTripper from Go code #7180
Conversation
I discussed this a bit on Slack, as well as with @charlieegan3 at KubeCon. The end result ended up being a bit nicer than I anticipated in the throes of making the change, though the testing odyssey was a bit involved. (Sorry!) |
I'm not sure what to make of the two test failures; neither seems obviously implicated by my code (which I built and tested on MacOS 15.1). I'm attempting 200 runs of |
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.
This looks like a good, non-intrusive addition to me. I'm a bit confused by renaming "round tripper" to "round trip" though... as that had med looking at the code several times wonder how one would pass such a thing around. Can we just go with RoundTripper?
("round tripper" is IMHO questionable as well, and one part of ther larger Go NIH-terminology, but at least it's recognized for what it is here)
Hey Evan, great to meet you last week. I am unsure if our conversation helped clear things up here (I suspect it might not have!) but this looks like a solid direction to me.
I am inclined to agree here too, but open to being persuaded/educated otherwise. |
I'm happy to rename to |
A followup on the runs of
So I suspect that there are some 1% flakes here, but I'll dig into those separately. |
4dfce4b
to
7e1c903
Compare
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.
Thanks! LGTM now :)
A bit of a nit, and one I should have noticed before — but as for topdown.CustomizeRoundTripper
, I think the fact that it's custom is implied as it's being passed in as an option... and could just be called RoundTripper
... but that's mostly just my preference.
I named it that way because it's not a RoundTripper, it's a transformation function. |
Well, that's pretty much what a RoundTripper is :) But if you think this makes its purpose more apparent, I'm fine with that. |
(Note that this mechanism would allow go library users to replace |
(Do I need to do more things to get this merged? I don't have permissions to merge this myself, but I don't know what / when the merge process is.) |
Signed-off-by: Evan Anderson <[email protected]>
7e1c903
to
665e70d
Compare
@evankanderson no, nothing more to do. I'm rebasing on top of main, and if the build is green, I'll merge. |
…cy-agent#7180) Signed-off-by: Evan Anderson <[email protected]>
Why the changes in this PR are needed?
We use Rego (via
topdown
) in Minder, an OpenSSF project. We'd like to be able to customize thehttp.send
for a number of use cases, such as automatically adding service-managed credentials (JWTs represent a specific project in a multi-tenant system, similar to GitHub Actions IDs) to outgoing requests. To do this, we'd need to inject our ownhttp.RoundTripper
, while respecting the existing flags and arguments to make it easier to transfer Rego knowledge from one environment to another (and to avoid rewriting the builtinhttp.send
, which does a lot of useful stuff).What are the changes in this PR?
Adds an
EvalHTTPRoundTrip
EvalOption and query-levelWithHTTPRoundTrip
option. Both use a new function type which converts anhttp.Transport
configured bytopdown
to anhttp.RoundTripper
, presumably by wrapping the underlyinghttp.Transport
.Notes to assist PR review:
I ended up needing to adjust some of the tests; in particular, I discovered that
assertTopDownWithPathAndContext
was creating twoquery
objects, but only using the suppliedoptions
for the full-eval version, and not the partial-eval version. In turn, this caused me to discover some other HTTP tests which were relying on theQuery
objects between the two tests having different options, and fixing them.Further comments:
I'm not sure if there's further documentation beyond the Go docs via comments that need to be added; if so, I'm happy to add them.