Skip to content

Commit b080f4c

Browse files
committed
NIFI-13015: Incorporated review comments
1 parent 47d72e4 commit b080f4c

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

nifi-extension-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.nifi.annotation.behavior.Restricted;
3434
import org.apache.nifi.annotation.behavior.Restriction;
3535
import org.apache.nifi.annotation.behavior.Stateful;
36+
import org.apache.nifi.annotation.behavior.SupportsSensitiveDynamicProperties;
3637
import org.apache.nifi.annotation.documentation.CapabilityDescription;
3738
import org.apache.nifi.annotation.documentation.SeeAlso;
3839
import org.apache.nifi.annotation.documentation.Tags;
@@ -80,17 +81,16 @@
8081
@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
8182
description = "Scripts can store and retrieve state using the State Management APIs. Consult the State Manager section of the Developer's Guide for more details.")
8283
@SeeAlso(classNames = {"org.apache.nifi.processors.script.ExecuteScript"})
84+
@SupportsSensitiveDynamicProperties
8385
@DynamicProperty(name = "A script engine property to update",
8486
value = "The value to set it to",
8587
expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES,
8688
description = "Updates a script engine property specified by the Dynamic Property's key with the value specified by the Dynamic Property's value. "
8789
+ "Use `CTL.` to access any controller services, `SQL.` to access any DBCPServices, `RecordReader.` to access RecordReaderFactory instances, or "
88-
+ "`RecordWriter.` to access any RecordSetWriterFactory instances. Use `SENSITIVE.` to mark the property as sensitive.")
90+
+ "`RecordWriter.` to access any RecordSetWriterFactory instances.")
8991
public class ExecuteGroovyScript extends AbstractProcessor {
9092
public static final String GROOVY_CLASSPATH = "${groovy.classes.path}";
9193

92-
protected static final String SENSITIVE_PROPERTY_PREFIX = "SENSITIVE.";
93-
9494
private static final String PRELOADS = "import org.apache.nifi.components.*;" + "import org.apache.nifi.flowfile.FlowFile;" + "import org.apache.nifi.processor.*;"
9595
+ "import org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult;" + "import org.apache.nifi.processor.exception.*;" + "import org.apache.nifi.processor.io.*;"
9696
+ "import org.apache.nifi.processor.util.*;" + "import org.apache.nifi.processors.script.*;" + "import org.apache.nifi.logging.ComponentLog;";
@@ -545,18 +545,13 @@ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String
545545
.build();
546546
}
547547

548-
final PropertyDescriptor.Builder builder = new PropertyDescriptor.Builder()
548+
return new PropertyDescriptor.Builder()
549549
.name(propertyDescriptorName)
550550
.required(false)
551551
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
552552
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
553-
.dynamic(true);
554-
555-
if (propertyDescriptorName.startsWith(SENSITIVE_PROPERTY_PREFIX)) {
556-
builder.sensitive(true);
557-
}
558-
559-
return builder.build();
553+
.dynamic(true)
554+
.build();
560555
}
561556

562557
/** simple HashMap with exception on access of non-existent key */

nifi-extension-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/test/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScriptTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import groovy.json.JsonOutput;
2020
import groovy.json.JsonSlurper;
2121
import org.apache.commons.io.FileUtils;
22+
import org.apache.nifi.components.PropertyDescriptor;
2223
import org.apache.nifi.controller.AbstractControllerService;
2324
import org.apache.nifi.dbcp.DBCPService;
25+
import org.apache.nifi.expression.ExpressionLanguageScope;
2426
import org.apache.nifi.processor.exception.ProcessException;
27+
import org.apache.nifi.processor.util.StandardValidators;
2528
import org.apache.nifi.serialization.RecordSetWriterFactory;
2629
import org.apache.nifi.serialization.record.MockRecordParser;
2730
import org.apache.nifi.serialization.record.MockRecordWriter;
@@ -556,9 +559,17 @@ public void test_attribute_passed_to_SQL() {
556559

557560
@Test
558561
public void test_sensitive_dynamic_property() throws Exception {
559-
runner.setProperty("SENSITIVE.password", "MyP@ssW0rd!");
562+
new PropertyDescriptor.Builder()
563+
.name("password")
564+
.required(false)
565+
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
566+
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
567+
.dynamic(true)
568+
.sensitive(true)
569+
.build();
570+
runner.setProperty("password", "MyP@ssW0rd!");
560571
runner.setProperty(ExecuteGroovyScript.SCRIPT_BODY,
561-
"assert context.getProperties().find {k,v -> k.name == 'SENSITIVE.password'}.key.sensitive");
572+
"assert context.getProperties().find {k,v -> k.name == 'password'}.key.sensitive");
562573
runner.assertValid();
563574
runner.run();
564575
}

0 commit comments

Comments
 (0)