You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by fe...@apache.org on 2023/01/11 02:17:02 UTC

[kyuubi] branch master updated: [KYUUBI #3739] [REST] Remove unused parameters in SessionOpenRequest

This is an automated email from the ASF dual-hosted git repository.

feiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d41081d7 [KYUUBI #3739] [REST] Remove unused parameters in SessionOpenRequest
2d41081d7 is described below

commit 2d41081d7b407cfa8faec866ace30c28ea00740c
Author: hongdongdong <ho...@apache.org>
AuthorDate: Wed Jan 11 10:16:55 2023 +0800

    [KYUUBI #3739] [REST] Remove unused parameters in SessionOpenRequest
    
    ### _Why are the changes needed?_
    
    We should put the authorization info in request header, user,password,ip in SessionOpenRequest are unnecessary.
    
    ### _How was this patch tested?_
    - [X] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #3739 from hddong/rm-unused-params.
    
    Closes #3739
    
    7fac61853 [hongdongdong] update
    8f1f4ae01 [hongdongdong] added on migration guide
    95962b472 [hongdongdong] fix
    63606350b [hongdongdong] [REST] Remove unused parameters in SessionOpenRequest
    
    Authored-by: hongdongdong <ho...@apache.org>
    Signed-off-by: fwang12 <fw...@ebay.com>
---
 docs/deployment/migration-guide.md                 |  1 +
 .../client/api/v1/dto/SessionOpenRequest.java      | 42 ++--------------------
 .../kyuubi/server/api/v1/SessionsResource.scala    |  2 +-
 .../operation/KyuubiRestAuthenticationSuite.scala  |  3 --
 .../server/api/v1/SessionsResourceSuite.scala      | 24 +++++--------
 5 files changed, 13 insertions(+), 59 deletions(-)

diff --git a/docs/deployment/migration-guide.md b/docs/deployment/migration-guide.md
index daab1be5d..86efd7a0c 100644
--- a/docs/deployment/migration-guide.md
+++ b/docs/deployment/migration-guide.md
@@ -24,6 +24,7 @@
 * Since Kyuubi 1.7, Kyuubi returns engine's information for `GetInfo` request instead of server. To restore the previous behavior, set `kyuubi.server.info.provider` to `SERVER`.
 * Since Kyuubi 1.7, Kyuubi session type `SQL` is refactored to `INTERACTIVE`, because Kyuubi supports not only `SQL` session, but also `SCALA` and `PYTHON` sessions.
   User need to use `INTERACTIVE` sessionType to look up the session event.
+* Since Kyuubi 1.7, the REST API of `Open(create) a session` will not contains parameters `user` `password` and `IpAddr`. User and password should be set in `Authorization` of http request if needed.
 
 ## Upgrading from Kyuubi 1.6.0 to 1.6.1
 * Since Kyuubi 1.6.1, `kyuubi.ha.zookeeper.engine.auth.type` does not fallback to `kyuubi.ha.zookeeper.auth.type`.  
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/api/v1/dto/SessionOpenRequest.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/api/v1/dto/SessionOpenRequest.java
index 4c8a8dfce..2d23aac57 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/api/v1/dto/SessionOpenRequest.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/api/v1/dto/SessionOpenRequest.java
@@ -25,23 +25,12 @@ import org.apache.commons.lang3.builder.ToStringStyle;
 
 public class SessionOpenRequest {
   private int protocolVersion;
-  private String user;
-  private String password;
-  private String ipAddr;
   private Map<String, String> configs;
 
   public SessionOpenRequest() {}
 
-  public SessionOpenRequest(
-      int protocolVersion,
-      String user,
-      String password,
-      String ipAddr,
-      Map<String, String> configs) {
+  public SessionOpenRequest(int protocolVersion, Map<String, String> configs) {
     this.protocolVersion = protocolVersion;
-    this.user = user;
-    this.password = password;
-    this.ipAddr = ipAddr;
     this.configs = configs;
   }
 
@@ -53,30 +42,6 @@ public class SessionOpenRequest {
     this.protocolVersion = protocolVersion;
   }
 
-  public String getUser() {
-    return user;
-  }
-
-  public void setUser(String user) {
-    this.user = user;
-  }
-
-  public String getPassword() {
-    return password;
-  }
-
-  public void setPassword(String password) {
-    this.password = password;
-  }
-
-  public String getIpAddr() {
-    return ipAddr;
-  }
-
-  public void setIpAddr(String ipAddr) {
-    this.ipAddr = ipAddr;
-  }
-
   public Map<String, String> getConfigs() {
     if (null == configs) {
       return Collections.emptyMap();
@@ -94,15 +59,12 @@ public class SessionOpenRequest {
     if (o == null || getClass() != o.getClass()) return false;
     SessionOpenRequest that = (SessionOpenRequest) o;
     return getProtocolVersion() == that.getProtocolVersion()
-        && Objects.equals(getUser(), that.getUser())
-        && Objects.equals(getPassword(), that.getPassword())
-        && Objects.equals(getIpAddr(), that.getIpAddr())
         && Objects.equals(getConfigs(), that.getConfigs());
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(getProtocolVersion(), getUser(), getPassword(), getIpAddr(), getConfigs());
+    return Objects.hash(getProtocolVersion(), getConfigs());
   }
 
   @Override
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala
index 17e23c58d..80212faf2 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala
@@ -146,7 +146,7 @@ private[v1] class SessionsResource extends ApiRequestContext with Logging {
     val handle = fe.be.openSession(
       TProtocolVersion.findByValue(request.getProtocolVersion),
       userName,
-      request.getPassword,
+      "",
       ipAddress,
       (request.getConfigs.asScala ++ Map(
         KYUUBI_CLIENT_IP_KEY -> ipAddress,
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiRestAuthenticationSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiRestAuthenticationSuite.scala
index a46c52572..64707ce01 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiRestAuthenticationSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiRestAuthenticationSuite.scala
@@ -131,9 +131,6 @@ class KyuubiRestAuthenticationSuite extends RestClientTestHelper {
     var token = generateToken(hostName)
     val sessionOpenRequest = new SessionOpenRequest(
       TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11.getValue,
-      "kyuubi",
-      "pass",
-      "localhost",
       Map(
         KyuubiConf.ENGINE_SHARE_LEVEL.key -> "CONNECTION",
         "hive.server2.proxy.user" -> proxyUser).asJava)
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
index 7f3f52104..db5e1360b 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
@@ -17,7 +17,9 @@
 
 package org.apache.kyuubi.server.api.v1
 
+import java.nio.charset.StandardCharsets
 import java.util
+import java.util.Base64
 import javax.ws.rs.client.Entity
 import javax.ws.rs.core.{GenericType, MediaType, Response}
 
@@ -32,6 +34,7 @@ import org.apache.kyuubi.config.KyuubiReservedKeys.KYUUBI_SESSION_CONNECTION_URL
 import org.apache.kyuubi.events.KyuubiSessionEvent
 import org.apache.kyuubi.metrics.{MetricsConstants, MetricsSystem}
 import org.apache.kyuubi.operation.OperationHandle
+import org.apache.kyuubi.server.http.authentication.AuthenticationHandler.AUTHORIZATION_HEADER
 import org.apache.kyuubi.session.SessionType
 
 class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
@@ -46,9 +49,6 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
   test("open/close and count session") {
     val requestObj = new SessionOpenRequest(
       1,
-      "admin",
-      "123456",
-      "localhost",
       Map("testConfig" -> "testValue").asJava)
 
     var response = webTarget.path("api/v1/sessions")
@@ -82,9 +82,6 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
   test("getSessionList") {
     val requestObj = new SessionOpenRequest(
       1,
-      "admin",
-      "123456",
-      "localhost",
       Map("testConfig" -> "testValue").asJava)
 
     var response = webTarget.path("api/v1/sessions")
@@ -113,13 +110,15 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
   test("get session event") {
     val sessionOpenRequest = new SessionOpenRequest(
       1,
-      "admin",
-      "123456",
-      "localhost",
       Map("testConfig" -> "testValue").asJava)
 
+    val user = "kyuubi".getBytes()
+
     val sessionOpenResp = webTarget.path("api/v1/sessions")
       .request(MediaType.APPLICATION_JSON_TYPE)
+      .header(
+        AUTHORIZATION_HEADER,
+        s"Basic ${new String(Base64.getEncoder().encode(user), StandardCharsets.UTF_8)}")
       .post(Entity.entity(sessionOpenRequest, MediaType.APPLICATION_JSON_TYPE))
 
     val sessionHandle = sessionOpenResp.readEntity(classOf[SessionHandle]).getIdentifier
@@ -130,6 +129,7 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
     val sessions = response.readEntity(classOf[KyuubiSessionEvent])
     assert(sessions.conf("testConfig").equals("testValue"))
     assert(sessions.sessionType.equals(SessionType.INTERACTIVE.toString))
+    assert(sessions.user.equals("kyuubi"))
 
     // close an opened session
     response = webTarget.path(s"api/v1/sessions/$sessionHandle").request().delete()
@@ -148,9 +148,6 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
 
     val requestObj = new SessionOpenRequest(
       1,
-      "admin",
-      "123456",
-      "localhost",
       Map("testConfig" -> "testValue", KyuubiConf.SERVER_INFO_PROVIDER.key -> "SERVER").asJava)
 
     var response: Response = webTarget.path("api/v1/sessions")
@@ -192,9 +189,6 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
   test("submit operation and get operation handle") {
     val requestObj = new SessionOpenRequest(
       1,
-      "admin",
-      "123456",
-      "localhost",
       Map("testConfig" -> "testValue").asJava)
 
     var response: Response = webTarget.path("api/v1/sessions")