Skip to content

Commit 785c70c

Browse files
authored
NIFI-13015 Support Sensitive Dynamic Properties in ExecuteGroovyScript (apache#9879)
Signed-off-by: David Handermann <exceptionfactory@apache.org>
1 parent 40bb150 commit 785c70c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 3 additions & 0 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,6 +81,7 @@
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,
@@ -542,6 +544,7 @@ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String
542544
.identifiesControllerService(RecordSetWriterFactory.class)
543545
.build();
544546
}
547+
545548
return new PropertyDescriptor.Builder()
546549
.name(propertyDescriptorName)
547550
.required(false)

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

Lines changed: 20 additions & 1 deletion
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;
@@ -40,7 +43,6 @@
4043
import org.junit.jupiter.api.condition.DisabledOnOs;
4144
import org.junit.jupiter.api.condition.OS;
4245
import org.junit.jupiter.api.io.TempDir;
43-
4446
import java.io.ByteArrayOutputStream;
4547
import java.io.File;
4648
import java.io.FileInputStream;
@@ -555,6 +557,23 @@ public void test_attribute_passed_to_SQL() {
555557
assertEquals("testDB", ((DBCPServiceSimpleImpl) dbcp).getDatabaseName());
556558
}
557559

560+
@Test
561+
public void test_sensitive_dynamic_property() throws Exception {
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!");
571+
runner.setProperty(ExecuteGroovyScript.SCRIPT_BODY,
572+
"assert context.getProperties().find {k,v -> k.name == 'password'}.key.sensitive");
573+
runner.assertValid();
574+
runner.run();
575+
}
576+
558577

559578
private HashMap<String, String> map(String key, String value) {
560579
HashMap<String, String> attrs = new HashMap<>();

0 commit comments

Comments
 (0)