!305 Introducing new features. 覆盖nacos官方历史记录查询的问题

Merge pull request !305 from aeizzz/auto-441246-dev-6446e088
This commit is contained in:
aeizzz 2022-12-26 11:30:38 +00:00 committed by Gitee
commit 0be21c621c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,85 @@
package com.alibaba.nacos.config.service;
import cn.hutool.core.util.StrUtil;
import com.alibaba.nacos.common.utils.Pair;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.model.Page;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.plugin.auth.exception.AccessException;
import com.alibaba.nacos.plugin.encryption.handler.EncryptionHandler;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Service
public class HistoryService {
private final HistoryConfigInfoPersistService historyConfigInfoPersistService;
private final ConfigInfoPersistService configInfoPersistService;
public HistoryService(HistoryConfigInfoPersistService historyConfigInfoPersistService,
ConfigInfoPersistService configInfoPersistService) {
this.historyConfigInfoPersistService = historyConfigInfoPersistService;
this.configInfoPersistService = configInfoPersistService;
}
public Page<ConfigHistoryInfo> listConfigHistory(String dataId, String group, String namespaceId, Integer pageNo,
Integer pageSize) {
return this.historyConfigInfoPersistService.findConfigHistory(dataId, group, namespaceId, pageNo, pageSize);
}
public ConfigHistoryInfo getConfigHistoryInfo(String dataId, String group, String namespaceId, Long nid)
throws AccessException {
ConfigHistoryInfo configHistoryInfo = this.historyConfigInfoPersistService.detailConfigHistory(nid);
if (Objects.isNull(configHistoryInfo)) {
return null;
}
else {
this.checkHistoryInfoPermission(configHistoryInfo, dataId, group, namespaceId);
String encryptedDataKey = configHistoryInfo.getEncryptedDataKey();
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, encryptedDataKey,
configHistoryInfo.getContent());
configHistoryInfo.setContent((String) pair.getSecond());
return configHistoryInfo;
}
}
public ConfigHistoryInfo getPreviousConfigHistoryInfo(String dataId, String group, String namespaceId, Long id)
throws AccessException {
ConfigHistoryInfo configHistoryInfo = this.historyConfigInfoPersistService.detailPreviousConfigHistory(id);
if (Objects.isNull(configHistoryInfo)) {
return null;
}
else {
this.checkHistoryInfoPermission(configHistoryInfo, dataId, group, namespaceId);
return configHistoryInfo;
}
}
public List<ConfigInfoWrapper> getConfigListByNamespace(String namespaceId) {
return this.configInfoPersistService.queryConfigInfoByNamespace(namespaceId);
}
/**
* 覆盖原有的校验方式oracle 数据库没有空 字符串 只有 null
* @param configHistoryInfo
* @param dataId
* @param group
* @param namespaceId
* @throws AccessException
*/
private void checkHistoryInfoPermission(ConfigHistoryInfo configHistoryInfo, String dataId, String group,
String namespaceId) throws AccessException {
if (!Objects.equals(configHistoryInfo.getDataId(), dataId)
|| !Objects.equals(configHistoryInfo.getGroup(), group)
|| (!StrUtil.isEmpty(configHistoryInfo.getTenant())
&& !Objects.equals(configHistoryInfo.getTenant(), namespaceId))) {
throw new AccessException("Please check dataId, group or namespaceId.");
}
}
}

View File

@ -0,0 +1,4 @@
/**
* 处理再oracle数据库下空置的判断
*/
package com.alibaba.nacos.config.service;