Search in sources :

Example 1 with OctaneConfiguration

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;
}
Also used : ConfigStructure(com.microfocus.octane.gitlab.model.ConfigStructure) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) PermissionException(com.hp.octane.integrations.exceptions.PermissionException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Example 2 with OctaneConfiguration

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());
    }
}
Also used : OctaneConnectivityException(com.hp.octane.integrations.exceptions.OctaneConnectivityException) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) IOException(java.io.IOException) OctaneConnectivityException(com.hp.octane.integrations.exceptions.OctaneConnectivityException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 3 with OctaneConfiguration

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());
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern)

Example 4 with OctaneConfiguration

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();
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) LinkedList(java.util.LinkedList) List(java.util.List) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with OctaneConfiguration

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();
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) LinkedList(java.util.LinkedList) List(java.util.List) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)11 OctaneConfigurationIntern (com.hp.octane.integrations.OctaneConfigurationIntern)6 OctaneClient (com.hp.octane.integrations.OctaneClient)5 OctaneSDK (com.hp.octane.integrations.OctaneSDK)4 OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)4 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)2 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 CIEventCause (com.hp.octane.integrations.dto.causes.CIEventCause)1 CIEventCauseType (com.hp.octane.integrations.dto.causes.CIEventCauseType)1 CoverageReportType (com.hp.octane.integrations.dto.coverage.CoverageReportType)1 CIEvent (com.hp.octane.integrations.dto.events.CIEvent)1 CIEventType (com.hp.octane.integrations.dto.events.CIEventType)1 CIEventsList (com.hp.octane.integrations.dto.events.CIEventsList)1