apucher commented on a change in pull request #6418:
URL: https://github.com/apache/incubator-pinot/pull/6418#discussion_r557829988



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/util/TlsUtils.java
##########
@@ -0,0 +1,258 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.util;
+
+import com.google.common.base.Preconditions;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.core.transport.TlsConfig;
+import org.apache.pinot.spi.env.PinotConfiguration;
+
+
+/**
+ * Utility class for shared TLS configuration logic
+ */
+public final class TlsUtils {
+  private static final String ENABLED = "enabled";
+  private static final String CLIENT_AUTH_ENABLED = "client.auth.enabled";
+  private static final String KEYSTORE_PATH = "keystore.path";
+  private static final String KEYSTORE_PASSWORD = "keystore.password";
+  private static final String TRUSTSTORE_PATH = "truststore.path";
+  private static final String TRUSTSTORE_PASSWORD = "truststore.password";
+
+  private TlsUtils() {
+    // left blank
+  }
+
+  /**
+   * Extract a TlsConfig instance from a namespaced set of configuration key, 
with optional defaults.
+   *
+   * @param pinotConfig pinot configuration
+   * @param namespace namespace prefix
+   *
+   * @return TlsConfig instance
+   */
+  public static TlsConfig extractTlsConfig(TlsConfig tlsDefaults, 
PinotConfiguration pinotConfig, String namespace) {
+    TlsConfig tlsConfig = new TlsConfig();
+    tlsConfig.setEnabled(tlsDefaults.isEnabled());
+    tlsConfig.setClientAuthEnabled(tlsDefaults.isClientAuthEnabled());
+    tlsConfig.setKeyStorePath(tlsDefaults.getKeyStorePath());
+    tlsConfig.setKeyStorePassword(tlsDefaults.getKeyStorePassword());
+    tlsConfig.setTrustStorePath(tlsDefaults.getTrustStorePath());
+    tlsConfig.setTrustStorePassword(tlsDefaults.getTrustStorePassword());
+
+    if (pinotConfig.containsKey(key(namespace, ENABLED))) {
+      tlsConfig.setEnabled(pinotConfig.getProperty(key(namespace, ENABLED), 
false));

Review comment:
       unfortunately, this seems to be the only way to gracefully access 
boolean properties via PinotConfiguration.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to