-
Notifications
You must be signed in to change notification settings - Fork 59
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 identity/authorization headers into Rest Client calls #613
Conversation
Signed-off-by: Nurym <[email protected]>
Signed-off-by: Nurym <[email protected]>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #613 +/- ##
============================================
- Coverage 63.70% 63.62% -0.08%
Complexity 263 263
============================================
Files 52 52
Lines 1138 1141 +3
Branches 36 36
============================================
+ Hits 725 726 +1
- Misses 402 404 +2
Partials 11 11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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 for this initial PR. It's very helpful that you have shown how to add the headers.
Can we make a setter for the client that updates the options? Something like setOptions(options)
which you create this way?
Signed-off-by: Nurym <[email protected]>
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.
A few general comments here:
- We need to continue to provide the default option if nothing is passed. Don't hard-code strings.
- We should just have a single string for a header, and not require the user to pass two strings that we append to each other.
- We should allow adding the header after instantiation. A
setHeader()
method would work for this but I think a much better idea is just having asetRequestOptions()
method.
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.
Let's simplify this to just having a RequestOptions
field.
Signed-off-by: Nurym <[email protected]>
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.
LGTM, not sure this is the "final solution" but should work for now until we figure out something better!
@dbwiddis I'm not clear with what does this change actually does? Talks about adding identity/authorization headers but all I see is a setter and the default value replaced? |
Per the issue being addressed, #430:
Such editing was explored earlier in this PR in commits now superceded, such as this one: public void search(SearchRequest request, ActionListener<SearchResponse> listener) {
RequestOptions options = RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", "Bearer TOKEN_HERE").build();
restHighLevelClient.searchAsync(request, options, listener);
} Of course, that solution hard codes a string as the token, which obviously doesn't work. But it points out the fact that if we want to use Given the singleton nature of our RestClient, we can accept an incoming Is this the final solution? I doubt it. It's not thread safe. There are other client changes needed per #612. This is also just a hack to our (deprecated) client used to aid migration, see also #625. Per my approval comment:
If you have a better idea, this would be a good time to post it! |
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.
@dbwiddis this PR handles the Request Options and provides a way to add a new header to the async requets and not use only the DEFAULT one. It doesn't actually adds identity/authorization headers
. A little confusing PR title got me thinking in the first place.
Signed-off-by: Nurym <[email protected]>
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.
Still few places left to replace RequestOptions.DEFAULT;
value with options
like this. We should add options for all the clients which have DEFAULT currently.
Signed-off-by: Nurym <[email protected]>
I'm not so sure we should be adding more stuff to the Java Clients, rather than just documenting how to use them. Do we actually have anything wrapped in the other clients yet? |
That was regards to |
Ah, sorry, I missed that context. Yes the options should be at the highest level of the Rest Client and copied to the other clients. If we removed the |
* added method headersToRequest Signed-off-by: Nurym <[email protected]> * creating a new equest ptions object Signed-off-by: Nurym <[email protected]> * set on the client Signed-off-by: Nurym <[email protected]> * added setter for requestoptions Signed-off-by: Nurym <[email protected]> * Merge branch 'main' into RepositoryExtension Signed-off-by: Nurym <[email protected]> * added options for all request Signed-off-by: Nurym <[email protected]> * added options for all request Signed-off-by: Nurym <[email protected]> --------- Signed-off-by: Nurym <[email protected]> Co-authored-by: Owais Kazi <[email protected]> (cherry picked from commit 0506955) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* added method headersToRequest * creating a new equest ptions object * set on the client * added setter for requestoptions * Merge branch 'main' into RepositoryExtension * added options for all request * added options for all request --------- (cherry picked from commit 0506955) Signed-off-by: Nurym <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Owais Kazi <[email protected]>
Description
Here I create a new Request Options object based on Request Options.DEFAULT using the to Builder() method, add the "Authorization" header with the token, and build a new RequestOptions object using the build() method.
Issues Resolved
#430
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.