Search in sources :

Example 1 with ConfigHistoryInfo

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;
}
Also used : ConfigHistoryInfo(com.alibaba.nacos.config.server.model.ConfigHistoryInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 2 with 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());
}
Also used : ConfigHistoryInfo(com.alibaba.nacos.config.server.model.ConfigHistoryInfo) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ConfigHistoryInfo

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());
}
Also used : ConfigHistoryInfo(com.alibaba.nacos.config.server.model.ConfigHistoryInfo) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ArrayList(java.util.ArrayList) Page(com.alibaba.nacos.config.server.model.Page) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) Timestamp(java.sql.Timestamp) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with ConfigHistoryInfo

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());
}
Also used : ConfigHistoryInfo(com.alibaba.nacos.config.server.model.ConfigHistoryInfo) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 5 with ConfigHistoryInfo

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;
}
Also used : ConfigHistoryInfo(com.alibaba.nacos.config.server.model.ConfigHistoryInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Aggregations

ConfigHistoryInfo (com.alibaba.nacos.config.server.model.ConfigHistoryInfo)5 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 Test (org.junit.Test)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 Secured (com.alibaba.nacos.auth.annotation.Secured)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Page (com.alibaba.nacos.config.server.model.Page)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1