diff --git a/pulsar-functions/instance/pom.xml b/pulsar-functions/instance/pom.xml
index c0d68cad72e27..a2f4d2fd50b0f 100644
--- a/pulsar-functions/instance/pom.xml
+++ b/pulsar-functions/instance/pom.xml
@@ -269,6 +269,15 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ some-configuration
+
+
+
diff --git a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
index c3f36f754daca..691e547256a7e 100644
--- a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
+++ b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
@@ -862,11 +862,7 @@ private void setupInput(ContextImpl contextImpl) throws Exception {
Thread.currentThread().setContextClassLoader(this.componentClassLoader);
}
try {
- if (sourceSpec.getConfigs().isEmpty()) {
- this.source.open(new HashMap<>(), contextImpl);
- } else {
- this.source.open(parseComponentConfig(sourceSpec.getConfigs()), contextImpl);
- }
+ this.source.open(augmentAndFilterConnectorConfig(sourceSpec.getConfigs()), contextImpl);
if (this.source instanceof PulsarSource) {
contextImpl.setInputConsumers(((PulsarSource) this.source).getInputConsumers());
}
@@ -877,31 +873,60 @@ private void setupInput(ContextImpl contextImpl) throws Exception {
Thread.currentThread().setContextClassLoader(this.instanceClassLoader);
}
}
- private Map parseComponentConfig(String connectorConfigs) throws IOException {
- return parseComponentConfig(connectorConfigs, instanceConfig, componentClassLoader, componentType);
+
+ /**
+ * Recursively interpolate configured secrets into the config map by calling
+ * {@link SecretsProvider#interpolateSecretForValue(String)}.
+ * @param secretsProvider - the secrets provider that will convert secret's values into config values.
+ * @param configs - the connector configuration map, which will be mutated.
+ */
+ private static void interpolateSecretsIntoConfigs(SecretsProvider secretsProvider,
+ Map configs) {
+ for (Map.Entry entry : configs.entrySet()) {
+ Object value = entry.getValue();
+ if (value instanceof String) {
+ String updatedValue = secretsProvider.interpolateSecretForValue((String) value);
+ if (updatedValue != null) {
+ entry.setValue(updatedValue);
+ }
+ } else if (value instanceof Map) {
+ interpolateSecretsIntoConfigs(secretsProvider, (Map) value);
+ }
+ }
+ }
+
+ private Map augmentAndFilterConnectorConfig(String connectorConfigs) throws IOException {
+ return augmentAndFilterConnectorConfig(connectorConfigs, instanceConfig, secretsProvider,
+ componentClassLoader, componentType);
}
- static Map parseComponentConfig(String connectorConfigs,
- InstanceConfig instanceConfig,
- ClassLoader componentClassLoader,
- org.apache.pulsar.functions.proto.Function
+ static Map augmentAndFilterConnectorConfig(String connectorConfigs,
+ InstanceConfig instanceConfig,
+ SecretsProvider secretsProvider,
+ ClassLoader componentClassLoader,
+ org.apache.pulsar.functions.proto.Function
.FunctionDetails.ComponentType componentType)
throws IOException {
- final Map config = ObjectMapperFactory
+ final Map config = connectorConfigs.isEmpty() ? new HashMap<>() : ObjectMapperFactory
.getMapper()
.reader()
.forType(new TypeReference