Search in sources :

Example 1 with CheckmarxSessionData

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData in project sechub by mercedes-benz.

the class CheckmarxProjectSupportTest method test_data_can_be_extracted.

@Test
public void test_data_can_be_extracted() throws AdapterException {
    /* prepare */
    String data = "[{\r\n" + "    \"id\": 1234,\r\n" + "    \"teamId\": \"xxxx-aax7-45asdf-b194-c736b605700d\",\r\n" + "    \"name\": \"TheName\",\r\n" + "    \"isPublic\": true,\r\n" + "    \"customFields\": [],\r\n" + "    \"links\": [\r\n" + "      {\r\n" + "        \"rel\": \"self\",\r\n" + "        \"uri\": \"/projects/113\"\r\n" + "      },\r\n" + "      {\r\n" + "        \"rel\": \"teams\",\r\n" + "        \"uri\": \"/auth/teams/\"\r\n" + "      },\r\n" + "      {\r\n" + "        \"rel\": \"latestscan\",\r\n" + "        \"uri\": \"/sast/scans?projectId=12213&last=1\"\r\n" + "      },\r\n" + "      {\r\n" + "        \"rel\": \"allscans\",\r\n" + "        \"uri\": \"/sast/scans?projectId=12213\"\r\n" + "      },\r\n" + "      {\r\n" + "        \"rel\": \"scansettings\",\r\n" + "        \"uri\": \"/sast/scanSettings/1234\"\r\n" + "      },\r\n" + "      {\r\n" + "        \"type\": \"local\",\r\n" + "        \"rel\": \"source\",\r\n" + "        \"uri\": null\r\n" + "      }\r\n" + "    ]\r\n" + "  }\r\n" + "]{Cache-Control=[no-cache], Pragma=[no-cache], Content-Type=[application/json; charset=utf-8], Expires=[-1], Server=[Microsoft-IIS/8.5], api-version=[2.0], X-AspNet-Version=[4.0.30319], X-Powered-By=[ASP.NET], Date=[Tue, 25 Sep 2018 14:06:42 GMT], Content-Length=[725]}";
    /* execute */
    CheckmarxSessionData result = supportToTest.extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport.FOR_UNKNOWN_ADAPTER, data);
    /* test */
    assertNotNull(result);
    assertEquals(1234L, result.getProjectId());
    assertEquals("TheName", result.getProjectName());
}
Also used : CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) Test(org.junit.Test)

Example 2 with CheckmarxSessionData

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method extractFirstProjectFromJsonWithProjectArray.

CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException {
    CheckmarxSessionData data = new CheckmarxSessionData();
    Access rootNode = support.fetchRootNode(json);
    Access first = support.fetchArray(0, rootNode.asArray());
    data.setProjectId(first.fetch("id").asLong());
    data.setProjectName(first.fetch("name").asText());
    return data;
}
Also used : CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)

Example 3 with CheckmarxSessionData

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method extractProjectFromJsonWithProjectCreationData.

CheckmarxSessionData extractProjectFromJsonWithProjectCreationData(String projectName, JSONAdapterSupport support, String json) throws AdapterException {
    CheckmarxSessionData data = new CheckmarxSessionData();
    Access rootNode = support.fetchRootNode(json);
    data.setProjectId(rootNode.fetch("id").asLong());
    data.setProjectName(projectName);
    return data;
}
Also used : CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)

Example 4 with CheckmarxSessionData

use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method createProject.

private CheckmarxSessionData createProject(CheckmarxContext context) throws AdapterException {
    CheckmarxAdapterConfig config = context.getConfig();
    String projectName = config.getProjectId();
    String teamId = config.getTeamIdForNewProjects();
    Map<String, String> json = new TreeMap<>();
    json.put("name", projectName);
    json.put("owningTeam", teamId);
    json.put("isPublic", "false");
    String url = context.getAPIURL("projects");
    String jsonAsString = context.json().toJSON(json);
    RestOperations restTemplate = context.getRestOperations();
    // https://checkmarx.atlassian.net/wiki/spaces/KC/pages/222265747/Create+Project+with+Default+Configuration+-+POST+projects
    // https://checkmarx.atlassian.net/wiki/spaces/KC/pages/814285654/Swagger+Examples+v8.8.0+-+v2
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.set("Content-Type", "application/json;v=2.0");
    HttpEntity<String> request = new HttpEntity<>(jsonAsString, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    CheckmarxSessionData sessionData = extractProjectFromJsonWithProjectCreationData(projectName, context.json(), response.getBody());
    updatePresetIdAndEngineConfigurationIfNecessary(context, sessionData);
    return sessionData;
}
Also used : HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) TreeMap(java.util.TreeMap) RestOperations(org.springframework.web.client.RestOperations)

Aggregations

CheckmarxSessionData (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData)4 Access (com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)2 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1 HttpEntity (org.springframework.http.HttpEntity)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 RestOperations (org.springframework.web.client.RestOperations)1