-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 withDefaultHeaders to connection configuration for ElasticsearchIO #25024
Conversation
Assigning reviewers. If you would like to opt out of this review, comment R: @apilloud for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Thanks @EgbertW ! To fix up the I noticed also that there are unit test failures due to compilation failures. You can run tests locally by running one of the ES test suites like |
@@ -514,6 +521,8 @@ public ConnectionConfiguration withApiKey(String apiKey) { | |||
|
|||
/** | |||
* If Elasticsearch authentication is enabled, provide a bearer token. | |||
* Be aware that you can only use one of {@Code withApiToken()}, {@code withBearerToken()} and | |||
* {@code withDefaultHeaders} at the same time, as they will override eachother. |
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.
Is there a reasonable way to add Precondition checks to try to alert the user when these mutually exclusive fields have been used in conjunction?
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.
There is but I didn't add it because the same issue was already lurking with just withApiKey
and withBearerToken
. I added checks to all three methods now to check that only one is used at a time - see my last update.
I'm not denying the utility here, but I'm not 100% clear on how this addresses #25018. Could you elaborate on how this technique can be used to work with short-lived credentials? |
Of course. What I did to work with short-lived tokens is create a new header class, something resembling:
Since the Elasticsearch RestClient will add the |
Ah, that is helpful. I just did and fixed the formatting and the compile error - I was using a newer feature that isn't available in Java 8. |
Aha! Very nice 😊 I think this kind of detail might be non-obvious to many users who might want to accomplish the same. Could you please add this example to the docstring for |
...ava/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java
Outdated
Show resolved
Hide resolved
...ava/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java
Show resolved
Hide resolved
I just updated the PR with this example added to the docstring. |
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 @EgbertW ! I’ll merge after all the workflows pass, which I expect them to 😊 Hopefully this can make the 2.45.0 cut scheduled for today!
Thanks for merging! Looking forward to seeing it in the next release :) |
Addresses #25018
This PR adds a
withDefaultHeaders
setting to the ElasticsearchIO ConnectionConfiguration. This allows you to provide any type oforg.apache.http.Header
instead of sticking to the built-inApiKey
andBearer
headers supported already. In a way, their functionality could be implemented using this option instead if desirable.This addresses #25018 - it allows to create a custom class implementing
org.apache.http.Header
that manages the bearer token lifecycle and use this with ElasticsearchIO - this all without imposing any specifics in the ElasticsearchIO library.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.