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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations