From 629b087655f8807a79e0c9893863b74c718a5c96 Mon Sep 17 00:00:00 2001 From: v-kkhuang <62878639+v-kkhuang@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:22:30 +0800 Subject: [PATCH] Dev 1.9.0 bug fix (#628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Code optimization * Code optimization --------- Co-authored-by: “v_kkhuang” <“420895376@qq.com”> --- .../restful/DataSourceCoreRestfulApi.java | 28 ++++++------------- .../core/restful/RestfulApiHelper.java | 13 +++++---- .../filesystem/util/FilesystemUtils.java | 2 +- .../apache/linkis/udf/api/UDFRestfulApi.java | 6 ++-- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java index 350fffe010..cf57612c03 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java @@ -389,9 +389,7 @@ public Message getInfoByDataSourceId( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); // Decrypt - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); return Message.ok().data("info", dataSource); }, "Fail to access data source[获取数据源信息失败]"); @@ -427,9 +425,8 @@ public Message getInfoByDataSourceName( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); // Decrypt - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); + return Message.ok().data("info", dataSource); }, "Fail to access data source[获取数据源信息失败]"); @@ -464,9 +461,8 @@ public Message getPublishedInfoByDataSourceName( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); // Decrypt - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); + return Message.ok().data("info", dataSource); }, "Fail to access data source[获取数据源信息失败]"); @@ -510,9 +506,7 @@ public Message getInfoByDataSourceIdAndVersion( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); // Decrypt - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, dataSource.getConnectParams()); return Message.ok().data("info", dataSource); }, "Fail to access data source[获取数据源信息失败]"); @@ -550,7 +544,7 @@ public Message getVersionList( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); // Decrypt - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue() && null != versions) { + if (null != versions) { versions.forEach( version -> { RestfulApiHelper.decryptPasswordKey( @@ -700,9 +694,7 @@ public Message getConnectParams( Map connectParams = dataSource.getConnectParams(); List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, connectParams); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, connectParams); return Message.ok().data("connectParams", connectParams); }, "Fail to connect data source[连接数据源失败]"); @@ -738,9 +730,7 @@ public Message getConnectParams( List keyDefinitionList = dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId()); - if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { - RestfulApiHelper.decryptPasswordKey(keyDefinitionList, connectParams); - } + RestfulApiHelper.decryptPasswordKey(keyDefinitionList, connectParams); return Message.ok().data("connectParams", connectParams); }, "Fail to connect data source[连接数据源失败]"); diff --git a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java index ff2d48121f..8726fd9a23 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java @@ -74,11 +74,12 @@ public static void encryptPasswordKey( Object password = connectParams.get(keyDefinition.getKey()); if (null != password) { String passwordStr = String.valueOf(password); - if (AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue() - && !connectParams.containsKey("isEncrypt")) { - passwordStr = - AESUtils.encrypt(passwordStr, AESUtils.LINKIS_DATASOURCE_AES_KEY.getValue()); - connectParams.put("isEncrypt", "1"); + if (AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue()) { + if (!connectParams.containsKey("isEncrypt")) { + passwordStr = + AESUtils.encrypt(passwordStr, AESUtils.LINKIS_DATASOURCE_AES_KEY.getValue()); + connectParams.put("isEncrypt", "1"); + } } else { passwordStr = CryptoUtils.object2String(passwordStr); } @@ -106,7 +107,7 @@ public static void decryptPasswordKey( passwordStr = AESUtils.decrypt(passwordStr, AESUtils.LINKIS_DATASOURCE_AES_KEY.getValue()); } else { - passwordStr = CryptoUtils.object2String(passwordStr); + passwordStr = String.valueOf(CryptoUtils.string2Object(passwordStr)); } connectParams.put(keyDefinition.getKey(), passwordStr); } diff --git a/linkis-public-enhancements/linkis-pes-publicservice/src/main/java/org/apache/linkis/filesystem/util/FilesystemUtils.java b/linkis-public-enhancements/linkis-pes-publicservice/src/main/java/org/apache/linkis/filesystem/util/FilesystemUtils.java index 82f760326c..9cf2f27f85 100644 --- a/linkis-public-enhancements/linkis-pes-publicservice/src/main/java/org/apache/linkis/filesystem/util/FilesystemUtils.java +++ b/linkis-public-enhancements/linkis-pes-publicservice/src/main/java/org/apache/linkis/filesystem/util/FilesystemUtils.java @@ -205,7 +205,7 @@ public static String checkModuleFile(MultipartFile file, String username) throws Utils.exec( (new String[] { "python", - Configuration.getLinkisHome() + "/admin/" + "check_python_module.py", + Configuration.getLinkisHome() + "/admin/" + "check_modules.py", module })); return !Boolean.parseBoolean(exec); diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java index 61d40dcceb..3ff6fb8c90 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/api/UDFRestfulApi.java @@ -1286,9 +1286,9 @@ public Message pythonFileExist( if (org.apache.commons.lang3.StringUtils.isBlank(fileName)) { return Message.error("参数fileName不能为空"); } - String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf(".")); - if (!fileNameWithoutExtension.matches("^[a-zA-Z][a-zA-Z0-9_.-]{0,49}$")) { - return Message.error("只支持数字字母下划线,且以字母开头,长度最大50"); + String fileNameWithoutExtension = fileName.split("\\.")[0]; + if (!fileNameWithoutExtension.matches("^[a-zA-Z][a-zA-Z0-9_-]{0,49}$")) { + return Message.error("只支持数字字母下划线,中划线,且以字母开头,长度最大50"); } // 封装PythonModuleInfo对象并查询数据库