use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationMessageExtractor method createBomComponentDetails.
@Override
protected List<BomComponentDetails> createBomComponentDetails(VulnerabilityUniqueProjectNotificationContent notificationContent, BlackDuckServicesFactory blackDuckServicesFactory) throws IntegrationException {
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
AffectedProjectVersion affectedProjectVersion = notificationContent.getAffectedProjectVersion();
String bomComponentUrl = affectedProjectVersion.getBomComponent();
List<ComponentConcern> componentConcerns = createComponentConcerns(notificationContent);
BomComponentDetails bomComponentDetails;
try {
ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(bomComponentUrl), ProjectVersionComponentVersionView.class);
ComponentUpgradeGuidance componentUpgradeGuidance = createComponentUpgradeGuidance(blackDuckApiClient, bomComponent);
bomComponentDetails = bomComponentDetailsCreator.createBomComponentDetails(bomComponent, componentConcerns, componentUpgradeGuidance, List.of());
} catch (IntegrationRestException e) {
bomComponent404Handler.logIf404OrThrow(e, notificationContent.getComponentName(), notificationContent.getVersionName());
ComponentUpgradeGuidance componentUpgradeGuidance = createComponentUpgradeGuidance(blackDuckApiClient, notificationContent);
bomComponentDetails = bomComponentDetailsCreator.createMissingBomComponentDetailsForVulnerability(notificationContent.getComponentName(), bomComponentUrl, notificationContent.getVersionName(), componentConcerns, componentUpgradeGuidance, List.of());
}
return List.of(bomComponentDetails);
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class BlackDuckMessageBomComponentDetailsCreator method createMissingDetails.
private BomComponentDetails createMissingDetails(String componentName, Supplier<String> componentUrlRetriever, @Nullable String componentVersionName, Supplier<String> componentVersionUrlRetriever, List<ComponentConcern> componentConcerns, ComponentUpgradeGuidance componentUpgradeGuidance, List<LinkableItem> additionalAttributes) {
LinkableItem component;
LinkableItem componentVersion = null;
String componentVersionUrl = componentVersionUrlRetriever.get();
if (StringUtils.isNotBlank(componentVersionUrl)) {
component = new LinkableItem(BlackDuckMessageLabels.LABEL_COMPONENT, componentName);
componentVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_COMPONENT_VERSION, componentVersionName, componentVersionUrl);
} else {
component = new LinkableItem(BlackDuckMessageLabels.LABEL_COMPONENT, componentName, componentUrlRetriever.get());
}
LinkableItem licenseInfo = new LinkableItem(BlackDuckMessageLabels.LABEL_LICENSE, BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE);
String usageInfo = BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE;
return new BomComponentDetails(component, componentVersion, ComponentVulnerabilities.none(), List.of(), componentConcerns, licenseInfo, usageInfo, componentUpgradeGuidance, additionalAttributes, null);
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class AbstractRuleViolationNotificationMessageExtractor method createBomComponentDetails.
@Override
protected List<BomComponentDetails> createBomComponentDetails(T notificationContent, BlackDuckServicesFactory blackDuckServicesFactory) throws IntegrationException {
List<BomComponentDetails> bomComponentDetails = new LinkedList<>();
for (ComponentVersionStatus componentVersionStatus : notificationContent.getComponentVersionStatuses()) {
BomComponentDetails componentVersionDetails = createBomComponentDetails(blackDuckServicesFactory, notificationContent, componentVersionStatus);
bomComponentDetails.add(componentVersionDetails);
}
return bomComponentDetails;
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class AbstractBlackDuckComponentConcernMessageExtractor method extract.
@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
Long providerConfigId = notificationModel.getProviderConfigId();
String providerUrl;
List<BomComponentDetails> bomComponentDetails;
try {
BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
} catch (AlertConfigurationException e) {
logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
return ProviderMessageHolder.empty();
} catch (IntegrationException e) {
logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
return ProviderMessageHolder.empty();
}
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
// FIXME this is where I should put the additional info
ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class ProjectMessageConverter method convertToFormattedMessageChunks.
@Override
public List<String> convertToFormattedMessageChunks(ProjectMessage projectMessage, String jobName) {
ChunkedStringBuilder chunkedStringBuilder = new ChunkedStringBuilder(messageFormatter.getMaxMessageLength());
String projectString;
Optional<String> optionalProjectVersionString;
Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
if (optionalProjectVersion.isPresent()) {
projectString = linkableItemConverter.convertToStringWithoutLink(projectMessage.getProject(), true);
optionalProjectVersionString = optionalProjectVersion.map(projectVersion -> linkableItemConverter.convertToString(projectVersion, true));
} else {
projectString = linkableItemConverter.convertToString(projectMessage.getProject(), true);
optionalProjectVersionString = Optional.empty();
}
String nonBreakingSpace = messageFormatter.getNonBreakingSpace();
String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
String boldJobName = messageFormatter.emphasize(jobLine);
chunkedStringBuilder.append(boldJobName);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
chunkedStringBuilder.append(projectString);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
optionalProjectVersionString.ifPresent(projectVersionString -> {
chunkedStringBuilder.append(projectVersionString);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
});
MessageReason messageReason = projectMessage.getMessageReason();
if (MessageReason.PROJECT_STATUS.equals(messageReason) || MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
projectMessage.getOperation().map(operation -> String.format("Project%sAction:%s%s", nonBreakingSpace, nonBreakingSpace, operation.name())).map(messageFormatter::encode).ifPresent(chunkedStringBuilder::append);
return chunkedStringBuilder.collectCurrentChunks();
}
List<BomComponentDetails> bomComponents = projectMessage.getBomComponents();
if (!bomComponents.isEmpty()) {
chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
}
for (BomComponentDetails bomComponentDetails : bomComponents) {
List<String> bomComponentMessagePieces = gatherBomComponentAndConcernSectionPieces(bomComponentDetails);
bomComponentMessagePieces.forEach(chunkedStringBuilder::append);
chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
}
return chunkedStringBuilder.collectCurrentChunks();
}
Aggregations