Search in sources :

Example 1 with Credentials

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

the class ChannelRestConnectionFactoryTest method testConnectionFields.

@Test
public void testConnectionFields() throws EncryptionException {
    final String host = "host";
    final int port = 1;
    final Credentials credentials = new Credentials("username", "password");
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    globalProperties.setHubProxyHost(host);
    globalProperties.setHubProxyUsername(credentials.getUsername());
    globalProperties.setHubProxyPassword(credentials.getDecryptedPassword());
    globalProperties.setHubProxyPort(String.valueOf(port));
    globalProperties.setHubTrustCertificate(true);
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection("https:url");
    final ProxyInfo expectedProxyInfo = new ProxyInfo(host, port, credentials, null, null, null);
    assertNotNull(restConnection);
    assertEquals(expectedProxyInfo, restConnection.getProxyInfo());
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) Credentials(com.blackducksoftware.integration.hub.Credentials) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 2 with Credentials

use of com.blackducksoftware.integration.hub.Credentials in project hub-docker-inspector by blackducksoftware.

the class HubClient method phoneHomeNoHubConnection.

private void phoneHomeNoHubConnection(final String dockerEngineVersion) {
    try {
        final IntLogger intLogger = new Slf4jIntLogger(logger);
        final ProxyInfo proxyInfo = new ProxyInfo(config.getHubProxyHost(), Integer.parseInt(config.getHubProxyPort()), new Credentials(config.getHubProxyUsername(), config.getHubProxyPassword()), null, null, null);
        final boolean alwaysTrustServerCertificate = config.isHubAlwaysTrustCert();
        final PhoneHomeClient phClient = new PhoneHomeClient(intLogger, 15, proxyInfo, alwaysTrustServerCertificate);
        final Map<String, String> infoMap = new HashMap<>();
        infoMap.put("blackDuckName", BlackDuckName.HUB.getName());
        infoMap.put("blackDuckVersion", "None");
        infoMap.put("thirdPartyName", THIRD_PARTY_NAME_DOCKER);
        infoMap.put("thirdPartyVersion", dockerEngineVersion);
        infoMap.put("pluginVersion", programVersion.getProgramVersion());
        if (!StringUtils.isBlank(config.getCallerName())) {
            infoMap.put(PHONE_HOME_METADATA_NAME_CALLER_NAME, config.getCallerName());
        }
        if (!StringUtils.isBlank(config.getCallerVersion())) {
            infoMap.put(PHONE_HOME_METADATA_NAME_CALLER_VERSION, config.getCallerVersion());
        }
        final PhoneHomeRequestBody phoneHomeRequestBody = new PhoneHomeRequestBody("None", "Integrations", infoMap);
        phClient.postPhoneHomeRequest(phoneHomeRequestBody, new CIEnvironmentVariables());
    } catch (final Throwable t) {
        logger.debug(String.format("Unable to phone home: %s", t.getMessage()));
    }
}
Also used : PhoneHomeRequestBody(com.blackducksoftware.integration.phonehome.PhoneHomeRequestBody) ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) PhoneHomeClient(com.blackducksoftware.integration.phonehome.PhoneHomeClient) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HashMap(java.util.HashMap) IntLogger(com.blackducksoftware.integration.log.IntLogger) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) Credentials(com.blackducksoftware.integration.hub.Credentials) CIEnvironmentVariables(com.blackducksoftware.integration.util.CIEnvironmentVariables)

Aggregations

Credentials (com.blackducksoftware.integration.hub.Credentials)2 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)2 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 IntLogger (com.blackducksoftware.integration.log.IntLogger)1 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)1 PhoneHomeClient (com.blackducksoftware.integration.phonehome.PhoneHomeClient)1 PhoneHomeRequestBody (com.blackducksoftware.integration.phonehome.PhoneHomeRequestBody)1 CIEnvironmentVariables (com.blackducksoftware.integration.util.CIEnvironmentVariables)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1