sijie closed pull request #2922: Always cover gson generated json with quotes
URL: https://github.com/apache/pulsar/pull/2922
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-functions/instance/src/main/python/python_instance_main.py 
b/pulsar-functions/instance/src/main/python/python_instance_main.py
index cc68fb0290..d2562697f3 100644
--- a/pulsar-functions/instance/src/main/python/python_instance_main.py
+++ b/pulsar-functions/instance/src/main/python/python_instance_main.py
@@ -154,6 +154,11 @@ def main():
   secrets_provider = secrets_provider()
   secrets_provider_config = None
   if args.secrets_provider_config is not None:
+    args.secrets_provider_config = str(args.secrets_provider_config)
+    if args.secrets_provider_config[0] == '\'':
+      args.secrets_provider_config = args.secrets_provider_config[1:]
+    if args.secrets_provider_config[-1] == '\'':
+      args.secrets_provider_config = args.secrets_provider_config[:-1]
     secrets_provider_config = json.loads(str(args.secrets_provider_config))
   secrets_provider.init(secrets_provider_config)
 
diff --git 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
index 80503bb82b..4c9c086dc3 100644
--- 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
+++ 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/JavaInstanceMain.java
@@ -138,6 +138,12 @@ public void start() throws Exception {
 
         Map<String, String> secretsProviderConfigMap = null;
         if (!StringUtils.isEmpty(secretsProviderConfig)) {
+            if (secretsProviderConfig.charAt(0) == '\'') {
+                secretsProviderConfig = secretsProviderConfig.substring(1);
+            }
+            if (secretsProviderConfig.charAt(secretsProviderConfig.length() - 
1) == '\'') {
+                secretsProviderConfig = secretsProviderConfig.substring(0, 
secretsProviderConfig.length() - 1);
+            }
             Type type = new TypeToken<Map<String, String>>() {}.getType();
             secretsProviderConfigMap = new 
Gson().fromJson(secretsProviderConfig, type);
         }
diff --git 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeUtils.java
 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeUtils.java
index f12222ef45..3bc8bffd18 100644
--- 
a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeUtils.java
+++ 
b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeUtils.java
@@ -158,7 +158,7 @@
         args.add(secretsProviderClassName);
         if (!StringUtils.isEmpty(secretsProviderConfig)) {
             args.add("--secrets_provider_config");
-            args.add(secretsProviderConfig);
+            args.add("'" + secretsProviderConfig + "'");
         }
         return args;
     }
diff --git 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/KubernetesRuntimeTest.java
 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/KubernetesRuntimeTest.java
index 5c05de2cae..fb4799745a 100644
--- 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/KubernetesRuntimeTest.java
+++ 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/KubernetesRuntimeTest.java
@@ -20,15 +20,19 @@
 package org.apache.pulsar.functions.runtime;
 
 import com.google.protobuf.util.JsonFormat;
+import io.kubernetes.client.models.V1PodSpec;
 import org.apache.pulsar.functions.instance.InstanceConfig;
 import org.apache.pulsar.functions.proto.Function;
 import org.apache.pulsar.functions.proto.Function.ConsumerSpec;
 import org.apache.pulsar.functions.proto.Function.FunctionDetails;
+import org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider;
 import 
org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator;
+import 
org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator;
 import org.apache.pulsar.functions.utils.FunctionDetailsUtils;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
+import java.lang.reflect.Type;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -53,6 +57,50 @@
                 
ConsumerSpec.newBuilder().setSerdeClassName("").setIsRegexPattern(false).build());
     }
 
+    class TestSecretProviderConfigurator implements 
SecretsProviderConfigurator {
+
+        @Override
+        public void init(Map<String, String> config) {
+
+        }
+
+        @Override
+        public String getSecretsProviderClassName(FunctionDetails 
functionDetails) {
+            if (functionDetails.getRuntime() == FunctionDetails.Runtime.JAVA) {
+                return ClearTextSecretsProvider.class.getName();
+            } else {
+                return "secretsprovider.ClearTextSecretsProvider";
+            }
+        }
+
+        @Override
+        public Map<String, String> getSecretsProviderConfig(FunctionDetails 
functionDetails) {
+            HashMap<String, String> map = new HashMap<>();
+            map.put("Somevalue", "myvalue");
+            return map;
+        }
+
+        @Override
+        public void configureKubernetesRuntimeSecretsProvider(V1PodSpec 
podSpec, String functionsContainerName, FunctionDetails functionDetails) {
+
+        }
+
+        @Override
+        public void configureProcessRuntimeSecretsProvider(ProcessBuilder 
processBuilder, FunctionDetails functionDetails) {
+
+        }
+
+        @Override
+        public Type getSecretObjectType() {
+            return null;
+        }
+
+        @Override
+        public void validateSecretMap(Map<String, Object> secretMap) {
+
+        }
+    }
+
     private final KubernetesRuntimeFactory factory;
     private final String userJarFile;
     private final String pulsarRootDir;
@@ -75,7 +123,7 @@ public KubernetesRuntimeTest() throws Exception {
         this.factory = spy(new KubernetesRuntimeFactory(null, null, null, 
pulsarRootDir,
             false, true, "myrepo", "anotherrepo",
                 null, pulsarServiceUrl, pulsarAdminUrl, 
stateStorageServiceUrl, null, null,
-                null, null, new DefaultSecretsProviderConfigurator()));
+                null, null, new TestSecretProviderConfigurator()));
         doNothing().when(this.factory).setupClient();
     }
 
@@ -124,7 +172,7 @@ public void testJavaConstructor() throws Exception {
 
         KubernetesRuntime container = factory.createContainer(config, 
userJarFile, userJarFile, 30l);
         List<String> args = container.getProcessArgs();
-        assertEquals(args.size(), 30);
+        assertEquals(args.size(), 32);
         String expectedArgs = "java -cp " + javaInstanceJarFile
                 + " -Dpulsar.functions.java.instance.jar=" + 
javaInstanceJarFile
                 + " -Dlog4j.configurationFile=kubernetes_instance_log4j2.yml "
@@ -139,7 +187,8 @@ public void testJavaConstructor() throws Exception {
                 + " --max_buffered_tuples 1024 --port " + args.get(23)
                 + " --state_storage_serviceurl " + stateStorageServiceUrl
                 + " --expected_healthcheck_interval -1"
-                + " --secrets_provider 
org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider";
+                + " --secrets_provider 
org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider"
+                + " --secrets_provider_config '{\"Somevalue\":\"myvalue\"}'";
         assertEquals(String.join(" ", args), expectedArgs);
     }
 
@@ -149,7 +198,7 @@ public void testPythonConstructor() throws Exception {
 
         KubernetesRuntime container = factory.createContainer(config, 
userJarFile, userJarFile, 30l);
         List<String> args = container.getProcessArgs();
-        assertEquals(args.size(), 34);
+        assertEquals(args.size(), 36);
         String expectedArgs = "python " + pythonInstanceFile
                 + " --py " + pulsarRootDir + "/" + userJarFile
                 + " --logging_directory " + logDirectory
@@ -165,7 +214,8 @@ public void testPythonConstructor() throws Exception {
                 + "' --pulsar_serviceurl " + pulsarServiceUrl
                 + " --max_buffered_tuples 1024 --port " + args.get(29)
                 + " --expected_healthcheck_interval -1"
-                + " --secrets_provider 
secretsprovider.ClearTextSecretsProvider";
+                + " --secrets_provider 
secretsprovider.ClearTextSecretsProvider"
+                + " --secrets_provider_config '{\"Somevalue\":\"myvalue\"}'";
         assertEquals(String.join(" ", args), expectedArgs);
     }
 
diff --git 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
index aa385fcf19..bc6222b3f2 100644
--- 
a/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
+++ 
b/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/ProcessRuntimeTest.java
@@ -181,7 +181,7 @@ public void testJavaConstructor() throws Exception {
                 + " --state_storage_serviceurl " + stateStorageServiceUrl
                 + " --expected_healthcheck_interval 30"
                 + " --secrets_provider 
org.apache.pulsar.functions.secretsprovider.ClearTextSecretsProvider"
-                + " --secrets_provider_config {\"Config\":\"Value\"}";
+                + " --secrets_provider_config '{\"Config\":\"Value\"}'";
         assertEquals(String.join(" ", args), expectedArgs);
     }
 
@@ -203,7 +203,7 @@ public void testPythonConstructor() throws Exception {
                 + " --max_buffered_tuples 1024 --port " + args.get(23)
                 + " --expected_healthcheck_interval 30"
                 + " --secrets_provider 
secretsprovider.ClearTextSecretsProvider"
-                + " --secrets_provider_config {\"Config\":\"Value\"}";
+                + " --secrets_provider_config '{\"Config\":\"Value\"}'";
         assertEquals(String.join(" ", args), expectedArgs);
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to