You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/11/15 01:25:46 UTC

[iotdb] branch master updated: [IOTDB-4601] Add configuration to close swagger (#7966)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4f22e14a22 [IOTDB-4601] Add configuration to close swagger (#7966)
4f22e14a22 is described below

commit 4f22e14a222e9c6688cb5a16811498d0d2817a4a
Author: CloudWise-Lukemiao <76...@users.noreply.github.com>
AuthorDate: Tue Nov 15 09:25:40 2022 +0800

    [IOTDB-4601] Add configuration to close swagger (#7966)
---
 .../GrafanaPlugin/iotdb/conf/iotdb-rest.properties          |  3 +++
 docs/UserGuide/API/RestService.md                           |  8 +++++++-
 docs/zh/UserGuide/API/RestService.md                        |  6 ++++++
 server/src/assembly/resources/conf/iotdb-rest.properties    |  3 +++
 .../apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java   | 11 +++++++++++
 .../iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java      |  3 +++
 .../iotdb/db/protocol/rest/filter/AuthorizationFilter.java  | 13 +++++++++++--
 server/src/test/resources/iotdb-rest.properties             |  3 +++
 session/src/test/resources/iotdb-rest.properties            |  3 +++
 9 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/docker/src/main/DockerCompose/GrafanaPlugin/iotdb/conf/iotdb-rest.properties b/docker/src/main/DockerCompose/GrafanaPlugin/iotdb/conf/iotdb-rest.properties
index 75d0ae1b06..6c608984df 100644
--- a/docker/src/main/DockerCompose/GrafanaPlugin/iotdb/conf/iotdb-rest.properties
+++ b/docker/src/main/DockerCompose/GrafanaPlugin/iotdb/conf/iotdb-rest.properties
@@ -27,6 +27,9 @@ enable_rest_service=true
 # the binding port of the REST service
 # rest_service_port=18080
 
+# Whether to display rest service interface information through swagger. eg: http://ip:port/swagger.json
+# enable_swagger=false
+
 # the default row limit to a REST query response when the rowSize parameter is not given in request
 # rest_query_default_row_size_limit=10000
 
diff --git a/docs/UserGuide/API/RestService.md b/docs/UserGuide/API/RestService.md
index e0ec03973e..2f1188a6f1 100644
--- a/docs/UserGuide/API/RestService.md
+++ b/docs/UserGuide/API/RestService.md
@@ -851,7 +851,7 @@ The configuration is located in 'iotdb-rest.properties'.
 
 
 
-* Set 'enable_REST_service' to 'true' to enable the module, and 'false' to disable the module. By default, this value is' false '.
+* Set 'enable_rest_service' to 'true' to enable the module, and 'false' to disable the module. By default, this value is' false '.
 
 ```properties
 enable_rest_service=true
@@ -863,6 +863,12 @@ enable_rest_service=true
 rest_service_port=18080
 ```
 
+* Set 'enable_swagger' to 'true' to display rest service interface information through swagger, and 'false' to do not display the rest service interface information through the swagger. By default, this value is' false '.
+
+```properties
+enable_swagger=false
+```
+
 * The maximum number of rows in the result set that can be returned by a query. When the number of rows in the returned result set exceeds the limit, the status code `411` is returned.
 
 ````properties
diff --git a/docs/zh/UserGuide/API/RestService.md b/docs/zh/UserGuide/API/RestService.md
index e4081338c5..d7ef565302 100644
--- a/docs/zh/UserGuide/API/RestService.md
+++ b/docs/zh/UserGuide/API/RestService.md
@@ -877,6 +877,12 @@ enable_rest_service=true
 rest_service_port=18080
 ```
 
+* 将 'enable_swagger' 设置 'true' 启用swagger来展示rest接口信息, 而设置为 'false' 关闭该功能. 默认情况下,该值为 `false`。
+
+```properties
+enable_swagger=false
+```
+
 * 一次查询能返回的结果集最大行数。当返回结果集的行数超出参数限制时,您只会得到在行数范围内的结果集,且将得到状态码`411`。
 
 ```properties
diff --git a/server/src/assembly/resources/conf/iotdb-rest.properties b/server/src/assembly/resources/conf/iotdb-rest.properties
index b7f426f745..53b418dab3 100644
--- a/server/src/assembly/resources/conf/iotdb-rest.properties
+++ b/server/src/assembly/resources/conf/iotdb-rest.properties
@@ -27,6 +27,9 @@
 # the binding port of the REST service
 # rest_service_port=18080
 
+# Whether to display rest service interface information through swagger. eg: http://ip:port/swagger.json
+# enable_swagger=false
+
 # the default row limit to a REST query response when the rowSize parameter is not given in request
 # rest_query_default_row_size_limit=10000
 
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
index ebe3a49a12..fdaca31851 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
@@ -26,6 +26,9 @@ public class IoTDBRestServiceConfig {
   /** set the REST Service port. */
   private int restServicePort = 18080;
 
+  /** Whether to display rest service interface information through swagger */
+  private boolean enableSwagger = false;
+
   /** enable the REST Service ssl. */
   private boolean enableHttps = false;
 
@@ -82,6 +85,14 @@ public class IoTDBRestServiceConfig {
     this.idleTimeoutInSeconds = idleTimeoutInSeconds;
   }
 
+  public boolean isEnableSwagger() {
+    return enableSwagger;
+  }
+
+  public void setEnableSwagger(boolean enableSwagger) {
+    this.enableSwagger = enableSwagger;
+  }
+
   public String getKeyStorePath() {
     return keyStorePath;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
index 01cf9adcf8..61658c4ac6 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
@@ -70,6 +70,9 @@ public class IoTDBRestServiceDescriptor {
               properties.getProperty(
                   "rest_query_default_row_size_limit",
                   Integer.toString(conf.getRestQueryDefaultRowSizeLimit()))));
+      conf.setEnableSwagger(
+          Boolean.parseBoolean(
+              properties.getProperty("enable_swagger", Boolean.toString(conf.isEnableSwagger()))));
 
       conf.setEnableHttps(
           Boolean.parseBoolean(
diff --git a/server/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java b/server/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java
index 9dafb0911d..f03e2f80a6 100644
--- a/server/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java
+++ b/server/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java
@@ -20,6 +20,7 @@ import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.auth.AuthException;
 import org.apache.iotdb.commons.auth.authorizer.IAuthorizer;
 import org.apache.iotdb.db.auth.AuthorizerManager;
+import org.apache.iotdb.db.conf.rest.IoTDBRestServiceConfig;
 import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
 import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus;
 import org.apache.iotdb.rpc.ConfigNodeConnectionException;
@@ -47,14 +48,22 @@ public class AuthorizationFilter implements ContainerRequestFilter {
 
   private final IAuthorizer authorizer = AuthorizerManager.getInstance();
   private final UserCache userCache = UserCache.getInstance();
+  IoTDBRestServiceConfig config = IoTDBRestServiceDescriptor.getInstance().getConfig();
 
   public AuthorizationFilter() throws AuthException {}
 
   @Override
   public void filter(ContainerRequestContext containerRequestContext) throws IOException {
     if ("OPTIONS".equals(containerRequestContext.getMethod())
-        || "swagger.json".equals(containerRequestContext.getUriInfo().getPath())
-        || "ping".equals(containerRequestContext.getUriInfo().getPath())) {
+        || "ping".equals(containerRequestContext.getUriInfo().getPath())
+        || (config.isEnableSwagger()
+            && "swagger.json".equals(containerRequestContext.getUriInfo().getPath()))) {
+      return;
+    } else if (!config.isEnableSwagger()
+        && "swagger.json".equals(containerRequestContext.getUriInfo().getPath())) {
+      Response resp =
+          Response.status(Status.NOT_FOUND).type(MediaType.APPLICATION_JSON).entity("").build();
+      containerRequestContext.abortWith(resp);
       return;
     }
 
diff --git a/server/src/test/resources/iotdb-rest.properties b/server/src/test/resources/iotdb-rest.properties
index 7e96a549e0..fd24dc22d6 100644
--- a/server/src/test/resources/iotdb-rest.properties
+++ b/server/src/test/resources/iotdb-rest.properties
@@ -27,6 +27,9 @@ enable_rest_service=true
 # the binding port of the REST service
 # rest_service_port=18080
 
+# Whether to display rest service interface information through swagger. eg: http://ip:port/swagger.json
+# enable_swagger=false
+
 # the default row limit to a REST query response when the rowSize parameter is not given in request
 # rest_query_default_row_size_limit=10000
 
diff --git a/session/src/test/resources/iotdb-rest.properties b/session/src/test/resources/iotdb-rest.properties
index 7e96a549e0..5019b199d1 100644
--- a/session/src/test/resources/iotdb-rest.properties
+++ b/session/src/test/resources/iotdb-rest.properties
@@ -30,6 +30,9 @@ enable_rest_service=true
 # the default row limit to a REST query response when the rowSize parameter is not given in request
 # rest_query_default_row_size_limit=10000
 
+# Whether to display rest service interface information through swagger. eg: http://ip:port/swagger.json
+# enable_swagger=false
+
 # the expiration time of the user login information cache (in seconds)
 # cache_expire_in_seconds=28800