Search in sources :

Example 6 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class ProjectMessageToIssueModelTransformer method createVulnerabilityProjectIssueModel.

private ProjectIssueModel createVulnerabilityProjectIssueModel(ProjectMessage projectMessage, IssueBomComponentDetails issueBomComponent, List<ComponentConcern> vulnerabilityConcerns) {
    List<IssueVulnerabilityModel> issueVulnerabilitiesAdded = new LinkedList<>();
    List<IssueVulnerabilityModel> issueVulnerabilitiesUpdated = new LinkedList<>();
    List<IssueVulnerabilityModel> issueVulnerabilitiesDeleted = new LinkedList<>();
    for (ComponentConcern vulnerabilityConcern : vulnerabilityConcerns) {
        IssueVulnerabilityModel issueVulnerabilityModel = IssueVulnerabilityModel.fromComponentConcern(vulnerabilityConcern);
        ItemOperation vulnOperation = vulnerabilityConcern.getOperation();
        if (ItemOperation.ADD.equals(vulnOperation)) {
            issueVulnerabilitiesAdded.add(issueVulnerabilityModel);
        } else if (ItemOperation.DELETE.equals(vulnOperation)) {
            issueVulnerabilitiesDeleted.add(issueVulnerabilityModel);
        } else {
            issueVulnerabilitiesUpdated.add(issueVulnerabilityModel);
        }
    }
    ComponentVulnerabilities componentVulnerabilities = issueBomComponent.getComponentVulnerabilities();
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(!componentVulnerabilities.hasVulnerabilities(), issueVulnerabilitiesAdded, issueVulnerabilitiesUpdated, issueVulnerabilitiesDeleted);
    return ProjectIssueModel.vulnerability(projectMessage.getProviderDetails(), projectMessage.getProject(), projectMessage.getProjectVersion().orElse(null), issueBomComponent, vulnerabilityDetails);
}
Also used : IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssueVulnerabilityModel(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) LinkedList(java.util.LinkedList) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)

Example 7 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createCustomFieldReplacementValues.

protected MessageReplacementValues createCustomFieldReplacementValues(ProjectIssueModel alertIssueSource) {
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    ComponentUpgradeGuidance upgradeGuidance = bomComponent.getComponentUpgradeGuidance();
    Optional<String> severity = Optional.empty();
    Optional<String> policyCategory = Optional.empty();
    Optional<IssuePolicyDetails> issuePolicyDetails = alertIssueSource.getPolicyDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = alertIssueSource.getVulnerabilityDetails();
    if (issuePolicyDetails.isPresent()) {
        IssuePolicyDetails policyDetails = issuePolicyDetails.get();
        severity = Optional.ofNullable(policyDetails.getSeverity().getPolicyLabel());
        policyCategory = bomComponent.getRelevantPolicies().stream().filter(policy -> policyDetails.getName().equals(policy.getPolicyName())).findAny().flatMap(ComponentPolicy::getCategory);
    }
    if (vulnerabilityDetails.isPresent()) {
        severity = vulnerabilityDetails.get().getHighestSeverityAddedOrUpdated();
    }
    return new MessageReplacementValues.Builder(alertIssueSource.getProvider().getLabel(), alertIssueSource.getProject().getValue()).projectVersionName(alertIssueSource.getProjectVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentName(bomComponent.getComponent().getValue()).componentVersionName(bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentUsage(bomComponent.getUsage()).componentLicense(bomComponent.getLicense().getValue()).severity(severity.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).policyCategory(policyCategory.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).shortTermUpgradeGuidance(upgradeGuidance.getShortTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).longTermUpgradeGuidance(upgradeGuidance.getLongTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).build();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) StringUtils(org.apache.commons.lang3.StringUtils) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) IssueResponseModel(com.synopsys.integration.jira.common.model.response.IssueResponseModel) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) IssueCreationResponseModel(com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssueStatus(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueStatus) IssueTrackerIssueCommenter(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCommenter) JiraPreconditionNotMetException(com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) JiraIssueAlertPropertiesManager(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesManager) JiraErrorMessageUtility(com.synopsys.integration.alert.api.channel.jira.distribution.JiraErrorMessageUtility) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueFieldsComponent(com.synopsys.integration.jira.common.model.components.IssueFieldsComponent) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssueTrackerIssueCreator(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCreator) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Optional(java.util.Optional) JiraIssueSearchPropertyStringCompatibilityUtils(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueSearchPropertyStringCompatibilityUtils) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) JiraCallbackUtils(com.synopsys.integration.alert.api.channel.jira.util.JiraCallbackUtils) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 8 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method isOnlyDeleteOperation.

private boolean isOnlyDeleteOperation(ProjectIssueModel projectIssueModel) {
    boolean isPolicyDelete = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isEstimatedRiskDelete = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isVulnerabilityDelete = false;
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        IssueVulnerabilityDetails vulnDetails = optionalVulnDetails.get();
        boolean allVulnsRemediated = vulnDetails.areAllComponentVulnerabilitiesRemediated();
        boolean hasDeletions = !vulnDetails.getVulnerabilitiesDeleted().isEmpty();
        boolean doesNotHaveAdditions = vulnDetails.getVulnerabilitiesAdded().isEmpty();
        boolean doesNotHaveUpdates = vulnDetails.getVulnerabilitiesUpdated().isEmpty();
        isVulnerabilityDelete = allVulnsRemediated || (hasDeletions && doesNotHaveAdditions && doesNotHaveUpdates);
    }
    return isPolicyDelete || isVulnerabilityDelete || isEstimatedRiskDelete;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation)

Example 9 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method createProjectIssueModelConcernSectionPieces.

private List<String> createProjectIssueModelConcernSectionPieces(ProjectIssueModel projectIssueModel, boolean commentFormat) {
    List<String> concernSectionPieces = new LinkedList<>();
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssuePolicyDetails> optionalPolicyDetails = projectIssueModel.getPolicyDetails();
    if (optionalPolicyDetails.isPresent()) {
        List<String> policyDetailsSectionPieces = issuePolicyDetailsConverter.createPolicyDetailsSectionPieces(bomComponentDetails, optionalPolicyDetails.get());
        concernSectionPieces.addAll(policyDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        List<String> vulnDetailsSectionPieces;
        if (commentFormat) {
            vulnDetailsSectionPieces = issueVulnerabilityDetailsConverter.createVulnerabilityDetailsSectionPieces(optionalVulnDetails.get());
        } else {
            vulnDetailsSectionPieces = componentVulnerabilitiesConverter.createComponentVulnerabilitiesSectionPieces(projectIssueModel.getBomComponentDetails().getComponentVulnerabilities());
        }
        concernSectionPieces.addAll(vulnDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueComponentUnknownVersionDetails> optionalUnknownVersionDetails = projectIssueModel.getComponentUnknownVersionDetails();
    if (optionalUnknownVersionDetails.isPresent()) {
        List<String> componentUnknownVersionDetailsSectionPieces;
        componentUnknownVersionDetailsSectionPieces = issueComponentUnknownVersionDetailsConverter.createEstimatedRiskDetailsSectionPieces(optionalUnknownVersionDetails.get());
        concernSectionPieces.addAll(componentUnknownVersionDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    return concernSectionPieces;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) LinkedList(java.util.LinkedList)

Example 10 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method createVulnerabilitySeverityStatusSectionPieces.

private List<String> createVulnerabilitySeverityStatusSectionPieces(ProjectIssueModel projectIssueModel) {
    List<String> severityStatusSectionPieces = new LinkedList<>();
    String encodedSeverityStatus = formatter.encode(LABEL_SEVERITY_STATUS);
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
    if (vulnerabilityDetails.isPresent()) {
        ComponentVulnerabilities componentVulnerabilities = bomComponentDetails.getComponentVulnerabilities();
        componentVulnerabilities.computeHighestSeverity().map(ComponentConcernSeverity::getVulnerabilityLabel).map(formatter::encode).map(severity -> encodedSeverityStatus + severity).ifPresentOrElse(severityStatusSectionPieces::add, () -> severityStatusSectionPieces.add(encodedSeverityStatus + "None"));
        severityStatusSectionPieces.add(formatter.getLineSeparator());
        severityStatusSectionPieces.add(formatter.getSectionSeparator());
        severityStatusSectionPieces.add(formatter.getLineSeparator());
    }
    return severityStatusSectionPieces;
}
Also used : ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ComponentConcernSeverity(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernSeverity) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities) StringUtils(org.apache.commons.lang3.StringUtils) IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ChunkedStringBuilderRechunker(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilderRechunker) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) BomComponentDetailConverter(com.synopsys.integration.alert.api.channel.convert.BomComponentDetailConverter) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) RechunkedModel(com.synopsys.integration.alert.common.channel.message.RechunkedModel) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) LinkedList(java.util.LinkedList) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) Optional(java.util.Optional) LinkableItemConverter(com.synopsys.integration.alert.api.channel.convert.LinkableItemConverter) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) LinkedList(java.util.LinkedList) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)

Aggregations

IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)14 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)10 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)8 Test (org.junit.jupiter.api.Test)8 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)6 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)5 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)4 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 AbstractBomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.AbstractBomComponentDetails)3 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)2 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)2 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2