Skip to content

Commit 0790847

Browse files
committed
add license policy rules
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 976ffec commit 0790847

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

policy/rules.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def count_violations(self, product, threshold, parameters):
3838
count = Package.objects.filter(
3939
productpackages__product=product,
4040
**self.package_filter,
41-
).count()
41+
).distinct().count()
4242

4343
return count if count > threshold else 0
4444

@@ -64,6 +64,26 @@ class UsagePolicyWarningRule(PackageBaseRule):
6464
package_filter = {"usage_policy__compliance_alert": "warning"}
6565

6666

67+
class LicensePolicyErrorRule(PackageBaseRule):
68+
rule_type = "license_policy_error"
69+
label = "License Policy Error"
70+
description = (
71+
"Detects packages whose licenses are assigned a usage policy"
72+
" with a compliance alert level of 'error'."
73+
)
74+
package_filter = {"licenses__usage_policy__compliance_alert": "error"}
75+
76+
77+
class LicensePolicyWarningRule(PackageBaseRule):
78+
rule_type = "license_policy_warning"
79+
label = "License Policy Warning"
80+
description = (
81+
"Detects packages whose licenses are assigned a usage policy"
82+
" with a compliance alert level of 'warning'."
83+
)
84+
package_filter = {"licenses__usage_policy__compliance_alert": "warning"}
85+
86+
6787
class LicenseCoverageGapRule(PackageBaseRule):
6888
rule_type = "license_coverage_gap"
6989
label = "License Coverage Gap"
@@ -103,6 +123,8 @@ def count_violations(self, product, threshold, parameters):
103123
RULE_REGISTRY = {
104124
UsagePolicyErrorRule.rule_type: UsagePolicyErrorRule(),
105125
UsagePolicyWarningRule.rule_type: UsagePolicyWarningRule(),
126+
LicensePolicyErrorRule.rule_type: LicensePolicyErrorRule(),
127+
LicensePolicyWarningRule.rule_type: LicensePolicyWarningRule(),
106128
LicenseCoverageGapRule.rule_type: LicenseCoverageGapRule(),
107129
VulnerabilityDetectedRule.rule_type: VulnerabilityDetectedRule(),
108130
}

0 commit comments

Comments
 (0)