Search in sources :

Example 1 with PolicyStatusDescription

use of com.synopsys.integration.blackduck.service.model.PolicyStatusDescription in project hub-detect by blackducksoftware.

the class PolicyChecker method getPolicyStatus.

/**
 * For the given DetectProject, find the matching Hub project/version, then all of its code locations, then all of their scan summaries, wait until they are all complete, then get the policy status.
 * @throws IntegrationException
 */
public Optional<PolicyStatusDescription> getPolicyStatus(final ProjectService projectService, final ProjectVersionView version) throws IntegrationException {
    final Optional<VersionBomPolicyStatusView> versionBomPolicyStatusView = projectService.getPolicyStatusForVersion(version);
    if (!versionBomPolicyStatusView.isPresent()) {
        return Optional.empty();
    }
    final PolicyStatusDescription policyStatusDescription = new PolicyStatusDescription(versionBomPolicyStatusView.get());
    PolicySummaryStatusType statusEnum = PolicySummaryStatusType.NOT_IN_VIOLATION;
    if (policyStatusDescription.getCountInViolation() != null && policyStatusDescription.getCountInViolation().value > 0) {
        statusEnum = PolicySummaryStatusType.IN_VIOLATION;
    } else if (policyStatusDescription.getCountInViolationOverridden() != null && policyStatusDescription.getCountInViolationOverridden().value > 0) {
        statusEnum = PolicySummaryStatusType.IN_VIOLATION_OVERRIDDEN;
    }
    logger.info(String.format("Policy Status: %s", statusEnum.name()));
    return Optional.of(policyStatusDescription);
}
Also used : PolicyStatusDescription(com.synopsys.integration.blackduck.service.model.PolicyStatusDescription) PolicySummaryStatusType(com.synopsys.integration.blackduck.api.generated.enumeration.PolicySummaryStatusType) VersionBomPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.VersionBomPolicyStatusView)

Example 2 with PolicyStatusDescription

use of com.synopsys.integration.blackduck.service.model.PolicyStatusDescription in project hub-detect by blackducksoftware.

the class PolicyChecker method checkPolicy.

public void checkPolicy(final List<PolicySeverityType> policySeverities, final ProjectService projectService, final ProjectVersionView projectVersionView) throws IntegrationException {
    final Optional<PolicyStatusDescription> optionalPolicyStatusDescription = getPolicyStatus(projectService, projectVersionView);
    if (optionalPolicyStatusDescription.isPresent()) {
        PolicyStatusDescription policyStatusDescription = optionalPolicyStatusDescription.get();
        logger.info(policyStatusDescription.getPolicyStatusMessage());
        if (arePolicySeveritiesViolated(policyStatusDescription, policySeverities)) {
            eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_POLICY_VIOLATION, policyStatusDescription.getPolicyStatusMessage()));
        }
    } else {
        String availableLinks = StringUtils.join(projectVersionView.getAvailableLinks(), ", ");
        logger.warn("It is not possible to check the policy status for this project/version. The policy-status link must be present. The available links are: " + availableLinks);
    }
}
Also used : PolicyStatusDescription(com.synopsys.integration.blackduck.service.model.PolicyStatusDescription) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)

Aggregations

PolicyStatusDescription (com.synopsys.integration.blackduck.service.model.PolicyStatusDescription)2 ExitCodeRequest (com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)1 PolicySummaryStatusType (com.synopsys.integration.blackduck.api.generated.enumeration.PolicySummaryStatusType)1 VersionBomPolicyStatusView (com.synopsys.integration.blackduck.api.generated.view.VersionBomPolicyStatusView)1