use of com.alibaba.nacos.config.server.model.ConfigHistoryInfo in project nacos by alibaba.
the class HistoryController method getConfigHistoryInfo.
/**
* Query the detailed configuration history information. notes:
*
* @param nid history_config_info nid
* @param dataId dataId @since 2.0.3
* @param group groupId @since 2.0.3
* @param tenant tenantId @since 2.0.3
* @return history config info
* @since 2.0.3 add {@link Secured}, dataId, groupId and tenant for history config permission check.
*/
@GetMapping
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public ConfigHistoryInfo getConfigHistoryInfo(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant, @RequestParam("nid") Long nid) throws AccessException {
ConfigHistoryInfo configHistoryInfo = persistService.detailConfigHistory(nid);
if (Objects.isNull(configHistoryInfo)) {
return null;
}
// check if history config match the input
checkHistoryInfoPermission(configHistoryInfo, dataId, group, tenant);
String encryptedDataKey = configHistoryInfo.getEncryptedDataKey();
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, encryptedDataKey, configHistoryInfo.getContent());
configHistoryInfo.setContent(pair.getSecond());
return configHistoryInfo;
}
use of com.alibaba.nacos.config.server.model.ConfigHistoryInfo in project nacos by alibaba.
the class HistoryControllerTest method testGetConfigHistoryInfo.
@Test
public void testGetConfigHistoryInfo() throws Exception {
ConfigHistoryInfo configHistoryInfo = new ConfigHistoryInfo();
configHistoryInfo.setDataId("test");
configHistoryInfo.setGroup("test");
configHistoryInfo.setContent("test");
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));
when(persistService.detailConfigHistory(1L)).thenReturn(configHistoryInfo);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.HISTORY_CONTROLLER_PATH).param("dataId", "test").param("group", "test").param("tenant", "").param("nid", "1");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
ConfigHistoryInfo resConfigHistoryInfo = JacksonUtils.toObj(actualValue, ConfigHistoryInfo.class);
Assert.assertEquals(configHistoryInfo.getDataId(), resConfigHistoryInfo.getDataId());
Assert.assertEquals(configHistoryInfo.getGroup(), resConfigHistoryInfo.getGroup());
Assert.assertEquals(configHistoryInfo.getContent(), resConfigHistoryInfo.getContent());
}
use of com.alibaba.nacos.config.server.model.ConfigHistoryInfo in project nacos by alibaba.
the class HistoryControllerTest method testListConfigHistory.
@Test
public void testListConfigHistory() throws Exception {
ConfigHistoryInfo configHistoryInfo = new ConfigHistoryInfo();
configHistoryInfo.setDataId("test");
configHistoryInfo.setGroup("test");
configHistoryInfo.setContent("test");
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));
List<ConfigHistoryInfo> configHistoryInfoList = new ArrayList<>();
configHistoryInfoList.add(configHistoryInfo);
Page<ConfigHistoryInfo> page = new Page<>();
page.setTotalCount(15);
page.setPageNumber(1);
page.setPagesAvailable(2);
page.setPageItems(configHistoryInfoList);
when(persistService.findConfigHistory("test", "test", "", 1, 10)).thenReturn(page);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.HISTORY_CONTROLLER_PATH).param("search", "accurate").param("dataId", "test").param("group", "test").param("tenant", "").param("appName", "").param("pageNo", "1").param("pageSize", "10");
MockHttpServletResponse response = mockmvc.perform(builder).andReturn().getResponse();
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
JsonNode pageItemsNode = JacksonUtils.toObj(actualValue).get("pageItems");
List resultList = JacksonUtils.toObj(pageItemsNode.toString(), List.class);
ConfigHistoryInfo resConfigHistoryInfo = JacksonUtils.toObj(pageItemsNode.get(0).toString(), ConfigHistoryInfo.class);
Assert.assertEquals(configHistoryInfoList.size(), resultList.size());
Assert.assertEquals(configHistoryInfo.getDataId(), resConfigHistoryInfo.getDataId());
Assert.assertEquals(configHistoryInfo.getGroup(), resConfigHistoryInfo.getGroup());
Assert.assertEquals(configHistoryInfo.getContent(), resConfigHistoryInfo.getContent());
}
use of com.alibaba.nacos.config.server.model.ConfigHistoryInfo in project nacos by alibaba.
the class HistoryControllerTest method testGetPreviousConfigHistoryInfo.
@Test
public void testGetPreviousConfigHistoryInfo() throws Exception {
ConfigHistoryInfo configHistoryInfo = new ConfigHistoryInfo();
configHistoryInfo.setDataId("test");
configHistoryInfo.setGroup("test");
configHistoryInfo.setContent("test");
configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime()));
configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime()));
when(persistService.detailPreviousConfigHistory(1L)).thenReturn(configHistoryInfo);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.HISTORY_CONTROLLER_PATH + "/previous").param("dataId", "test").param("group", "test").param("tenant", "").param("id", "1");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
ConfigHistoryInfo resConfigHistoryInfo = JacksonUtils.toObj(actualValue, ConfigHistoryInfo.class);
Assert.assertEquals(configHistoryInfo.getDataId(), resConfigHistoryInfo.getDataId());
Assert.assertEquals(configHistoryInfo.getGroup(), resConfigHistoryInfo.getGroup());
Assert.assertEquals(configHistoryInfo.getContent(), resConfigHistoryInfo.getContent());
}
use of com.alibaba.nacos.config.server.model.ConfigHistoryInfo in project nacos by alibaba.
the class HistoryController method getPreviousConfigHistoryInfo.
/**
* Query previous config history information. notes:
*
* @param id config_info id
* @param dataId dataId @since 2.0.3
* @param group groupId @since 2.0.3
* @param tenant tenantId @since 2.0.3
* @return history config info
* @since 2.0.3 add {@link Secured}, dataId, groupId and tenant for history config permission check.
* @since 1.4.0
*/
@GetMapping(value = "/previous")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public ConfigHistoryInfo getPreviousConfigHistoryInfo(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant, @RequestParam("id") Long id) throws AccessException {
ConfigHistoryInfo configHistoryInfo = persistService.detailPreviousConfigHistory(id);
if (Objects.isNull(configHistoryInfo)) {
return null;
}
// check if history config match the input
checkHistoryInfoPermission(configHistoryInfo, dataId, group, tenant);
return configHistoryInfo;
}
Aggregations