Search in sources :

Example 1 with BlackDuckRequestBuilder

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

the class BlackDuckMessageBomComponentDetailsCreator method retrieveComponentVulnerabilities.

private ComponentVulnerabilities retrieveComponentVulnerabilities(ProjectVersionComponentVersionView bomComponent) throws IntegrationException {
    if (!vulnerabilityDetailsCreator.hasSecurityRisk(bomComponent)) {
        return ComponentVulnerabilities.none();
    }
    if (StringUtils.isBlank(bomComponent.getComponentVersion())) {
        return ComponentVulnerabilities.none();
    }
    List<HttpUrl> vulnerabilitiesUrls = createVulnerabilitiesLinks(bomComponent.getHref(), bomComponent.getOrigins());
    List<BlackDuckProjectVersionComponentVulnerabilitiesView> allVulnerabilitiesViews = new ArrayList<>();
    for (HttpUrl vulnerabilitiesUrl : vulnerabilitiesUrls) {
        UrlMultipleResponses<BlackDuckProjectVersionComponentVulnerabilitiesView> urlMultipleResponses = new UrlMultipleResponses<>(vulnerabilitiesUrl, VULNERABILITIES_LINK.getResponseClass());
        BlackDuckMultipleRequest<BlackDuckProjectVersionComponentVulnerabilitiesView> spec = new BlackDuckRequestBuilder().commonGet().addHeader(HttpHeaders.ACCEPT, VULNERABILITIES_MEDIA_TYPE).buildBlackDuckRequest(urlMultipleResponses);
        allVulnerabilitiesViews.addAll(blackDuckApiClient.getAllResponses(spec));
    }
    return vulnerabilityDetailsCreator.toComponentVulnerabilities(allVulnerabilitiesViews);
}
Also used : UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) ArrayList(java.util.ArrayList) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 2 with BlackDuckRequestBuilder

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

the class BlackDuckProviderDataAccessor method getProjectVersionNamesByHref.

@Override
public AlertPagedModel<String> getProjectVersionNamesByHref(Long providerConfigId, String projectHref, int pageNumber) {
    Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
    if (providerConfigOptional.isPresent()) {
        try {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
            BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(BlackDuckRequestBuilder.DEFAULT_LIMIT, pageNumber * BlackDuckRequestBuilder.DEFAULT_LIMIT);
            BlackDuckMultipleRequest<ProjectVersionView> projectVersionSpec = new BlackDuckRequestBuilder().commonGet().setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(foundProject.metaVersionsLink());
            BlackDuckPageResponse<ProjectVersionView> pageResponse = blackDuckApiClient.getPageResponse(projectVersionSpec);
            return new AlertPagedModel<>(pageResponse.getTotalCount(), pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT, pageResponse.getItems()).transformContent(ProjectVersionView::getVersionName);
        } catch (IntegrationException e) {
            logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
        }
    }
    return AlertPagedModel.empty(pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT);
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Example 3 with BlackDuckRequestBuilder

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

the class BlackDuckProviderIssueHandler method performRequest.

private void performRequest(HttpUrl httpUrl, HttpMethod httpMethod, IssueRequest issueRequest) throws IntegrationException {
    BlackDuckResponseRequest request = new BlackDuckRequestBuilder().method(httpMethod).bodyContent(new StringBodyContent(gson.toJson(issueRequest), BodyContentConverter.DEFAULT)).buildBlackDuckResponseRequest(httpUrl);
    blackDuckApiClient.execute(request);
}
Also used : StringBodyContent(com.synopsys.integration.rest.body.StringBodyContent) BlackDuckResponseRequest(com.synopsys.integration.blackduck.service.request.BlackDuckResponseRequest) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)

Example 4 with BlackDuckRequestBuilder

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

the class BlackDuckSSOConfigRetriever method retrieve.

public BlackDuckSSOConfigView retrieve() throws AlertException {
    BlackDuckRequestBuilder requestBuilder = new BlackDuckRequestBuilder().acceptMimeType(SSO_CONFIGURATION_MIME_TYPE);
    UrlSingleResponse<BlackDuckSSOConfigView> ssoConfigurationSingleResponse = apiDiscovery.metaSingleResponse(SSO_CONFIGURATION_PATH);
    BlackDuckRequest<BlackDuckSSOConfigView, UrlSingleResponse<BlackDuckSSOConfigView>> ssoConfigurationRequest = new BlackDuckRequest<>(requestBuilder, ssoConfigurationSingleResponse);
    try {
        return blackDuckApiClient.getResponse(ssoConfigurationRequest);
    } catch (IntegrationException e) {
        String errorMessage = String.format("Unable to retrieve SSO configuration from Black Duck: %s", e.getMessage());
        throw new AlertException(errorMessage, e);
    }
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 5 with BlackDuckRequestBuilder

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

the class BlackDuckProviderDataAccessor method retrieveBlackDuckPageResponse.

private <T extends BlackDuckResponse> BlackDuckPageResponse<T> retrieveBlackDuckPageResponse(BlackDuckServicesFactory blackDuckServicesFactory, UrlMultipleResponses<T> urlMultipleResponses, int pageNumber, int pageSize, Predicate<T> searchFilter) throws IntegrationException {
    BlackDuckResponsesTransformer blackDuckResponsesTransformer = blackDuckServicesFactory.getBlackDuckResponsesTransformer();
    int offset = pageNumber * pageSize;
    BlackDuckMultipleRequest<T> spec = new BlackDuckRequestBuilder().commonGet().setLimitAndOffset(pageSize, offset).buildBlackDuckRequest(urlMultipleResponses);
    return blackDuckResponsesTransformer.getSomeMatchingResponses(spec, searchFilter, pageSize);
}
Also used : BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer)

Aggregations

BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)8 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)3 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)2 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)2 BlackDuckQuery (com.synopsys.integration.blackduck.http.BlackDuckQuery)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)1 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)1 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 BlackDuckResponsesTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer)1