Repository navigation
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
d6d90d4 to
a98af71
Compare
DependencyTrack 5.0 rejects a policy condition with subject EXPRESSION
unless it carries a violation type:
private void maybeValidateExpression(final PolicyCondition policyCondition) {
if (policyCondition.getSubject() != PolicyCondition.Subject.EXPRESSION) {
return;
}
if (policyCondition.getViolationType() == null) {
throw new BadRequestException(... "Expression conditions must define a violation type");
}
Every other subject carries an implicit violation type, declared on the
Subject enum itself, but EXPRESSION is declared as EXPRESSION(null) and so
depends entirely on the explicit field. Without it on the struct there is no
way to create an expression condition through this client.
Adds PolicyConditionViolationType (LICENSE, SECURITY, OPERATIONAL, matching
PolicyViolation.Type) and the missing PolicyConditionSubjectExpression
constant. The field is omitempty so conditions using any other subject
serialise exactly as before.
Signed-off-by: 1azunna <26540897+1azunna@users.noreply.github.com>
a98af71 to
33053e4
Compare
|
Thanks @1azunna! I am wondering whether we should bump the major version of this library before we start introducing v5-specific stuff. It'd be a pain to have the client work with v4 and v5 going forward. Thinking to cut a v1 release (since we're currently at v0 still) of the current state, and then merging your PRs into what will then become v2. WDYT? |
I think v4 and v5 compatible features can go in the v1 release and the v2 release can be strictly v5 features. |
Problem
PolicyConditionhas noviolationTypefield, so expression conditions cannot be created through this client — DependencyTrack rejects them with HTTP 400.PolicyConditionResource.maybeValidateExpression(DT 5.0.3):Every other subject supplies its own violation type from the
Subjectenum, butEXPRESSIONis declaredEXPRESSION(null)and depends entirely on the explicit field:Change
PolicyCondition.ViolationType, taggedjson:"violationType,omitempty"PolicyConditionViolationTypewithLICENSE,SECURITY,OPERATIONAL— matchingPolicyViolation.TypePolicyConditionSubjectExpression, which was also missing from the subject constantsBecause of
omitempty, conditions using any other subject serialise byte-identically to before, so this is purely additive.Tests
policy_condition_test.gocovers the serialisation contract. Written as unit tests so they run without a container, followingutil_test.go:violationTypeis emitted for an expression conditiongo build ./...,go vet ./...andgo test -run TestPolicyCondition ./...all pass.Context
Found while adding expression-condition support to SolarFactories/terraform-provider-dependencytrack, which vendors a fork of this client. I raised it here rather than on that fork because this is the canonical home for the change and the fork is currently identical to
main.