-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes to include apikey configuration for elastic search rest client #45688
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! Your pull request does not follow our editorial rules. Could you have a look?
This message is automatically generated by a bot. |
/cc @gsmet (elasticsearch), @loicmathieu (elasticsearch), @marko-bekhta (elasticsearch) |
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.
Hey @sriram22,
Thanks for the PR. I've added a comment inline and you might also want to take a look at that message from the quarkus bot 😉😃.
@@ -63,6 +68,15 @@ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpCli | |||
credentialsProvider.setCredentials(AuthScope.ANY, | |||
new UsernamePasswordCredentials(config.username().get(), config.password().orElse(null))); | |||
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | |||
} else if (config.apiKeyId().isPresent() && config.apiKeySecret().isPresent()) { |
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.
We probably should add a bit more validation... e.g. we should check that only one auth method is configured, and if there are both, we should let the user know (since we'd only apply one). And we probably would want to check that outside of the customize method 🤔
Also, maybe it's worth creating a small enum with auth methods, e.g. NONE, BASIC, API_KEY
where you'd have a method that applies required transformations and here in the customizer you'd just make a call authMethod.apply(builder, config )
/** | ||
* The API Key ID for Elasticsearch authentication. | ||
*/ | ||
Optional<String> apiKeyId(); |
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.
Since both apiKeyId and apiKeySecret are needed or not I think this should be in a nested interface like this;
@WithParentName
Optional<EsAuth> esAuth()
interface EsAuth {
String apiKeyId
String apiKeySecret
}
This way the code can just check for esAuth.isPresent()
esAuth is a quick name just as an example. WithParentName only if you do not want to have an extra level to the config.
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.
used this as reference for configuration https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_other_authentication_methods.html#_elasticsearch_api_keys but looks like the apikey generated from elastic search already has base64 encoded apikeyid and secret. nevertheless i have made updates
Adding support for apikey to elasticsearch low level rest client
Fixes #45490