Search in sources :

Example 1 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetrieverTest method retrieveTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_BLACKDUCK_CONNECTION) })
public void retrieveTestIT() throws AlertException {
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
    BlackDuckSSOConfigRetriever ssoConfigRetriever = BlackDuckSSOConfigRetriever.fromProperties(blackDuckProperties);
    try {
        BlackDuckSSOConfigView ssoConfig = ssoConfigRetriever.retrieve();
        System.out.println("SSO Config:");
        System.out.println(ssoConfig);
    } catch (AlertException e) {
        fail("SSO Config Retrieval Failed", e);
    }
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Example 2 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverFactoryTest method createBlackDuckProperties.

private BlackDuckProperties createBlackDuckProperties(String blackDuckUrl) {
    ConfigurationModel configurationModel = createConfigurationModel(blackDuckUrl);
    ProxyManager proxyManager = new ProxyManager(new MockSettingsUtility());
    return new BlackDuckProperties(1L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), new MockAlertProperties(), proxyManager, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Gson(com.google.gson.Gson)

Example 3 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestAction method testConfig.

@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
    ArrayList<AlertFieldStatus> fieldStatuses = new ArrayList<>();
    Optional<Long> optionalProviderConfigId = registeredFieldValues.getLong(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
    if (optionalProviderConfigId.isPresent()) {
        Long providerConfigId = optionalProviderConfigId.get();
        boolean filterByProjects = registeredFieldValues.getBoolean(ProviderDescriptor.KEY_FILTER_BY_PROJECT).orElse(false);
        if (filterByProjects) {
            Collection<String> configuredProjects = registeredFieldValues.getAllStrings(ProviderDescriptor.KEY_CONFIGURED_PROJECT);
            validateSelectedProjectExists(providerConfigId, configuredProjects).ifPresent(fieldStatuses::add);
            Optional<String> optionalProjectNamePattern = registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN);
            optionalProjectNamePattern.flatMap(projectNamePattern -> validatePatternMatchesProject(providerConfigId, projectNamePattern)).ifPresent(fieldStatuses::add);
            registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN).flatMap(projectVersionNamePattern -> validatePatternMatchesProjectVersion(providerConfigId, projectVersionNamePattern, optionalProjectNamePattern.orElse(null), configuredProjects)).ifPresent(fieldStatuses::add);
        }
        BlackDuckProperties blackDuckProperties = null;
        Optional<ConfigurationModel> providerConfigurationOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
        if (providerConfigurationOptional.isPresent()) {
            ConfigurationModel providerConfiguration = providerConfigurationOptional.get();
            StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerConfiguration);
            blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
        }
        if (null != blackDuckProperties) {
            BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
            if (!blackDuckAPITokenValidator.isApiTokenValid()) {
                fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "User permission failed, cannot read notifications from Black Duck."));
            }
        }
    } else {
        fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "A provider configuration is required"));
    }
    if (MessageResult.hasFieldStatusBySeverity(fieldStatuses, FieldStatusSeverity.ERROR)) {
        return new MessageResult("There were errors with the BlackDuck provider fields", fieldStatuses);
    }
    return new MessageResult("Successfully tested BlackDuck provider fields", fieldStatuses);
}
Also used : BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) FieldStatusSeverity(com.synopsys.integration.alert.common.descriptor.config.field.errors.FieldStatusSeverity) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Nullable(org.springframework.lang.Nullable) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator)

Example 4 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.

private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
    Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
    if (optionalProperties.isPresent()) {
        BlackDuckProperties blackDuckProperties = optionalProperties.get();
        Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
        try {
            BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
            return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
        } catch (AlertException e) {
            throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
        }
    }
    throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 5 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckProjectCustomFunctionAction method validateBlackDuckConfiguration.

private void validateBlackDuckConfiguration(Long blackDuckConfigId) {
    BlackDuckProperties blackDuckProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "The BlackDuck configuration used in this Job does not exist"));
    BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
    if (!blackDuckAPITokenValidator.isApiTokenValid()) {
        throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid permissions. The BlackDuck user configured would not have proper access to notifications for these projects.");
    }
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ResponseStatusException(org.springframework.web.server.ResponseStatusException) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator)

Aggregations

BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)25 Test (org.junit.jupiter.api.Test)15 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)9 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)7 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)7 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)7 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)6 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)5 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)4 IntLogger (com.synopsys.integration.log.IntLogger)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)3 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)3 Gson (com.google.gson.Gson)2 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2