use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.
the class SSCIntegrationTest method initSPEPSimulatorsForSSC.
private Map<String, OctaneSPEndpointSimulator> initSPEPSimulatorsForSSC(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
for (String spID : spIDs) {
OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
// vulnerabilities preflight API
simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
try {
// retrieve query parameters
request.mergeQueryParameters("", request.getQueryString(), false);
preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
request.getResponse().setStatus(HttpStatus.SC_OK);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtils.octaneFormat);
request.getResponse().getWriter().write(getOctaneInput().baseline == null ? "true" : simpleDateFormat.format(getOctaneInput().baseline));
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
// vulnerabilities push API
simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
try {
String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
request.getResponse().getWriter().write("{\"status\": \"queued\"}");
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
// vulnerabilities push API
simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/remote-issue-ids.*", request -> {
try {
request.getResponse().setStatus(HttpStatus.SC_OK);
request.getResponse().getWriter().write(SSCTestUtils.getJson(this.getOctaneInput().remoteIds));
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
result.put(spID, simulator);
}
return result;
}
use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceFunctionalityTest method initSPEPSimulatorsForSSC.
private Map<String, OctaneSPEndpointSimulator> initSPEPSimulatorsForSSC(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
for (String spID : spIDs) {
OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
// vulnerabilities preflight API
simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
try {
// retrieve query parameters
request.mergeQueryParameters("", request.getQueryString(), false);
preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
request.getResponse().setStatus(HttpStatus.SC_OK);
request.getResponse().getWriter().write("true");
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
// vulnerabilities push API
simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
try {
String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
request.getResponse().getWriter().write("{\"status\": \"queued\"}");
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
result.put(spID, simulator);
}
return result;
}
use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceFunctionalityTest method initSPEPSimulators.
private Map<String, OctaneSPEndpointSimulator> initSPEPSimulators(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
for (String spID : spIDs) {
OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
// vulnerabilities preflight API
simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
try {
// retrieve query parameters
request.mergeQueryParameters("", request.getQueryString(), false);
preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
request.getResponse().setStatus(HttpStatus.SC_OK);
request.getResponse().getWriter().write(request.getQueryParameters().getString("job-ci-id").contains("true") ? "true" : "false");
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
// vulnerabilities push API
simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
try {
String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
request.getResponse().getWriter().write("{\"status\": \"queued\"}");
request.getResponse().getWriter().flush();
} catch (IOException ioe) {
throw new OctaneSDKGeneralException("failed to write response", ioe);
}
});
result.put(spID, simulator);
}
return result;
}
Aggregations