This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.8 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit a84632a72a0fbca173981987b0a40a8f44e7826a Author: Neng Lu <[email protected]> AuthorDate: Wed Nov 24 18:31:45 2021 -0800 [function] pulsar admin exposes secrets for function (#12950) ### Motivation Fixes #12834 ### Modifications add the `--secrets` argument into `pulsar-admin functions create/update/localrun` command (cherry picked from commit 9c0cee959e0f215a9a33adca98948f3a5fdf2dfa) --- .../main/java/org/apache/pulsar/admin/cli/CmdFunctions.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java index 722aa6b..1f5bd4f 100644 --- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java +++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java @@ -37,6 +37,7 @@ import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Type; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -319,6 +320,8 @@ public class CmdFunctions extends CmdBase { protected Integer maxMessageRetries; @Parameter(names = "--custom-runtime-options", description = "A string that encodes options to customize the runtime, see docs for configured runtime for details") protected String customRuntimeOptions; + @Parameter(names = "--secrets", description = "The map of secretName to an object that encapsulates how the secret is fetched by the underlying secrets provider") + protected String secretsString; @Parameter(names = "--dead-letter-topic", description = "The topic where messages that are not processed successfully are sent to") protected String deadLetterTopic; protected FunctionConfig functionConfig; @@ -490,6 +493,15 @@ public class CmdFunctions extends CmdBase { functionConfig.setCustomRuntimeOptions(customRuntimeOptions); } + if (secretsString != null) { + Type type = new TypeToken<Map<String, Object>>() {}.getType(); + Map<String, Object> secretsMap = new Gson().fromJson(secretsString, type); + if (secretsMap == null) { + secretsMap = Collections.emptyMap(); + } + functionConfig.setSecrets(secretsMap); + } + // window configs WindowConfig windowConfig = functionConfig.getWindowConfig(); if (null != windowLengthCount) {
