exceptionfactory commented on a change in pull request #5028:
URL: https://github.com/apache/nifi/pull/5028#discussion_r621502741



##########
File path: 
nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
##########
@@ -151,7 +152,24 @@ public ValidationResult validate(final String subject, 
final String value, final
         }
     };
 
-    public static final Validator PORT_VALIDATOR = createLongValidator(1, 
65535, true);
+    public static final Validator NETWORK_ADDRESS_VALIDATOR = new Validator() {
+        private final Pattern ipv4Pattern = 
Pattern.compile("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!$)|$)){4}$");
+
+        @Override
+        public ValidationResult validate(final String subject, final String 
value, final ValidationContext context) {
+
+            final String reason = "not a valid IP address";
+            final boolean isValidInetAddress = "localhost".equals(value) || 
isValid(value);
+            return new 
ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(isValidInetAddress).build();
+        }
+
+        private boolean isValid(final String email) {
+            Matcher matcher = ipv4Pattern.matcher(email);
+            return matcher.matches();
+        }
+    };
+
+    public static final Validator PORT_VALIDATOR = createLongValidator(0, 
65535, true);

Review comment:
       Thanks for the reference, it seems like `0` should be acceptable in some 
cases where a random port number could be useful.  Some existing components 
rely on an explicit port number, so I think the best approach is to leave the 
existing `PORT_VALIDATOR` as it is, but create a new port validator that allows 
`0` to indicate preference for a dynamic port number.




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


Reply via email to