Search in sources :

Example 1 with UriCombiner

use of com.blackducksoftware.integration.hub.rest.UriCombiner in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigThrowsExceptionTest.

@Test
public void testGlobalConfigThrowsExceptionTest() throws IntegrationException, MalformedURLException {
    final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    RestConnection restConnection = new UnauthenticatedRestConnection(new PrintStreamIntLogger(System.out, LogLevel.INFO), new URL("http://google.com"), 100, null, new UriCombiner());
    restConnection = Mockito.spy(restConnection);
    Mockito.doThrow(new IntegrationException("Mock exception")).when(restConnection).connect();
    Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(restConnection);
    hipChatMockUtil.setApiKey("apiKey");
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
    } catch (final IntegrationException ex) {
        assertEquals("Invalid API key: Mock exception", ex.getMessage());
    }
}
Also used : UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) URL(java.net.URL) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 2 with UriCombiner

use of com.blackducksoftware.integration.hub.rest.UriCombiner in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testCreateRestConnection.

@Test
public void testCreateRestConnection() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String apiToken = "User";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setApiToken(apiToken);
    // we create this spy to skip the server validation that happens in the build method
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.doAnswer(new Answer<HubServerConfig>() {

        @Override
        public HubServerConfig answer(final InvocationOnMock invocation) throws Throwable {
            final HubServerConfig hubServerConfig = new HubServerConfig(new URL(url), 0, apiToken, new ProxyInfo(null, 0, null, null, null, null), false, new UriCombiner());
            return hubServerConfig;
        }
    }).when(serverConfigBuilder).build();
    final RestConnection restConnection = configActions.createRestConnection(serverConfigBuilder);
    assertNotNull(restConnection);
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) URL(java.net.URL) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 3 with UriCombiner

use of com.blackducksoftware.integration.hub.rest.UriCombiner in project hub-fortify-ssc-integration-service by blackducksoftware.

the class RestConnectionHelper method getRestConnection.

/**
 * Get the Hub REST connection
 *
 * @param serverConfig
 * @param logLevel
 * @return
 */
private static CredentialsRestConnection getRestConnection(final HubServerConfig serverConfig, final LogLevel logLevel) {
    CredentialsRestConnection restConnection;
    try {
        final ProxyInfo proxyInfo = getProxyInfo(serverConfig);
        restConnection = new CredentialsRestConnection(new PrintStreamIntLogger(System.out, logLevel), serverConfig.getHubUrl(), serverConfig.getGlobalCredentials().getUsername(), serverConfig.getGlobalCredentials().getDecryptedPassword(), serverConfig.getTimeout(), proxyInfo, new UriCombiner());
    } catch (final IllegalArgumentException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (final EncryptionException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return restConnection;
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) CredentialsRestConnection(com.blackducksoftware.integration.hub.rest.CredentialsRestConnection) EncryptionException(com.blackducksoftware.integration.exception.EncryptionException)

Example 4 with UriCombiner

use of com.blackducksoftware.integration.hub.rest.UriCombiner in project hub-detect by blackducksoftware.

the class OfflineScanner method offlineScan.

boolean offlineScan(final DetectProject detectProject, final HubScanConfig hubScanConfig, final String hubSignatureScannerOfflineLocalPath) throws IllegalArgumentException, IntegrationException, DetectUserFriendlyException, InterruptedException {
    final IntLogger intLogger = new Slf4jIntLogger(logger);
    final HubServerConfig hubServerConfig = new HubServerConfig(null, 0, (String) null, null, false, new UriCombiner());
    final CIEnvironmentVariables ciEnvironmentVariables = new CIEnvironmentVariables();
    ciEnvironmentVariables.putAll(System.getenv());
    final SimpleScanUtility simpleScanUtility = new SimpleScanUtility(intLogger, gson, hubServerConfig, ciEnvironmentVariables, hubScanConfig, detectProject.getProjectName(), detectProject.getProjectVersionName());
    CLILocation cliLocation = new CLILocation(intLogger, hubScanConfig.getToolsDir());
    if (StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
        cliLocation = new OfflineCLILocation(intLogger, new File(hubSignatureScannerOfflineLocalPath));
    }
    boolean cliInstalledOkay = checkCliInstall(cliLocation, intLogger);
    if (!cliInstalledOkay && StringUtils.isNotBlank(detectConfiguration.getHubSignatureScannerHostUrl())) {
        installSignatureScannerFromUrl(intLogger, hubScanConfig, ciEnvironmentVariables);
        cliInstalledOkay = checkCliInstall(cliLocation, intLogger);
    }
    if (!cliInstalledOkay && StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
        OfflineScanner.logger.warn(String.format("The signature scanner is not correctly installed at %s", hubSignatureScannerOfflineLocalPath));
        return false;
    } else if (!cliInstalledOkay) {
        OfflineScanner.logger.warn(String.format("The signature scanner is not correctly installed at %s", hubScanConfig.getToolsDir()));
        return false;
    } else {
        simpleScanUtility.setupAndExecuteScan(cliLocation);
        OfflineScanner.logger.info(String.format("The scan dry run files can be found in : %s", simpleScanUtility.getDataDirectory()));
        return true;
    }
}
Also used : UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) OfflineCLILocation(com.blackducksoftware.integration.hub.cli.OfflineCLILocation) CLILocation(com.blackducksoftware.integration.hub.cli.CLILocation) OfflineCLILocation(com.blackducksoftware.integration.hub.cli.OfflineCLILocation) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) IntLogger(com.blackducksoftware.integration.log.IntLogger) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) File(java.io.File) CIEnvironmentVariables(com.blackducksoftware.integration.util.CIEnvironmentVariables) SimpleScanUtility(com.blackducksoftware.integration.hub.cli.SimpleScanUtility)

Aggregations

UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)4 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)2 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2 PrintStreamIntLogger (com.blackducksoftware.integration.log.PrintStreamIntLogger)2 URL (java.net.URL)2 Test (org.junit.Test)2 EncryptionException (com.blackducksoftware.integration.exception.EncryptionException)1 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)1 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)1 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)1 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)1 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)1 CLILocation (com.blackducksoftware.integration.hub.cli.CLILocation)1 OfflineCLILocation (com.blackducksoftware.integration.hub.cli.OfflineCLILocation)1 SimpleScanUtility (com.blackducksoftware.integration.hub.cli.SimpleScanUtility)1 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)1 CredentialsRestConnection (com.blackducksoftware.integration.hub.rest.CredentialsRestConnection)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1