You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/10/06 18:23:32 UTC

[GitHub] [druid] jihoonson commented on a change in pull request #9938: Add https to druid-influxdb-emitter extension

jihoonson commented on a change in pull request #9938:
URL: https://github.com/apache/druid/pull/9938#discussion_r500506192



##########
File path: extensions-contrib/influxdb-emitter/src/main/java/org/apache/druid/emitter/influxdb/InfluxdbEmitter.java
##########
@@ -211,4 +219,46 @@ public void transformAndSendToInfluxdb(LinkedBlockingQueue<ServiceMetricEvent> e
     postToInflux(payload.toString());
   }
 
+  private HttpClient buildInfluxdbClient()
+  {
+    if ("https".equals(influxdbEmitterConfig.getProtocol())) {
+      SSLContext sslContext;
+      if (influxdbEmitterConfig.getTrustStorePath() == null || influxdbEmitterConfig.getTrustStorePassword() == null) {
+        String msg = "Can't load TrustStore. Truststore path or password is not set.";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+
+      FileInputStream in = null;
+
+      try {
+        in = new FileInputStream(new File(influxdbEmitterConfig.getTrustStorePath()));
+        KeyStore store = KeyStore.getInstance(influxdbEmitterConfig.getTrustStoreType());
+        store.load(in, influxdbEmitterConfig.getTrustStorePassword().toCharArray());
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+        tmf.init(store);
+        sslContext = SSLContext.getInstance("TLS");
+        sslContext.init(null, tmf.getTrustManagers(), null);
+      }
+      catch (Exception ex) {
+        String msg = "Unable to load TrustStore";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+      finally {
+        if (in != null) {
+          try {
+            in.close();
+          }
+          catch (IOException ex) {
+            log.error("Unable to load TrustStore");

Review comment:
       I think this should be thrown.

##########
File path: extensions-contrib/influxdb-emitter/src/main/java/org/apache/druid/emitter/influxdb/InfluxdbEmitter.java
##########
@@ -211,4 +219,46 @@ public void transformAndSendToInfluxdb(LinkedBlockingQueue<ServiceMetricEvent> e
     postToInflux(payload.toString());
   }
 
+  private HttpClient buildInfluxdbClient()
+  {
+    if ("https".equals(influxdbEmitterConfig.getProtocol())) {
+      SSLContext sslContext;
+      if (influxdbEmitterConfig.getTrustStorePath() == null || influxdbEmitterConfig.getTrustStorePassword() == null) {
+        String msg = "Can't load TrustStore. Truststore path or password is not set.";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+
+      FileInputStream in = null;
+
+      try {
+        in = new FileInputStream(new File(influxdbEmitterConfig.getTrustStorePath()));
+        KeyStore store = KeyStore.getInstance(influxdbEmitterConfig.getTrustStoreType());
+        store.load(in, influxdbEmitterConfig.getTrustStorePassword().toCharArray());
+        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+        tmf.init(store);
+        sslContext = SSLContext.getInstance("TLS");
+        sslContext.init(null, tmf.getTrustManagers(), null);
+      }
+      catch (Exception ex) {
+        String msg = "Unable to load TrustStore";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+      finally {
+        if (in != null) {

Review comment:
       It would be better to use `try-with-resources`. You will not have to handle the IOException thrown in `close()` by yourself.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org