ihji commented on a change in pull request #14345:
URL: https://github.com/apache/beam/pull/14345#discussion_r606039467
##########
File path:
sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java
##########
@@ -329,6 +339,32 @@ public ConnectionConfiguration withPassword(String
password) {
return builder().setPassword(password).build();
}
+ /**
+ * If Elasticsearch authentication is enabled, provide an API key.
+ *
+ * @param apiKey the API key used to authenticate to Elasticsearch
+ * @return a {@link ConnectionConfiguration} describes a connection
configuration to
+ * Elasticsearch.
+ */
+ public ConnectionConfiguration withApiKey(String apiKey) {
+ checkArgument(apiKey != null, "apiKey can not be null");
+ checkArgument(!apiKey.isEmpty(), "apiKey can not be empty");
Review comment:
You might use `Strings.isNullOrEmpty` instead of two checks.
##########
File path:
sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java
##########
@@ -329,6 +339,32 @@ public ConnectionConfiguration withPassword(String
password) {
return builder().setPassword(password).build();
}
+ /**
+ * If Elasticsearch authentication is enabled, provide an API key.
+ *
+ * @param apiKey the API key used to authenticate to Elasticsearch
+ * @return a {@link ConnectionConfiguration} describes a connection
configuration to
+ * Elasticsearch.
+ */
+ public ConnectionConfiguration withApiKey(String apiKey) {
+ checkArgument(apiKey != null, "apiKey can not be null");
+ checkArgument(!apiKey.isEmpty(), "apiKey can not be empty");
+ return builder().setApiKey(apiKey).build();
+ }
+
+ /**
+ * If Elasticsearch authentication is enabled, provide a bearer token.
+ *
+ * @param bearerToken the bearer token used to authenticate to
Elasticsearch
+ * @return a {@link ConnectionConfiguration} describes a connection
configuration to
+ * Elasticsearch.
+ */
+ public ConnectionConfiguration withBearerToken(String bearerToken) {
+ checkArgument(bearerToken != null, "bearerToken can not be null");
+ checkArgument(!bearerToken.isEmpty(), "bearerToken can not be empty");
Review comment:
ditto.
##########
File path:
sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java
##########
@@ -424,6 +460,14 @@ RestClient createClient() throws IOException {
httpAsyncClientBuilder ->
httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
}
+ if (getApiKey() != null) {
+ restClientBuilder.setDefaultHeaders(
+ new Header[] {new BasicHeader("Authorization", "ApiKey " +
getApiKey())});
Review comment:
Is there any way we can test this options easily? If not, never mind.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]