Search in sources :

Example 6 with BlackDuckHttpClient

use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method createBlackDuckServicesFactory.

private BlackDuckServicesFactory createBlackDuckServicesFactory(ConfigurationModel blackDuckConfiguration) throws AlertException {
    BlackDuckProperties properties = blackDuckPropertiesFactory.createProperties(blackDuckConfiguration);
    BlackDuckHttpClient blackDuckHttpClient = properties.createBlackDuckHttpClient(logger);
    return properties.createBlackDuckServicesFactory(blackDuckHttpClient, logger);
}
Also used : BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)

Example 7 with BlackDuckHttpClient

use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.

the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.

@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
    String registrationId = null;
    String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    try {
        descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
        StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
        BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
        BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
        BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
        BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
        blackDuckVersion = blackDuckServerData.getVersion();
        registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
        blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
    } catch (IntegrationException ignored) {
    // ignoring this exception
    }
    // We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
    if (StringUtils.isBlank(registrationId)) {
        registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    }
    PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
    return phoneHomeBuilder;
}
Also used : PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BlackDuckServerData(com.synopsys.integration.blackduck.service.model.BlackDuckServerData) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)

Example 8 with BlackDuckHttpClient

use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.

the class BlackDuckCacheHttpClientCache method retrieveOrCreateBlackDuckCacheHttpClient.

public BlackDuckHttpClient retrieveOrCreateBlackDuckCacheHttpClient(Long blackDuckConfigId) throws IntegrationException {
    BlackDuckHttpClient cachedClient = httpClientCache.get(blackDuckConfigId);
    if (null != cachedClient) {
        return cachedClient;
    }
    BlackDuckProperties properties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("No BlackDuck configuration with id %s", blackDuckConfigId)));
    BlackDuckHttpClient blackDuckCacheClient = properties.createBlackDuckCacheClient(new Slf4jIntLogger(logger));
    httpClientCache.put(blackDuckConfigId, blackDuckCacheClient);
    return blackDuckCacheClient;
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 9 with BlackDuckHttpClient

use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.

the class BlackDuckIssueTrackerCallbackEventHandler method createBlackDuckServicesFactory.

private Optional<BlackDuckServicesFactory> createBlackDuckServicesFactory(BlackDuckProperties blackDuckProperties) {
    IntLogger intLogger = new Slf4jIntLogger(logger);
    try {
        BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
        return Optional.of(blackDuckServicesFactory);
    } catch (AlertException e) {
        logger.error("Failed to create a BlackDuck http client", e);
        return Optional.empty();
    }
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 10 with BlackDuckHttpClient

use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.

the class BlackDuckDataSyncTask method runProviderTask.

@Override
public void runProviderTask() {
    try {
        BlackDuckProperties providerProperties = getProviderProperties();
        Optional<BlackDuckHttpClient> optionalBlackDuckHttpClient = providerProperties.createBlackDuckHttpClientAndLogErrors(logger);
        if (optionalBlackDuckHttpClient.isPresent()) {
            BlackDuckHttpClient blackDuckHttpClient = optionalBlackDuckHttpClient.get();
            BlackDuckServicesFactory blackDuckServicesFactory = providerProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
            ProjectUsersService projectUsersService = blackDuckServicesFactory.createProjectUsersService();
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
            List<ProjectView> projectViews = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink());
            Map<ProjectView, ProviderProject> blackDuckToAlertProjects = mapBlackDuckProjectsToAlertProjects(projectViews, blackDuckApiClient);
            Map<ProviderProject, Set<String>> projectToEmailAddresses = getEmailsPerProject(blackDuckToAlertProjects, projectUsersService);
            Set<String> allRelevantBlackDuckUsers = getAllActiveBlackDuckUserEmailAddresses(blackDuckApiClient, apiDiscovery);
            blackDuckDataAccessor.updateProjectAndUserData(providerProperties.getConfigId(), projectToEmailAddresses, allRelevantBlackDuckUsers);
        } else {
            logger.error("Missing BlackDuck global configuration.");
        }
    } catch (IntegrationException | AlertRuntimeException e) {
        logger.error(String.format("Could not retrieve the current data from the BlackDuck server: %s", e.getMessage()), e);
    }
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject)

Aggregations

BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)15 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)3 IntLogger (com.synopsys.integration.log.IntLogger)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)2 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)2 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)2 RuleViolationNotificationMessageExtractor (com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor)2 BlackDuckComponentVulnerabilityDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator)2 BlackDuckMessageBomComponentDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory)2 BomComponent404Handler (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler)2 BlackDuckComponentPolicyDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory)2