Skip to content

Commit

Permalink
Merge pull request #1923 from simonbaird/less-noisy-purl-is-valid
Browse files Browse the repository at this point in the history
Don't produce error output for invalid purl checks
  • Loading branch information
simonbaird authored Sep 5, 2024
2 parents a086d9d + 7515577 commit 3739a89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions acceptance/examples/purl.rego
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ deny contains result if {
}
}

# METADATA
# custom:
# short_name: parse_fail
deny contains result if {
# This will emit a failure too but this time an error is logged
not ec.purl.parse(_bad)
result := {
"code": "purl.parse_fail",
"msg": sprintf("PURL can't be parsed %q", [_bad])
}
}

# METADATA
# custom:
# short_name: is_valid_pass
Expand Down
6 changes: 6 additions & 0 deletions features/__snapshots__/validate_image.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3579,6 +3579,12 @@ Error: 1 error occurred:
"code": "purl.is_valid_fail"
}
},
{
"msg": "PURL can't be parsed \"this-is-not-a-valid-purl\"",
"metadata": {
"code": "purl.parse_fail"
}
},
{
"msg": "PURL parsed as: type: \"rpm\", namespace: \"rhel\", name: \"coreutils-single\", version: \"8.32-34.el9\", qualifiers: \"[{\\\"key\\\": \\\"arch\\\", \\\"value\\\": \\\"x86_64\\\"}, {\\\"key\\\": \\\"distro\\\", \\\"value\\\": \\\"rhel-9.3\\\"}, {\\\"key\\\": \\\"upstream\\\", \\\"value\\\": \\\"coreutils-8.32-34.el9.src.rpm\\\"}]\", subpath: \"\"",
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion internal/rego/purl/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func purlIsValid(bctx rego.BuiltinContext, a *ast.Term) (*ast.Term, error) {
}
_, err := packageurl.FromString(string(uri))
if err != nil {
log.Errorf("Parsing PURL %s failed: %s", uri, err)
log.Debugf("Parsing PURL %s failed: %s", uri, err)
return ast.BooleanTerm(false), nil
}
return ast.BooleanTerm(true), nil
Expand Down

0 comments on commit 3739a89

Please sign in to comment.