exceptionfactory commented on code in PR #11784:
URL: https://github.com/apache/nifi/pull/11784#discussion_r4239260052


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenFTP.java:
##########
@@ -119,9 +122,45 @@ public class ListenFTP extends 
AbstractSessionFactoryProcessor implements Listen
             .sensitive(true)
             .build();
 
+    private static final Pattern PORT_RANGE_PATTERN = 
Pattern.compile("^(\\d{1,5})-(\\d{1,5})$");
+
+    private static final Validator PORT_RANGE_VALIDATOR = (subject, input, 
context) -> {
+        if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
+            return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
 Language Present").valid(true).build();
+        }
+
+        final String explanation;
+        final Matcher matcher = PORT_RANGE_PATTERN.matcher(input);
+        if (matcher.matches()) {
+            final int startPort = Integer.parseInt(matcher.group(1));
+            final int endPort = Integer.parseInt(matcher.group(2));
+            if (startPort < 1 || endPort > 65535) {
+                explanation = "Ports must be between 1 and 65535";
+            } else if (startPort > endPort) {
+                explanation = "Start port must be less than or equal to end 
port";
+            } else {
+                explanation = null;
+            }
+        } else {
+            explanation = "Port range must be in the format <start>-<end>, 
e.g. 50000-50099";
+        }
+        return new 
ValidationResult.Builder().subject(subject).input(input).explanation(explanation).valid(explanation
 == null).build();
+    };
+
+    public static final PropertyDescriptor PASSIVE_PORT_RANGE = new 
PropertyDescriptor.Builder()
+            .name("Passive Port Range")
+            .description("The range of ports, in the format <start>-<end> 
(e.g. 50000-50099), that the FTP server uses for data connections in passive 
mode. "
+                    + "Restricting the range simplifies firewall and container 
port mapping configurations. "
+                    + "If not set, any available port is used for each passive 
data connection.")
+            .required(false)

Review Comment:
   Instead of making this property optional, what do you think about having a 
default of `1025-65534`?



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenFTP.java:
##########
@@ -119,9 +122,45 @@ public class ListenFTP extends 
AbstractSessionFactoryProcessor implements Listen
             .sensitive(true)
             .build();
 
+    private static final Pattern PORT_RANGE_PATTERN = 
Pattern.compile("^(\\d{1,5})-(\\d{1,5})$");
+
+    private static final Validator PORT_RANGE_VALIDATOR = (subject, input, 
context) -> {
+        if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
+            return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
 Language Present").valid(true).build();
+        }
+
+        final String explanation;
+        final Matcher matcher = PORT_RANGE_PATTERN.matcher(input);
+        if (matcher.matches()) {
+            final int startPort = Integer.parseInt(matcher.group(1));
+            final int endPort = Integer.parseInt(matcher.group(2));
+            if (startPort < 1 || endPort > 65535) {
+                explanation = "Ports must be between 1 and 65535";
+            } else if (startPort > endPort) {
+                explanation = "Start port must be less than or equal to end 
port";
+            } else {
+                explanation = null;
+            }
+        } else {
+            explanation = "Port range must be in the format <start>-<end>, 
e.g. 50000-50099";
+        }
+        return new 
ValidationResult.Builder().subject(subject).input(input).explanation(explanation).valid(explanation
 == null).build();

Review Comment:
   For readability, it would be helpful to have each method call on one line.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenFTP.java:
##########
@@ -119,9 +122,45 @@ public class ListenFTP extends 
AbstractSessionFactoryProcessor implements Listen
             .sensitive(true)
             .build();
 
+    private static final Pattern PORT_RANGE_PATTERN = 
Pattern.compile("^(\\d{1,5})-(\\d{1,5})$");
+
+    private static final Validator PORT_RANGE_VALIDATOR = (subject, input, 
context) -> {
+        if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
+            return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
 Language Present").valid(true).build();
+        }
+
+        final String explanation;
+        final Matcher matcher = PORT_RANGE_PATTERN.matcher(input);
+        if (matcher.matches()) {
+            final int startPort = Integer.parseInt(matcher.group(1));
+            final int endPort = Integer.parseInt(matcher.group(2));
+            if (startPort < 1 || endPort > 65535) {
+                explanation = "Ports must be between 1 and 65535";
+            } else if (startPort > endPort) {
+                explanation = "Start port must be less than or equal to end 
port";
+            } else {
+                explanation = null;
+            }
+        } else {
+            explanation = "Port range must be in the format <start>-<end>, 
e.g. 50000-50099";
+        }
+        return new 
ValidationResult.Builder().subject(subject).input(input).explanation(explanation).valid(explanation
 == null).build();
+    };
+
+    public static final PropertyDescriptor PASSIVE_PORT_RANGE = new 
PropertyDescriptor.Builder()
+            .name("Passive Port Range")
+            .description("The range of ports, in the format <start>-<end> 
(e.g. 50000-50099), that the FTP server uses for data connections in passive 
mode. "

Review Comment:
   A multiline string should be used instead of concatenation for descriptions.



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