ソースを参照

[Fix-10080]When the created tenant name is too long, an error message will be prompted (#10081)

* [Fix-10080]When the created tenant name is too long, an error message will be prompted

* [Fix-10080]When the created tenant name is too long, an error message will be prompted

* [Fix-10080]When the created tenant name is too long, an error message will be prompted

Co-authored-by: houshitao <shitaohou@163.com>
hstdream 2 年 前
コミット
67cf7b2800

+ 2 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@@ -402,7 +402,8 @@ public enum Status {
     QUERY_UNAUTHORIZED_NAMESPACE_ERROR(1300012, "query unauthorized namespace error", "查询未授权命名空间错误"),
     QUERY_AUTHORIZED_NAMESPACE_ERROR(1300013, "query authorized namespace error", "查询授权命名空间错误"),
     QUERY_CAN_USE_K8S_CLUSTER_ERROR(1300014, "login user query can used k8s cluster list error", "查询可用k8s集群错误"),
-    RESOURCE_FULL_NAME_TOO_LONG_ERROR(1300015, "resource's fullname is too long error", "资源文件名过长");
+    RESOURCE_FULL_NAME_TOO_LONG_ERROR(1300015, "resource's fullname is too long error", "资源文件名过长"),
+    TENANT_FULL_NAME_TOO_LONG_ERROR(1300016, "tenant's fullname is too long error", "租户名过长");
 
     private final int code;
     private final String enMsg;

+ 8 - 1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java

@@ -40,12 +40,13 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.apache.dolphinscheduler.common.Constants.TENANT_FULL_NAME_MAX_LENGTH;
+
 /**
  * tenant service impl
  */
@@ -89,11 +90,17 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService
             return result;
         }
 
+        if(StringUtils.length(tenantCode) > TENANT_FULL_NAME_MAX_LENGTH){
+            putMsg(result, Status.TENANT_FULL_NAME_TOO_LONG_ERROR);
+            return result;
+        }
+
         if (!RegexUtils.isValidLinuxUserName(tenantCode)) {
             putMsg(result, Status.CHECK_OS_TENANT_CODE_ERROR);
             return result;
         }
 
+
         if (checkTenantExists(tenantCode)) {
             putMsg(result, Status.OS_TENANT_CODE_EXIST, tenantCode);
             return result;

+ 5 - 0
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@@ -823,4 +823,9 @@ public final class Constants {
      */
     public static final String SCHEDULE_TIMEZONE = "schedule_timezone";
     public static final int RESOURCE_FULL_NAME_MAX_LENGTH = 128;
+
+    /**
+     * tenant
+     */
+    public static final int TENANT_FULL_NAME_MAX_LENGTH = 30;
 }