Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminBuilder;
import org.apache.pulsar.client.admin.internal.PulsarAdminImpl;
import org.apache.pulsar.common.util.DefaultPulsarSslFactory;
import org.apache.pulsar.common.util.ShutdownUtil;
import org.apache.pulsar.internal.CommandHook;
import org.apache.pulsar.internal.CommanderFactory;
Expand Down Expand Up @@ -114,41 +113,11 @@ public PulsarAdminTool(Properties properties) throws Exception {
}

private static PulsarAdminBuilder createAdminBuilderFromProperties(Properties properties) {
boolean useKeyStoreTls = Boolean
.parseBoolean(properties.getProperty("useKeyStoreTls", "false"));
String tlsTrustStoreType = properties.getProperty("tlsTrustStoreType", "JKS");
String tlsTrustStorePath = properties.getProperty("tlsTrustStorePath");
String tlsTrustStorePassword = properties.getProperty("tlsTrustStorePassword");
String tlsKeyStoreType = properties.getProperty("tlsKeyStoreType", "JKS");
String tlsKeyStorePath = properties.getProperty("tlsKeyStorePath");
String tlsKeyStorePassword = properties.getProperty("tlsKeyStorePassword");
String tlsKeyFilePath = properties.getProperty("tlsKeyFilePath");
String tlsCertificateFilePath = properties.getProperty("tlsCertificateFilePath");

boolean tlsAllowInsecureConnection = Boolean.parseBoolean(properties
.getProperty("tlsAllowInsecureConnection", "false"));

boolean tlsEnableHostnameVerification = Boolean.parseBoolean(properties
.getProperty("tlsEnableHostnameVerification", "false"));
final String tlsTrustCertsFilePath = properties.getProperty("tlsTrustCertsFilePath");
final String sslFactoryPlugin = properties.getProperty("sslFactoryPlugin",
DefaultPulsarSslFactory.class.getName());
final String sslFactoryPluginParams = properties.getProperty("sslFactoryPluginParams", "");

return PulsarAdmin.builder().allowTlsInsecureConnection(tlsAllowInsecureConnection)
.enableTlsHostnameVerification(tlsEnableHostnameVerification)
.tlsTrustCertsFilePath(tlsTrustCertsFilePath)
.useKeyStoreTls(useKeyStoreTls)
.tlsTrustStoreType(tlsTrustStoreType)
.tlsTrustStorePath(tlsTrustStorePath)
.tlsTrustStorePassword(tlsTrustStorePassword)
.tlsKeyStoreType(tlsKeyStoreType)
.tlsKeyStorePath(tlsKeyStorePath)
.tlsKeyStorePassword(tlsKeyStorePassword)
.tlsKeyFilePath(tlsKeyFilePath)
.tlsCertificateFilePath(tlsCertificateFilePath)
.sslFactoryPlugin(sslFactoryPlugin)
.sslFactoryPluginParams(sslFactoryPluginParams);
Map<String, Object> conf = new HashMap<>();
for (String key : properties.stringPropertyNames()) {
conf.put(key, properties.getProperty(key));
}
return PulsarAdmin.builder().loadConf(conf);
}

private void setupCommands(Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.google.common.annotations.VisibleForTesting;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import lombok.Getter;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -96,23 +98,8 @@ public static class RootParams {

@ArgGroup(exclusive = false)
protected RootParams rootParams = new RootParams();
boolean tlsAllowInsecureConnection;
boolean tlsEnableHostnameVerification;

String tlsKeyFilePath;
String tlsCertificateFilePath;


// for tls with keystore type config
boolean useKeyStoreTls;
String tlsTrustStoreType;
String tlsTrustStorePath;
String tlsTrustStorePassword;
String tlsKeyStoreType;
String tlsKeyStorePath;
String tlsKeyStorePassword;
String sslFactoryPlugin;
String sslFactoryPluginParams;
protected Properties properties;

protected final CommandLine commander;
protected CmdProduce produceCommand;
Expand All @@ -139,24 +126,6 @@ protected void initCommander(Properties properties) {
readCommand = new CmdRead();
generateDocumentation = new CmdGenerateDocumentation();

this.tlsAllowInsecureConnection = Boolean
.parseBoolean(properties.getProperty("tlsAllowInsecureConnection", "false"));
this.tlsEnableHostnameVerification = Boolean
.parseBoolean(properties.getProperty("tlsEnableHostnameVerification", "false"));
this.useKeyStoreTls = Boolean
.parseBoolean(properties.getProperty("useKeyStoreTls", "false"));
this.tlsTrustStoreType = properties.getProperty("tlsTrustStoreType", "JKS");
this.tlsTrustStorePath = properties.getProperty("tlsTrustStorePath");
this.tlsTrustStorePassword = properties.getProperty("tlsTrustStorePassword");

this.tlsKeyStoreType = properties.getProperty("tlsKeyStoreType", "JKS");
this.tlsKeyStorePath = properties.getProperty("tlsKeyStorePath");
this.tlsKeyStorePassword = properties.getProperty("tlsKeyStorePassword");
this.tlsKeyFilePath = properties.getProperty("tlsKeyFilePath");
this.tlsCertificateFilePath = properties.getProperty("tlsCertificateFilePath");
this.sslFactoryPlugin = properties.getProperty("sslFactoryPlugin");
this.sslFactoryPluginParams = properties.getProperty("sslFactoryPluginParams");

pulsarClientPropertiesProvider = PulsarClientPropertiesProvider.create(properties);
commander.setDefaultValueProvider(pulsarClientPropertiesProvider);
commander.addSubcommand("produce", produceCommand);
Expand All @@ -170,7 +139,12 @@ protected void addCommand(String name, Object cmd) {
}

private int updateConfig() throws UnsupportedAuthenticationException {
ClientBuilder clientBuilder = PulsarClient.builder()
Map<String, Object> conf = new HashMap<>();
for (String key : properties.stringPropertyNames()) {
conf.put(key, properties.getProperty(key));
}

ClientBuilder clientBuilder = PulsarClient.builder().loadConf(conf)
.memoryLimit(rootParams.memoryLimit, SizeUnit.BYTES);
Authentication authentication = null;
if (isNotBlank(this.rootParams.authPluginClassName)) {
Expand All @@ -180,25 +154,8 @@ private int updateConfig() throws UnsupportedAuthenticationException {
if (isNotBlank(this.rootParams.listenerName)) {
clientBuilder.listenerName(this.rootParams.listenerName);
}
clientBuilder.allowTlsInsecureConnection(this.tlsAllowInsecureConnection);
clientBuilder.enableTlsHostnameVerification(this.tlsEnableHostnameVerification);
clientBuilder.serviceUrl(rootParams.serviceURL);

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

clientBuilder.useKeyStoreTls(useKeyStoreTls)
.tlsTrustStoreType(tlsTrustStoreType)
.tlsTrustStorePath(tlsTrustStorePath)
.tlsTrustStorePassword(tlsTrustStorePassword)
.tlsKeyStoreType(tlsKeyStoreType)
.tlsKeyStorePath(tlsKeyStorePath)
.tlsKeyStorePassword(tlsKeyStorePassword);

clientBuilder.sslFactoryPlugin(sslFactoryPlugin)
.sslFactoryPluginParams(sslFactoryPluginParams);

clientBuilder.tlsTrustCertsFilePath(this.rootParams.tlsTrustCertsFilePath);
if (isNotBlank(rootParams.proxyServiceURL)) {
if (rootParams.proxyProtocol == null) {
commander.getErr().println("proxy-protocol must be provided with proxy-url");
Expand Down
Loading