You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/08/28 07:22:18 UTC

[GitHub] [calcite] fageiguanbing commented on a change in pull request #2123: Support for Elasticsearch basic authentication

fageiguanbing commented on a change in pull request #2123:
URL: https://github.com/apache/calcite/pull/2123#discussion_r478879223



##########
File path: elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java
##########
@@ -100,14 +106,27 @@ public ElasticsearchSchemaFactory() {
   /**
    * Builds elastic rest client from user configuration
    * @param hosts list of ES HTTP Hosts to connect to
+   * @param jdbcUser the username of ES
+   * @param jdbcPassword the password of ES
    * @return newly initialized low-level rest http client for ES
    */
-  private static RestClient connect(List<HttpHost> hosts, String pathPrefix) {
+  private static RestClient connect(List<HttpHost> hosts, String pathPrefix, String jdbcUser,
+                                    String jdbcPassword) {

Review comment:
       I don't know where to find the specification. Could you tell me where it is? 
   I guess:
   ```java
     private static RestClient connect(List<HttpHost> hosts, String pathPrefix,
                                       String jdbcUser, String jdbcPassword) {
   ```
   I add a new class in test package. And I think I should add `@Disabled` to prevent it execute in build.
   ```java
   package org.apache.calcite.adapter.elasticsearch;
   
   import org.junit.jupiter.api.Disabled;
   import org.junit.jupiter.api.Test;
   
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
   
   import static org.junit.jupiter.api.Assertions.assertEquals;
   
   /**
    * Testing Elasticsearch Authentication.
    */
   @Disabled("need a elasticsearch cluster")
   public class AuthenticationTest {
   
     /**
      * You need specify jdbcUser/jdbcPassword in elasticsearch.json
      */
     @Test void select1() throws ClassNotFoundException, SQLException {
       Class.forName("org.apache.calcite.jdbc.Driver");
   
       try (Connection con = DriverManager
           .getConnection("jdbc:calcite:model=src/test/resources/elasticsearch.json")) {
         try (Statement stmt = con.createStatement()) {
           String sql = "select 1";
           try (ResultSet rs = stmt.executeQuery(sql)) {
             if (rs.next()) {
               assertEquals(rs.getObject(1), 1);
             }
           }
         }
       }
     }
   }
   ```




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