use of com.synopsys.integration.rest.HttpUrl 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);
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class AbstractRuleViolationNotificationMessageExtractor method createBomComponentDetails.
private BomComponentDetails createBomComponentDetails(BlackDuckServicesFactory blackDuckServicesFactory, T notificationContent, ComponentVersionStatus componentVersionStatus) throws IntegrationException {
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
ComponentConcern policyConcern = policyComponentConcernCreator.fromPolicyInfo(notificationContent.getPolicyInfo(), itemOperation);
try {
ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(componentVersionStatus.getBomComponent()), ProjectVersionComponentVersionView.class);
return bomComponentDetailsCreator.createBomComponentDetails(bomComponent, policyConcern, ComponentUpgradeGuidance.none(), List.of());
} catch (IntegrationRestException e) {
bomComponent404Handler.logIf404OrThrow(e, componentVersionStatus.getComponentName(), componentVersionStatus.getComponentVersionName());
return bomComponentDetailsCreator.createMissingBomComponentDetails(componentVersionStatus.getComponentName(), createComponentUrl(componentVersionStatus), componentVersionStatus.getComponentVersionName(), createComponentVersionUrl(componentVersionStatus), List.of(policyConcern), ComponentUpgradeGuidance.none(), List.of());
}
}
use of com.synopsys.integration.rest.HttpUrl 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);
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class BlackDuckProviderIssueHandler method retrieveExistingIssue.
private Optional<ProjectVersionIssuesView> retrieveExistingIssue(String projectVersionUrl, String blackDuckIssueId) throws IntegrationException {
HttpUrl projectVersionHttpUrl = new HttpUrl(projectVersionUrl);
ProjectVersionView projectVersion = blackDuckApiClient.getResponse(projectVersionHttpUrl, ProjectVersionView.class);
List<ProjectVersionIssuesView> bomComponentIssues = issueService.getIssuesForProjectVersion(projectVersion);
return bomComponentIssues.stream().filter(issue -> issue.getIssueId().equals(blackDuckIssueId)).findAny();
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class RestChannelUtility method createPostMessageRequest.
public Request createPostMessageRequest(String url, Map<String, String> headers, @Nullable Map<String, Set<String>> queryParameters, String jsonString) {
HttpUrl httpUrl;
try {
httpUrl = new HttpUrl(url);
} catch (IntegrationException e) {
throw new AlertRuntimeException(e);
}
Request.Builder requestBuilder = new Request.Builder().method(HttpMethod.POST).url(httpUrl);
requestBuilder.getHeaders().putAll(headers);
requestBuilder.bodyContent(new StringBodyContent(jsonString, BodyContentConverter.DEFAULT));
if (queryParameters != null && !queryParameters.isEmpty()) {
requestBuilder.queryParameters(queryParameters);
}
return requestBuilder.build();
}
Aggregations