EgbertW commented on code in PR #25024:
URL: https://github.com/apache/beam/pull/25024#discussion_r1073131415


##########
sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java:
##########
@@ -501,29 +506,55 @@ public ConnectionConfiguration withPassword(String 
password) {
     }
 
     /**
-     * If Elasticsearch authentication is enabled, provide an API key.
+     * If Elasticsearch authentication is enabled, provide an API key. Be 
aware that you can only
+     * use one of {@Code withApiToken()}, {@code withBearerToken()} and {@code 
withDefaultHeaders}
+     * at the same time, as they (potentially) use the same header.
      *
      * @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(!Strings.isNullOrEmpty(apiKey), "apiKey can not be null or 
empty");
+      checkArgument(getBearerToken() == null, "apiKey can not be combined with 
bearerToken");
+      checkArgument(getDefaultHeaders() == null, "apiKey can not be combined 
with defaultHeaders");
       return builder().setApiKey(apiKey).build();
     }
 
     /**
-     * If Elasticsearch authentication is enabled, provide a bearer token.
+     * 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 (potentially) use the 
same header.
      *
      * @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(!Strings.isNullOrEmpty(bearerToken), "bearerToken can not 
be null or empty");
+      checkArgument(getApiKey() == null, "bearerToken can not be combined with 
apiKey");
+      checkArgument(getDefaultHeaders() == null, "apiKey can not be combined 
with defaultHeaders");
       return builder().setBearerToken(bearerToken).build();
     }
 
+    /**
+     * For authentication or custom requirements, provide a set if default 
headers for the client.
+     * Be aware that you can only use one of {@code withApiToken()}, {@code 
withBearerToken()} and
+     * {@code withDefaultHeaders} at the same time, as they (potentially) use 
the same header.
+     *
+     * @param defaultHeaders the headers to add to outgoing requests
+     * @return a {@link ConnectionConfiguration} describes a connection 
configuration to
+     *     Elasticsearch.
+     */
+    public ConnectionConfiguration withDefaultHeaders(Header[] defaultHeaders) 
{

Review Comment:
   Main reason is to mimic what is happening in e.g. the `create()` method that 
accepts an array `String[] addresses` which is converted to a list, where this 
list is used again to instantiate an array.
   
   Secondary reason is the assumption that the class is trying to avoid the use 
of mutable Lists, so a copy would need to be made anyway.
   
   Third reason is that `AutoValue` doesn't understand non-primitive arrays. 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to