Search in sources :

Example 1 with HubServerConfigBuilder

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

the class GlobalHubConfigActions method channelTestConfig.

@Override
public String channelTestConfig(final GlobalHubConfigRestModel restModel) throws IntegrationException {
    final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    String apiToken;
    if (restModel.isHubApiKeyIsSet()) {
        final GlobalHubConfigEntity foundEntity = getRepository().findOne(Long.parseLong(restModel.getId()));
        apiToken = foundEntity.getHubApiKey();
    } else {
        apiToken = restModel.getHubApiKey();
    }
    final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
    hubServerConfigBuilder.setHubUrl(globalProperties.getHubUrl());
    hubServerConfigBuilder.setTimeout(restModel.getHubTimeout());
    hubServerConfigBuilder.setProxyHost(globalProperties.getHubProxyHost());
    hubServerConfigBuilder.setProxyPort(globalProperties.getHubProxyPort());
    hubServerConfigBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
    hubServerConfigBuilder.setApiToken(apiToken);
    hubServerConfigBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
    if (globalProperties.getHubTrustCertificate() != null) {
        hubServerConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    }
    hubServerConfigBuilder.setLogger(intLogger);
    validateHubConfiguration(hubServerConfigBuilder);
    final RestConnection restConnection = createRestConnection(hubServerConfigBuilder);
    restConnection.connect();
    return "Successfully connected to the Hub.";
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 2 with HubServerConfigBuilder

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

the class GlobalHubConfigActionsTest method testValidConfig.

@Test
@Override
public void testValidConfig() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String user = "User";
    final String password = "Password";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setUsername(user);
    serverConfigBuilder.setUsername(password);
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
        fail();
    } catch (final AlertFieldException e) {
        assertNotNull(e);
        assertEquals("There were issues with the configuration.", e.getMessage());
        assertTrue(!e.getFieldErrors().isEmpty());
    }
    final HubServerConfigValidator validator = Mockito.mock(HubServerConfigValidator.class);
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.when(serverConfigBuilder.createValidator()).thenReturn(validator);
    Mockito.when(validator.assertValid()).thenReturn(new ValidationResults());
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
    } catch (final AlertFieldException e) {
        fail();
    }
}
Also used : ValidationResults(com.blackducksoftware.integration.validator.ValidationResults) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) HubServerConfigValidator(com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 3 with HubServerConfigBuilder

use of com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder 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 4 with HubServerConfigBuilder

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

the class GlobalProperties method createHubServerConfig.

public HubServerConfig createHubServerConfig(final IntLogger logger, final int hubTimeout, final String hubUsername, final String hubPassword) throws AlertException {
    final HubServerConfigBuilder hubServerConfigBuilder = createHubServerConfigBuilderWithoutAuthentication(logger, hubTimeout);
    hubServerConfigBuilder.setUsername(hubUsername);
    hubServerConfigBuilder.setPassword(hubPassword);
    try {
        return hubServerConfigBuilder.build();
    } catch (final IllegalStateException e) {
        throw new AlertException(e.getMessage(), e);
    }
}
Also used : HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 5 with HubServerConfigBuilder

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

the class GlobalProperties method createHubServerConfigBuilderWithoutAuthentication.

private HubServerConfigBuilder createHubServerConfigBuilderWithoutAuthentication(final IntLogger logger, final int hubTimeout) {
    final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
    hubServerConfigBuilder.setHubUrl(getHubUrl());
    hubServerConfigBuilder.setTimeout(hubTimeout);
    hubServerConfigBuilder.setProxyHost(getHubProxyHost());
    hubServerConfigBuilder.setProxyPort(getHubProxyPort());
    hubServerConfigBuilder.setProxyUsername(getHubProxyUsername());
    hubServerConfigBuilder.setProxyPassword(getHubProxyPassword());
    if (hubTrustCertificate != null) {
        hubServerConfigBuilder.setAlwaysTrustServerCertificate(hubTrustCertificate);
    }
    hubServerConfigBuilder.setLogger(logger);
    return hubServerConfigBuilder;
}
Also used : HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)

Aggregations

HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)7 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)4 Test (org.junit.Test)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)2 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)2 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)2 LoginRestModel (com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel)2 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)2 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)2 ValidationResults (com.blackducksoftware.integration.validator.ValidationResults)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)1 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 MockLoginRestModel (com.blackducksoftware.integration.hub.alert.mock.model.MockLoginRestModel)1 RoleAssignmentView (com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView)1 HubServerConfigValidator (com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1