Skip to content

Commit

Permalink
merge conflicts (#16961)
Browse files Browse the repository at this point in the history
Co-authored-by: Vineeth <vineeth.polamreddy@verizonmedia.com>
  • Loading branch information
vineeth1995 and Vineeth authored Aug 5, 2022
1 parent 7650612 commit 7a65f3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -269,6 +270,31 @@ public void testDisableBatching() throws Exception {
}
}

@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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ public static class RootParams {

@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;
Expand All @@ -103,8 +107,6 @@ public PulsarClientTool(Properties properties) {
.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");
Expand Down Expand Up @@ -143,6 +145,7 @@ protected void initRootParamsFromProperties(Properties properties) {
}
this.rootParams.authPluginClassName = properties.getProperty("authPlugin");
this.rootParams.authParams = properties.getProperty("authParams");
this.rootParams.tlsTrustCertsFilePath = properties.getProperty("tlsTrustCertsFilePath");
}

private void updateConfig() throws UnsupportedAuthenticationException {
Expand All @@ -160,7 +163,7 @@ private void updateConfig() throws UnsupportedAuthenticationException {
clientBuilder.enableTlsHostnameVerification(this.tlsEnableHostnameVerification);
clientBuilder.serviceUrl(rootParams.serviceURL);

clientBuilder.tlsTrustCertsFilePath(this.tlsTrustCertsFilePath)
clientBuilder.tlsTrustCertsFilePath(this.rootParams.tlsTrustCertsFilePath)
.tlsKeyFilePath(tlsKeyFilePath)
.tlsCertificateFilePath(tlsCertificateFilePath);

Expand Down

0 comments on commit 7a65f3f

Please sign in to comment.