Search in sources :

Example 1 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder in project blackduck-common by blackducksoftware.

the class PolicyRuleServiceTestIT method createTestPolicy.

private PolicyRuleView createTestPolicy(String name) throws BlackDuckIntegrationException {
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addHighSeverityVulnerabilityCondition(PolicyRuleConditionOperatorType.GT, 0);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setCategory(PolicyRuleCategoryType.SECURITY);
    policyRuleView.setDescription("This is a policy that is used for testing in PolicyRuleServiceTestIT.");
    policyRuleView.setName(name);
    policyRuleView.setEnabled(false);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)

Example 2 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder in project blackduck-common by blackducksoftware.

the class CheckPolicyForProjectVersionRecipeTest method constructTestPolicy.

private PolicyRuleView constructTestPolicy(ComponentService componentService) throws IntegrationException {
    ExternalId externalId = constructExternalId();
    Optional<ComponentsView> searchResult = componentService.getSingleOrEmptyResult(externalId);
    ComponentVersionView componentVersionView = componentService.getComponentVersionView(searchResult.get()).get();
    /*
         * using the PolicyRuleExpressionSetBuilder we can build the expression
         * set for a PolicyRuleView
         */
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName("Test Rule" + System.currentTimeMillis());
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 3 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method createBlackDuckPolicyRuleView.

public PolicyRuleView createBlackDuckPolicyRuleView(String policyName, Supplier<ExternalId> externalIdSupplier) throws IntegrationException {
    setupBlackDuckServicesFactory();
    ComponentService componentService = blackDuckServicesFactory.createComponentService();
    ExternalId externalId = externalIdSupplier.get();
    ComponentsView searchResult = componentService.getSingleOrEmptyResult(externalId).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentsView for component: %s", externalId.getName())));
    ComponentVersionView componentVersionView = componentService.getComponentVersionView(searchResult).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentVersionView for component: %s", searchResult.getComponentName())));
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(policyName);
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentService(com.synopsys.integration.blackduck.service.dataservice.ComponentService) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 4 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder in project blackduck-common by blackducksoftware.

the class PolicyRuleService method createPolicyRuleForExternalId.

/**
 * This will create a policy rule that will be violated by the existence of a matching external id in the project's BOM.
 */
public HttpUrl createPolicyRuleForExternalId(ComponentService componentService, ExternalId externalId, String policyName) throws IntegrationException {
    Optional<ComponentsView> componentSearchResult = componentService.getSingleOrEmptyResult(externalId);
    if (!componentSearchResult.isPresent()) {
        throw new BlackDuckIntegrationException(String.format("The external id (%s) provided could not be found, so no policy can be created for it.", externalId.createExternalId()));
    }
    Optional<ComponentVersionView> componentVersionView = componentService.getComponentVersionView(componentSearchResult.get());
    if (!componentVersionView.isPresent()) {
        throw new BlackDuckIntegrationException(String.format("A component version could not be found for the provided external id (%s), so no policy can be created for it.", externalId.createExternalId()));
    }
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView.get());
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(policyName);
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return createPolicyRule(policyRuleView);
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 5 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder in project blackduck-common by blackducksoftware.

the class ProjectBomServiceTestIT method createTestPolicyRuleForProjectWithComponentVersion.

private PolicyRuleView createTestPolicyRuleForProjectWithComponentVersion(ProjectView projectView, ComponentVersionView componentVersion, String policyRuleName) throws BlackDuckIntegrationException {
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addProjectCondition(PolicyRuleConditionOperatorType.EQ, projectView);
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersion);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setCategory(PolicyRuleCategoryType.COMPONENT);
    policyRuleView.setEnabled(true);
    policyRuleView.setName(policyRuleName);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)

Aggregations

PolicyRuleExpressionView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 PolicyRuleExpressionSetBuilder (com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder)6 ComponentsView (com.synopsys.integration.blackduck.api.generated.response.ComponentsView)4 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)3 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 ComponentService (com.synopsys.integration.blackduck.service.dataservice.ComponentService)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1