in config/src/main/java/com/alibaba/nacos/config/server/service/HistoryService.java [130:216]
public ConfigHistoryInfoDetail getConfigHistoryInfoDetail(String dataId, String group, String namespaceId, Long nid)
throws AccessException {
ConfigHistoryInfo configHistoryInfo = historyConfigInfoPersistService.detailConfigHistory(nid);
if (Objects.isNull(configHistoryInfo)) {
return null;
}
// check if history config match the input
checkHistoryInfoPermission(configHistoryInfo, dataId, group, namespaceId);
// transform
ConfigHistoryInfoDetail configHistoryInfoDetail = new ConfigHistoryInfoDetail();
BeanUtils.copyProperties(configHistoryInfo, configHistoryInfoDetail);
configHistoryInfoDetail.setOpType(configHistoryInfoDetail.getOpType().trim());
//insert
if (OperationType.INSERT.getValue().equals(configHistoryInfoDetail.getOpType())) {
configHistoryInfoDetail.setUpdatedContent(configHistoryInfo.getContent());
configHistoryInfoDetail.setUpdatedMd5(configHistoryInfo.getMd5());
configHistoryInfoDetail.setUpdatedEncryptedDataKey(configHistoryInfo.getEncryptedDataKey());
configHistoryInfoDetail.setUpdateExtInfo(configHistoryInfo.getExtInfo());
configHistoryInfoDetail.setOriginalExtInfo(StringUtils.EMPTY);
configHistoryInfoDetail.setOriginalContent(StringUtils.EMPTY);
configHistoryInfoDetail.setOriginalMd5(StringUtils.EMPTY);
configHistoryInfoDetail.setOriginalEncryptedDataKey(StringUtils.EMPTY);
}
//update
if (OperationType.UPDATE.getValue().equals(configHistoryInfoDetail.getOpType())) {
configHistoryInfoDetail.setOriginalExtInfo(configHistoryInfo.getExtInfo());
configHistoryInfoDetail.setOriginalContent(configHistoryInfo.getContent());
configHistoryInfoDetail.setOriginalMd5(configHistoryInfo.getMd5());
configHistoryInfoDetail.setOriginalEncryptedDataKey(configHistoryInfo.getEncryptedDataKey());
ConfigHistoryInfo nextHistoryInfo = historyConfigInfoPersistService.getNextHistoryInfo(dataId, group,
namespaceId, configHistoryInfoDetail.getPublishType(), configHistoryInfoDetail.getGrayName(), nid);
ConfigInfo currentConfigInfo = null;
if (Objects.isNull(nextHistoryInfo)) {
//double check for concurrent
currentConfigInfo = StringUtils.isEmpty(configHistoryInfoDetail.getGrayName())
? configInfoPersistService.findConfigInfo(dataId, group, namespaceId)
: configInfoGrayPersistService.findConfigInfo4Gray(dataId, group, namespaceId,
configHistoryInfoDetail.getGrayName());
nextHistoryInfo = historyConfigInfoPersistService.getNextHistoryInfo(dataId, group, namespaceId,
configHistoryInfoDetail.getPublishType(), configHistoryInfoDetail.getGrayName(), nid);
}
if (nextHistoryInfo != null) {
configHistoryInfoDetail.setUpdateExtInfo(nextHistoryInfo.getExtInfo());
configHistoryInfoDetail.setUpdatedContent(nextHistoryInfo.getContent());
configHistoryInfoDetail.setUpdatedMd5(nextHistoryInfo.getMd5());
configHistoryInfoDetail.setUpdatedEncryptedDataKey(nextHistoryInfo.getEncryptedDataKey());
} else {
configHistoryInfoDetail.setUpdatedContent(currentConfigInfo.getContent());
configHistoryInfoDetail.setUpdatedMd5(currentConfigInfo.getMd5());
configHistoryInfoDetail.setUpdatedEncryptedDataKey(currentConfigInfo.getEncryptedDataKey());
}
}
//delete
if (OperationType.DELETE.getValue().equals(configHistoryInfoDetail.getOpType())) {
configHistoryInfoDetail.setOriginalMd5(configHistoryInfo.getMd5());
configHistoryInfoDetail.setOriginalContent(configHistoryInfo.getContent());
configHistoryInfoDetail.setOriginalEncryptedDataKey(configHistoryInfo.getEncryptedDataKey());
configHistoryInfoDetail.setOriginalExtInfo(configHistoryInfo.getExtInfo());
}
// decrypt content
if (StringUtils.isNotBlank(configHistoryInfoDetail.getOriginalContent())) {
String originalContent = EncryptionHandler.decryptHandler(dataId,
configHistoryInfoDetail.getOriginalEncryptedDataKey(), configHistoryInfoDetail.getOriginalContent())
.getSecond();
configHistoryInfoDetail.setOriginalContent(originalContent);
}
if (StringUtils.isNotBlank(configHistoryInfoDetail.getUpdatedContent())) {
String updatedContent = EncryptionHandler.decryptHandler(dataId,
configHistoryInfoDetail.getUpdatedEncryptedDataKey(), configHistoryInfoDetail.getUpdatedContent())
.getSecond();
configHistoryInfoDetail.setUpdatedContent(updatedContent);
}
return configHistoryInfoDetail;
}