You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "michaeljmarshall (via GitHub)" <gi...@apache.org> on 2023/02/18 06:53:44 UTC
[GitHub] [pulsar] michaeljmarshall commented on a diff in pull request #19548: [fix][broker] Fix geo-replication admin
michaeljmarshall commented on code in PR #19548:
URL: https://github.com/apache/pulsar/pull/19548#discussion_r1110745714
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -1379,37 +1402,52 @@ public PulsarAdmin getClusterPulsarAdmin(String cluster, Optional<ClusterData> c
try {
ClusterData data = clusterDataOp
.orElseThrow(() -> new MetadataStoreException.NotFoundException(cluster));
+ PulsarAdminBuilder builder = PulsarAdmin.builder();
ServiceConfiguration conf = pulsar.getConfig();
-
- boolean isTlsUrl = conf.isBrokerClientTlsEnabled() && isNotBlank(data.getServiceUrlTls());
- String adminApiUrl = isTlsUrl ? data.getServiceUrlTls() : data.getServiceUrl();
- PulsarAdminBuilder builder = PulsarAdmin.builder().serviceHttpUrl(adminApiUrl);
-
// Apply all arbitrary configuration. This must be called before setting any fields annotated as
// @Secret on the ClientConfigurationData object because of the way they are serialized.
// See https://github.com/apache/pulsar/issues/8509 for more information.
builder.loadConf(PropertiesUtils.filterAndMapProperties(conf.getProperties(), "brokerClient_"));
- builder.authentication(
- conf.getBrokerClientAuthenticationPlugin(),
- conf.getBrokerClientAuthenticationParameters());
-
- if (isTlsUrl) {
- builder.allowTlsInsecureConnection(conf.isTlsAllowInsecureConnection());
- if (conf.isBrokerClientTlsEnabledWithKeyStore()) {
- builder.useKeyStoreTls(true)
- .tlsTrustStoreType(conf.getBrokerClientTlsTrustStoreType())
- .tlsTrustStorePath(conf.getBrokerClientTlsTrustStore())
- .tlsTrustStorePassword(conf.getBrokerClientTlsTrustStorePassword())
- .tlsKeyStoreType(conf.getBrokerClientTlsKeyStoreType())
- .tlsKeyStorePath(conf.getBrokerClientTlsKeyStore())
- .tlsKeyStorePassword(conf.getBrokerClientTlsKeyStorePassword());
- } else {
- builder.tlsTrustCertsFilePath(conf.getBrokerClientTrustCertsFilePath())
- .tlsKeyFilePath(conf.getBrokerClientKeyFilePath())
- .tlsCertificateFilePath(conf.getBrokerClientCertificateFilePath());
- }
+ if (data.getAuthenticationPlugin() != null && data.getAuthenticationParameters() != null) {
+ builder.authentication(data.getAuthenticationPlugin(), data.getAuthenticationParameters());
+ } else if (pulsar.getConfiguration().isAuthenticationEnabled()) {
Review Comment:
Is there a reason to only run this when `pulsar.getConfiguration().isAuthenticationEnabled()` is true? I see that we previously always ran it. I think this section could be a simple if/else block.
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -1379,37 +1402,52 @@ public PulsarAdmin getClusterPulsarAdmin(String cluster, Optional<ClusterData> c
try {
ClusterData data = clusterDataOp
.orElseThrow(() -> new MetadataStoreException.NotFoundException(cluster));
+ PulsarAdminBuilder builder = PulsarAdmin.builder();
ServiceConfiguration conf = pulsar.getConfig();
-
- boolean isTlsUrl = conf.isBrokerClientTlsEnabled() && isNotBlank(data.getServiceUrlTls());
- String adminApiUrl = isTlsUrl ? data.getServiceUrlTls() : data.getServiceUrl();
- PulsarAdminBuilder builder = PulsarAdmin.builder().serviceHttpUrl(adminApiUrl);
-
// Apply all arbitrary configuration. This must be called before setting any fields annotated as
// @Secret on the ClientConfigurationData object because of the way they are serialized.
// See https://github.com/apache/pulsar/issues/8509 for more information.
builder.loadConf(PropertiesUtils.filterAndMapProperties(conf.getProperties(), "brokerClient_"));
- builder.authentication(
- conf.getBrokerClientAuthenticationPlugin(),
- conf.getBrokerClientAuthenticationParameters());
-
- if (isTlsUrl) {
- builder.allowTlsInsecureConnection(conf.isTlsAllowInsecureConnection());
- if (conf.isBrokerClientTlsEnabledWithKeyStore()) {
- builder.useKeyStoreTls(true)
- .tlsTrustStoreType(conf.getBrokerClientTlsTrustStoreType())
- .tlsTrustStorePath(conf.getBrokerClientTlsTrustStore())
- .tlsTrustStorePassword(conf.getBrokerClientTlsTrustStorePassword())
- .tlsKeyStoreType(conf.getBrokerClientTlsKeyStoreType())
- .tlsKeyStorePath(conf.getBrokerClientTlsKeyStore())
- .tlsKeyStorePassword(conf.getBrokerClientTlsKeyStorePassword());
- } else {
- builder.tlsTrustCertsFilePath(conf.getBrokerClientTrustCertsFilePath())
- .tlsKeyFilePath(conf.getBrokerClientKeyFilePath())
- .tlsCertificateFilePath(conf.getBrokerClientCertificateFilePath());
- }
+ if (data.getAuthenticationPlugin() != null && data.getAuthenticationParameters() != null) {
+ builder.authentication(data.getAuthenticationPlugin(), data.getAuthenticationParameters());
+ } else if (pulsar.getConfiguration().isAuthenticationEnabled()) {
+ builder.authentication(pulsar.getConfiguration().getBrokerClientAuthenticationPlugin(),
+ pulsar.getConfiguration().getBrokerClientAuthenticationParameters());
+ }
+
+ boolean isTlsEnabled = data.isBrokerClientTlsEnabled() || conf.isBrokerClientTlsEnabled();
+ String adminApiUrl = isTlsEnabled ? data.getServiceUrlTls() : data.getServiceUrl();
Review Comment:
I see we remove the check for `isNotBlank(data.getServiceUrlTls())` up above. I support the change, but should we make sure to handle the failure scenario gracefully instead of with a null pointer?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org