Skip to content

Commit

Permalink
Dev 1.9.0 bug fix (#628)
Browse files Browse the repository at this point in the history
* Code optimization

* Code optimization

---------

Co-authored-by: “v_kkhuang” <“[email protected]”>
  • Loading branch information
v-kkhuang and “v_kkhuang” authored Oct 30, 2024
1 parent aea4960 commit 629b087
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ public Message getInfoByDataSourceId(
List<DataSourceParamKeyDefinition> 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[获取数据源信息失败]");
Expand Down Expand Up @@ -427,9 +425,8 @@ public Message getInfoByDataSourceName(
List<DataSourceParamKeyDefinition> 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[获取数据源信息失败]");
Expand Down Expand Up @@ -464,9 +461,8 @@ public Message getPublishedInfoByDataSourceName(
List<DataSourceParamKeyDefinition> 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[获取数据源信息失败]");
Expand Down Expand Up @@ -510,9 +506,7 @@ public Message getInfoByDataSourceIdAndVersion(
List<DataSourceParamKeyDefinition> 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[获取数据源信息失败]");
Expand Down Expand Up @@ -550,7 +544,7 @@ public Message getVersionList(
List<DataSourceParamKeyDefinition> keyDefinitionList =
dataSourceRelateService.getKeyDefinitionsByType(dataSource.getDataSourceTypeId());
// Decrypt
if (!AESUtils.LINKIS_DATASOURCE_AES_SWITCH.getValue() && null != versions) {
if (null != versions) {
versions.forEach(
version -> {
RestfulApiHelper.decryptPasswordKey(
Expand Down Expand Up @@ -700,9 +694,7 @@ public Message getConnectParams(
Map<String, Object> connectParams = dataSource.getConnectParams();
List<DataSourceParamKeyDefinition> 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[连接数据源失败]");
Expand Down Expand Up @@ -738,9 +730,7 @@ public Message getConnectParams(

List<DataSourceParamKeyDefinition> 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[连接数据源失败]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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对象并查询数据库
Expand Down

0 comments on commit 629b087

Please sign in to comment.