use of com.hp.octane.integrations.OctaneConfiguration in project octane-gitlab-service by MicroFocus.
the class OctaneServices method getOctaneConfiguration.
/* @Override*/
public OctaneConfiguration getOctaneConfiguration() {
OctaneConfiguration result = null;
try {
ConfigStructure config = applicationSettings.getConfig();
if (config != null && config.getOctaneLocation() != null && !config.getOctaneLocation().isEmpty()) {
String octaneApiClientSecret = config.getOctaneApiClientSecret();
if (octaneApiClientSecret != null && octaneApiClientSecret.startsWith(PREFIX)) {
try {
octaneApiClientSecret = PasswordEncryption.decrypt(octaneApiClientSecret.substring(PREFIX.length()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
result = OctaneConfiguration.createWithUiLocation(config.getCiServerIdentity(), config.getOctaneLocation());
result.setClient(config.getOctaneApiClientID());
result.setSecret(octaneApiClientSecret);
ConfigurationParameterFactory.addParameter(result, EncodeCiJobBase64Parameter.KEY, "true");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-gitlab-service by MicroFocus.
the class Application method tryToConnectToOctane.
private static void tryToConnectToOctane(OctaneServices octaneServices) throws OctaneConnectivityException {
OctaneConfiguration octaneConfiguration = octaneServices.getOctaneConfiguration();
if (StringUtils.isEmpty(octaneConfiguration.getUrl())) {
throw new IllegalArgumentException("Location URL is missing");
}
if (StringUtils.isEmpty(octaneConfiguration.getClient())) {
throw new IllegalArgumentException("Client ID is missing");
}
if (StringUtils.isEmpty(octaneConfiguration.getSecret())) {
throw new IllegalArgumentException("Client Secret is missing");
}
octaneServices.getGitLabApiWrapper().getGitLabApi().getSecretToken();
try {
OctaneSDK.testOctaneConfigurationAndFetchAvailableWorkspaces(octaneConfiguration.getUrl(), octaneConfiguration.getSharedSpace(), octaneConfiguration.getClient(), octaneConfiguration.getSecret(), OctaneServices.class);
} catch (OctaneConnectivityException e) {
throw new IllegalArgumentException(e.getErrorMessageVal());
} catch (Exception e) {
throw new IllegalArgumentException("Unexpected exception :" + e.getMessage());
}
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class SSCIntegrationTest method runAsQueueItem.
public void runAsQueueItem() {
try {
//
// I
// add one client and verify it works okay
//
OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("jobSSC1", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
if (expectedOutput.expectNoPsuh) {
CIPluginSDKUtils.doWait(2000);
} else {
GeneralTestUtils.waitAtMostFor(12000, () -> {
if (pushVulnerabilitiesCollectors.get(spIdA) != null && pushVulnerabilitiesCollectors.get(spIdA).size() == 1) {
return true;
} else {
return null;
}
});
}
Assert.assertEquals(clientAInstanceId + "|jobSSC1|1", preFlightRequestCollectors.get(spIdA).get(0));
//
// III
// remove one client and verify it is shut indeed and the second continue to work okay
//
OctaneSDK.removeClient(clientA);
} finally {
// remove clients
OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
// remove simulators
if (simulators != null)
removeSPEPSimulators(simulators.values());
}
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceFunctionalityTest method testVulnerabilitiesFunctional.
@Test(timeout = 20000)
public void testVulnerabilitiesFunctional() {
Map<String, OctaneSPEndpointSimulator> simulators = null;
try {
String spIdA = UUID.randomUUID().toString();
String spIdB = UUID.randomUUID().toString();
String clientAInstanceId = UUID.randomUUID().toString();
String clientBInstanceId = UUID.randomUUID().toString();
Map<String, List<String>> preflightRequestCollectors = new LinkedHashMap<>();
Map<String, List<String>> pushVulnerabilitiesCollectors = new LinkedHashMap<>();
// init 2 shared space endpoints simulators
simulators = initSPEPSimulators(Stream.of(spIdA, spIdB).collect(Collectors.toSet()), preflightRequestCollectors, pushVulnerabilitiesCollectors);
//
// I
// add one client and verify it works okay
//
OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
Assert.assertFalse(preflightRequestCollectors.containsKey(spIdA));
Assert.assertFalse(preflightRequestCollectors.containsKey(spIdB));
//
// II
// add one more client and verify they are both works okay
//
OctaneConfiguration configB = new OctaneConfigurationIntern(clientBInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdB);
OctaneClient clientB = OctaneSDK.addClient(configB, VulnerabilitiesServicePluginServicesTest.class);
VulnerabilitiesService vulnerabilitiesServiceB = clientB.getVulnerabilitiesService();
vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
GeneralTestUtils.waitAtMostFor(12000, () -> {
if (preflightRequestCollectors.get(spIdA) != null && preflightRequestCollectors.get(spIdA).size() == 2 && preflightRequestCollectors.get(spIdB) != null && preflightRequestCollectors.get(spIdB).size() == 2) {
return true;
} else {
return null;
}
});
Assert.assertEquals(clientAInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdA).get(0));
Assert.assertEquals(clientAInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdA).get(1));
Assert.assertEquals(clientBInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdB).get(0));
Assert.assertEquals(clientBInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdB).get(1));
//
// III
// remove one client and verify it is shut indeed and the second continue to work okay
//
OctaneSDK.removeClient(clientA);
//
// IV
// remove second client and ensure no interactions anymore
//
OctaneSDK.removeClient(clientB);
} finally {
// remove clients
OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
// remove simulators
if (simulators != null)
removeSPEPSimulators(simulators.values());
SSCServerSimulator.instance().endSimulation();
}
}
use of com.hp.octane.integrations.OctaneConfiguration in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceFunctionalityTest method testVulnerabilitiesFunctionalSSC.
@Test(timeout = 20000)
public void testVulnerabilitiesFunctionalSSC() {
Map<String, OctaneSPEndpointSimulator> simulators = null;
try {
String spIdA = UUID.randomUUID().toString();
String clientAInstanceId = UUID.randomUUID().toString();
Map<String, List<String>> preflightRequestCollectors = new LinkedHashMap<>();
Map<String, List<String>> pushVulnerabilitiesCollectors = new LinkedHashMap<>();
simulators = initSPEPSimulatorsForSSC(Stream.of(spIdA).collect(Collectors.toSet()), preflightRequestCollectors, pushVulnerabilitiesCollectors);
//
// I
// add one client and verify it works okay
//
OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
prepareSSCSimulator();
vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("jobSSC1", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
GeneralTestUtils.waitAtMostFor(12000, () -> {
if (preflightRequestCollectors.get(spIdA) != null && preflightRequestCollectors.get(spIdA).size() == 1) {
return true;
} else {
return null;
}
});
Assert.assertEquals(clientAInstanceId + "|jobSSC1|1", preflightRequestCollectors.get(spIdA).get(0));
OctaneSDK.removeClient(clientA);
} finally {
// remove clients
OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
// remove simulators
if (simulators != null)
removeSPEPSimulators(simulators.values());
SSCServerSimulator.instance().endSimulation();
}
}
Aggregations