Closed MonksterFX closed 2 years ago
Unfortunately, this is not implemented yet. All config options can be seen in the class ElasticSearchConfig.java and the client is initialized at ElasticSearchClientFactory.java. I think modifying these two classes should be enough to make this work (assuming Elastic Cloud uses HTTP basic auth).
Thanks to pointing me in the right direction. If anyone else need to do this follow along with:
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html
// ElasticSearchClientFactory.java
public static RestClient createClient(ElasticSearchConfig config) {
HttpHost[] httpHosts = parseHostAddresses(config.getRestApiHosts());
final CredentialsProvider credentialsProvider =
new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(config.getUsername(), config.getPassword()));
final RestClientBuilder builder = RestClient.builder(httpHosts)
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
.setConnectTimeout(config.getRestConnectTimeout())
.setSocketTimeout(config.getRestSocketTimeout())
)
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(
HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder
.setDefaultCredentialsProvider(credentialsProvider);
}
})
.setMaxRetryTimeoutMillis(config.getRestMaxRetryTimeoutMillis());
...
config.getUsername()
and config.getPassword()
could be easily added to ElasticSearchConfig.java
Thanks, @MonksterFX! I just added this to the dev
branch and will merge it into the master later if there are no problems.
Is there a easy way to pass credentials to the Elastic Client? Or is it necessary to implement this as a new feature? Would expect some input from config like that: