This is an automated email from the ASF dual-hosted git repository. rdhabalia pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push: new 7a65f3ff907 merge conflicts (#16961) 7a65f3ff907 is described below commit 7a65f3ff907385af4b115f300324e5ec60aa25ac Author: vineeth1995 <vineethreddypo...@gmail.com> AuthorDate: Fri Aug 5 14:32:27 2022 -0700 merge conflicts (#16961) Co-authored-by: Vineeth <vineeth.polamre...@verizonmedia.com> --- .../pulsar/client/cli/PulsarClientToolTest.java | 26 ++++++++++++++++++++++ .../apache/pulsar/client/cli/PulsarClientTool.java | 11 +++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolTest.java b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolTest.java index 4a1589250ad..5cc5e50b96d 100644 --- a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolTest.java +++ b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/client/cli/PulsarClientToolTest.java @@ -29,6 +29,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.beust.jcommander.JCommander; import lombok.Cleanup; import org.apache.pulsar.broker.service.BrokerTestBase; import org.apache.pulsar.client.admin.PulsarAdminException; @@ -269,6 +270,31 @@ public class PulsarClientToolTest extends BrokerTestBase { } } + @Test(timeOut = 20000) + public void testArgs() throws Exception { + PulsarClientTool pulsarClientTool = new PulsarClientTool(new Properties()); + final String url = "pulsar+ssl://localhost:6651"; + final String authPlugin = "org.apache.pulsar.client.impl.auth.AuthenticationTls"; + final String authParams = "tlsCertFile:pulsar-broker/src/test/resources/authentication/tls/client-cert.pem," + + "tlsKeyFile:pulsar-broker/src/test/resources/authentication/tls/client-key.pem"; + final String tlsTrustCertsFilePath = "pulsar/pulsar-broker/src/test/resources/authentication/tls/cacert.pem"; + final String message = "test msg"; + final int numberOfMessages = 1; + final String topicName = getTopicWithRandomSuffix("test-topic"); + + String[] args = {"--url", url, + "--auth-plugin", authPlugin, + "--auth-params", authParams, + "--tlsTrustCertsFilePath", tlsTrustCertsFilePath, + "produce", "-m", message, + "-n", Integer.toString(numberOfMessages), topicName}; + pulsarClientTool.jcommander.parse(args); + assertEquals(pulsarClientTool.rootParams.getTlsTrustCertsFilePath(), tlsTrustCertsFilePath); + assertEquals(pulsarClientTool.rootParams.getAuthParams(), authParams); + assertEquals(pulsarClientTool.rootParams.getAuthPluginClassName(), authPlugin); + assertEquals(pulsarClientTool.rootParams.getServiceURL(), url); + } + private static String getTopicWithRandomSuffix(String localNameBase) { return String.format("persistent://prop/ns-abc/test/%s-%s", localNameBase, UUID.randomUUID().toString()); } diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/PulsarClientTool.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/PulsarClientTool.java index 32770f3bd07..648505b7d75 100644 --- a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/PulsarClientTool.java +++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/PulsarClientTool.java @@ -72,15 +72,19 @@ public class PulsarClientTool { @Parameter(names = { "-h", "--help", }, help = true, description = "Show this help.") boolean help; + + @Parameter(names = { "--tlsTrustCertsFilePath" }, description = "File path to client trust certificates") + String tlsTrustCertsFilePath; } protected RootParams rootParams; boolean tlsAllowInsecureConnection; boolean tlsEnableHostnameVerification; - String tlsTrustCertsFilePath; + String tlsKeyFilePath; String tlsCertificateFilePath; + // for tls with keystore type config boolean useKeyStoreTls; String tlsTrustStoreType; @@ -103,8 +107,6 @@ public class PulsarClientTool { .parseBoolean(properties.getProperty("tlsAllowInsecureConnection", "false")); this.tlsEnableHostnameVerification = Boolean .parseBoolean(properties.getProperty("tlsEnableHostnameVerification", "false")); - this.tlsTrustCertsFilePath = properties.getProperty("tlsTrustCertsFilePath"); - this.useKeyStoreTls = Boolean .parseBoolean(properties.getProperty("useKeyStoreTls", "false")); this.tlsTrustStoreType = properties.getProperty("tlsTrustStoreType", "JKS"); @@ -143,6 +145,7 @@ public class PulsarClientTool { } this.rootParams.authPluginClassName = properties.getProperty("authPlugin"); this.rootParams.authParams = properties.getProperty("authParams"); + this.rootParams.tlsTrustCertsFilePath = properties.getProperty("tlsTrustCertsFilePath"); } private void updateConfig() throws UnsupportedAuthenticationException { @@ -160,7 +163,7 @@ public class PulsarClientTool { clientBuilder.enableTlsHostnameVerification(this.tlsEnableHostnameVerification); clientBuilder.serviceUrl(rootParams.serviceURL); - clientBuilder.tlsTrustCertsFilePath(this.tlsTrustCertsFilePath) + clientBuilder.tlsTrustCertsFilePath(this.rootParams.tlsTrustCertsFilePath) .tlsKeyFilePath(tlsKeyFilePath) .tlsCertificateFilePath(tlsCertificateFilePath);