zhisheng17 commented on a change in pull request #11822:
URL: https://github.com/apache/flink/pull/11822#discussion_r417035037



##########
File path: 
flink-connectors/flink-connector-elasticsearch-base/src/main/java/org/apache/flink/table/descriptors/ElasticsearchValidator.java
##########
@@ -76,12 +78,20 @@ public void validate(DescriptorProperties properties) {
                properties.validateValue(CONNECTOR_TYPE, 
CONNECTOR_TYPE_VALUE_ELASTICSEARCH, false);
                validateVersion(properties);
                validateHosts(properties);
+               validateAuth(properties);
                validateGeneralProperties(properties);
                validateFailureHandler(properties);
                validateBulkFlush(properties);
                validateConnectionProperties(properties);
        }
 
+       private void validateAuth(DescriptorProperties properties) {
+               if (properties.containsKey(CONNECTOR_USERNAME) || 
properties.containsKey(CONNECTOR_PASSWORD)) {
+                       properties.validateString(CONNECTOR_USERNAME, false, 1);
+                       properties.validateString(CONNECTOR_PASSWORD, false, 1);

Review comment:
       @KarmaGYZ  if username is not empty and password is empty, 
   
   ```java
   properties.validateString(CONNECTOR_USERNAME, false, 1);
   properties.validateString(CONNECTOR_PASSWORD, false, 1);
   ```
   
   I will check the two property must required, not Optional. that case, will 
throw ValidationException in validateOptional function
   
   ```java
   public void validateString(String key, boolean isOptional, int minLen) {
                validateString(key, isOptional, minLen, Integer.MAX_VALUE);
        }
   
        public void validateString(String key, boolean isOptional, int minLen, 
int maxLen) {
                validateOptional(
                        key,
                        isOptional,
                        (value) -> {
                                final int length = value.length();
                                if (length < minLen || length > maxLen) {
                                        throw new ValidationException(
                                                "Property '" + key + "' must 
have a length between " + minLen + " and " + maxLen + " but was: " + value);
                                }
                        });
        }
   
        private void validateOptional(String key, boolean isOptional, 
Consumer<String> valueValidation) {
                if (!properties.containsKey(key)) {
                        if (!isOptional) {
                                throw new ValidationException("Could not find 
required property '" + key + "'.");
                        }
                } else {
                        final String value = properties.get(key);
                        valueValidation.accept(value);
                }
        }
   ```
   




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to