-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 context-aware functions to vault/api #14388
Conversation
1938afe
to
a850e0f
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.
Whew, good work! LGTM, aside from some inconsistency in when the http.MethodGet is used vs the hard-coded "GET".
I am starting to second-guess whether adding such a large amount of duplicate methods is a better choice than just adding ctx to all the existing ones and bumping to a new major version (where breaking changes would presumably be expected)... but it's a little late for that now so we can rethink that in the new version of the client I suppose!
Good point, I think I'll just revert all of the
This is meant as a stop-gap solution until we have a new shiny version. In the new version, we'll most likely default to context-only functions. |
Credits
This pull request is based on a community contribution #14152 by ilyakaznacheev and resolves #14070
Description
For each API wrapper function in
vault/api
, we are adding a context-aware equivalent. These new functions will haveWithContext
appended to their names.Implementation Notes
One of the issues that I discovered in the original PR (#14152) is a potential context leak due to this piece of code inside
RawRequestWithContext
:To prevent context leaks, the timeout logic has been extracted out of
RawRequestWithContext
and into each...WithContext
wrapper (usingwithConfiguredTimeout
helper). Additionally, sinceRawRequestWithContext
is still used outside ofvautl/api
, its implementation has been moved into unexportedrawRequestWithContext
See this comment for more details.
Testing
All existing tests that were calling vault/api functions have been switched to call
WithContext
equivalents withcontext.Background()
passed in. SinceWithContext
functions invoke the regular ones, this change should increase code coverage without any negative side effects.