Skip to content

Commit 2598b0d

Browse files
committed
used the new refactored policy code
Signed-off-by: NucleonGodX <[email protected]>
1 parent cce65c7 commit 2598b0d

File tree

7 files changed

+25
-36
lines changed

7 files changed

+25
-36
lines changed

docs/tutorial_license_policies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ in the project:
149149
[resources]
150150
> ERROR: 1
151151
cuckoo_filter-1.0.6.tar.gz-extract/cuckoo_filter-1.0.6/README.md
152-
[License Clarity Compliance]
152+
[License Clarity]
153153
> Alert Level: error
154154
155155
.. tip::

scanpipe/api/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def clarity_compliance(self, request, *args, **kwargs):
494494
495495
"""
496496
project = self.get_object()
497-
clarity_alert = (project.extra_data or {}).get("clarity_compliance_alert")
497+
clarity_alert = project.get_clarity_compliance_alert()
498498
return Response({"clarity_compliance_alert": clarity_alert})
499499

500500

scanpipe/management/commands/check-compliance.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def check_compliance(self, fail_level):
7474
len(issues) for model in alerts.values() for issues in model.values()
7575
)
7676

77-
clarity_alert = self.get_clarity_compliance_alert()
77+
clarity_alert = self.project.get_clarity_compliance_alert()
7878
has_clarity_issue = clarity_alert not in (None, "ok")
7979

8080
total_issues = count + (1 if has_clarity_issue else 0)
@@ -89,19 +89,11 @@ def check_compliance(self, fail_level):
8989
self.stderr.write(" " + "\n ".join(entries))
9090

9191
if has_clarity_issue:
92-
self.stderr.write("[License Clarity Compliance]")
92+
self.stderr.write("[License Clarity]")
9393
self.stderr.write(f" > Alert Level: {clarity_alert}")
9494

9595
return total_issues > 0
9696

97-
def get_clarity_compliance_alert(self):
98-
"""
99-
Return the clarity compliance alert value for the project,
100-
or None if not set.
101-
"""
102-
extra_data = self.project.extra_data or {}
103-
return extra_data.get("clarity_compliance_alert")
104-
10597
def check_vulnerabilities(self):
10698
packages = self.project.discoveredpackages.vulnerable_ordered()
10799
dependencies = self.project.discovereddependencies.vulnerable_ordered()

scanpipe/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,14 @@ def get_policies_dict(self):
15141514

15151515
return scanpipe_app.policies
15161516

1517+
def get_clarity_compliance_alert(self):
1518+
"""
1519+
Return the clarity compliance alert value for the project,
1520+
or None if not set.
1521+
"""
1522+
extra_data = self.extra_data or {}
1523+
return extra_data.get("clarity_compliance_alert")
1524+
15171525
def get_license_policy_index(self):
15181526
"""Return the policy license index for this project instance."""
15191527
if policies_dict := self.get_policies_dict():

scanpipe/pipes/license_clarity.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
from pathlib import Path
4343

44-
from django.conf import settings
4544
from django.core.exceptions import ValidationError
4645

4746
import saneyaml
@@ -168,23 +167,18 @@ def load_clarity_thresholds_from_file(file_path):
168167

169168
def get_project_clarity_thresholds(project):
170169
"""
171-
Get clarity thresholds for a project, checking multiple sources.
170+
Get clarity thresholds for a project using the unified policy loading logic.
172171
173172
Returns:
174173
ClarityThresholdsPolicy or None: Policy object if thresholds are configured
175174
176175
"""
177-
if hasattr(project, "get_input_policies_file"):
178-
policies_file = project.get_input_policies_file()
179-
if policies_file:
180-
policy = load_clarity_thresholds_from_file(policies_file)
181-
if policy:
182-
return policy
183-
184-
global_policies_file = getattr(settings, "SCANCODEIO_POLICIES_FILE", None)
185-
if global_policies_file:
186-
policy = load_clarity_thresholds_from_file(global_policies_file)
187-
if policy:
188-
return policy
189-
190-
return None
176+
policies_dict = project.get_policies_dict()
177+
if not policies_dict:
178+
return None
179+
180+
clarity_thresholds = policies_dict.get("license_clarity_thresholds")
181+
if not clarity_thresholds:
182+
return None
183+
184+
return ClarityThresholdsPolicy(clarity_thresholds)

scanpipe/pipes/scancode.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,5 @@ def make_results_summary(project, scan_results_location):
975975
alert = clarity_policy.get_alert_for_score(clarity_score)
976976
summary["clarity_compliance_alert"] = alert
977977

978-
extra_data = project.extra_data or {}
979-
extra_data["clarity_compliance_alert"] = alert
980-
project.extra_data = extra_data
981-
project.save(update_fields=["extra_data"])
982-
978+
project.update_extra_data({"clarity_compliance_alert": alert})
983979
return summary

scanpipe/tests/test_commands.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,7 @@ def test_scanpipe_management_command_check_clarity_compliance_only(self):
12261226
self.assertEqual(cm.exception.code, 1)
12271227
out_value = out.getvalue().strip()
12281228
expected = (
1229-
"1 compliance issues detected."
1230-
"\n[License Clarity Compliance]\n > Alert Level: error"
1229+
"1 compliance issues detected.\n[License Clarity]\n > Alert Level: error"
12311230
)
12321231
self.assertEqual(expected, out_value)
12331232

@@ -1251,7 +1250,7 @@ def test_scanpipe_management_command_check_both_compliance_and_clarity(self):
12511250
expected = (
12521251
"2 compliance issues detected."
12531252
"\n[packages]\n > ERROR: 1"
1254-
"\n[License Clarity Compliance]\n > Alert Level: warning"
1253+
"\n[License Clarity]\n > Alert Level: warning"
12551254
)
12561255
self.assertEqual(expected, out_value)
12571256

0 commit comments

Comments
 (0)