Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sriram22
Copy link

@sriram22 sriram22 commented Jan 17, 2025

Adding support for apikey to elasticsearch low level rest client
Fixes #45490

Copy link

quarkus-bot bot commented Jan 17, 2025

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)
  • description should not be empty, describe your intent or provide links to the issues this PR is fixing (using Fixes #NNNNN) or changelogs

This message is automatically generated by a bot.

Copy link

quarkus-bot bot commented Jan 17, 2025

/cc @gsmet (elasticsearch), @loicmathieu (elasticsearch), @marko-bekhta (elasticsearch)

Copy link
Contributor

@marko-bekhta marko-bekhta left a 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()) {
Copy link
Contributor

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 )

@sriram22 sriram22 changed the title changes to include apikey configuration for elastic search rest client Changes to include apikey configuration for elastic search rest client Jan 17, 2025
/**
* The API Key ID for Elasticsearch authentication.
*/
Optional<String> apiKeyId();
Copy link
Contributor

@manofthepeace manofthepeace Jan 17, 2025

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.

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add apikey authentication support to quarkus-elasticsearch-rest-client
3 participants