Skip to content

Commit ae1c688

Browse files
committed
add documentation and support api endpoint for clarity compliance
Signed-off-by: NucleonGodX <racerpro41@gmail.com>
1 parent a102e00 commit ae1c688

4 files changed

Lines changed: 126 additions & 3 deletions

File tree

docs/policies.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,43 @@ structure similar to the following:
3838
- ``warning``
3939
- ``error``
4040

41+
Creating Clarity Thresholds Files
42+
---------------------------------
43+
44+
A valid clarity thresholds file is required to **enable clarity compliance features**.
45+
46+
The clarity thresholds file, by default named ``policies.yml``, is a **YAML file** with a
47+
structure similar to the following:
48+
49+
.. code-block:: yaml
50+
51+
license_clarity_thresholds:
52+
91: ok
53+
80: warning
54+
0: error
55+
56+
- In the example above, the keys ``91``, ``80``, and ``0`` are integer threshold values
57+
representing **minimum clarity scores**.
58+
- The values ``error``, ``warning``, and ``ok`` are the **compliance alert levels** that
59+
will be triggered if the project's license clarity score meets or exceeds the
60+
corresponding threshold.
61+
- The thresholds must be listed in **strictly descending order**.
62+
63+
How it works:
64+
65+
- If the clarity score is **91 or above**, the alert is **``ok``**.
66+
- If the clarity score is **80 to 90**, the alert is **``warning``**.
67+
- If the clarity score is **below 80**, the alert is **``error``**.
68+
69+
You can adjust the threshold values and alert levels to match your organization's
70+
compliance requirements.
71+
72+
Accepted values for the alert level:
73+
74+
- ``ok``
75+
- ``warning``
76+
- ``error``
77+
4178
App Policies
4279
------------
4380

@@ -99,7 +136,7 @@ REST API
99136
--------
100137

101138
For more details on retrieving compliance data through the REST API, see the
102-
:ref:`rest_api_compliance` section.
139+
:ref:`rest_api_compliance` section and :ref:`rest_api_clarity_compliance` section
103140

104141
Command Line Interface
105142
----------------------

docs/rest-api.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,29 @@ Data:
493493
}
494494
}
495495
496+
.. _rest_api_clarity_compliance:
497+
498+
Clarity Compliance
499+
^^^^^^^^^^^^^^^^^^
500+
501+
This action returns the **clarity compliance alert** for a project.
502+
503+
The clarity compliance alert is a single value (``ok``, ``warning``, or ``error``) that summarizes
504+
the project's **license clarity status**, based on the thresholds defined in the ``policies.yml`` file.
505+
506+
``GET /api/projects/6461408c-726c-4b70-aa7a-c9cc9d1c9685/clarity_compliance/``
507+
508+
Data:
509+
- ``clarity_compliance_alert``: The overall clarity compliance alert for the project.
510+
511+
Possible values: ``ok``, ``warning``, ``error``.
512+
513+
.. code-block:: json
514+
515+
{
516+
"clarity_compliance_alert": "warning"
517+
}
518+
496519
Reset
497520
^^^^^
498521

docs/tutorial_license_policies.rst

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,51 @@ detected license, and computed at the codebase resource level, for example:
8383
"[...]": "[...]"
8484
}
8585
86+
License Clarity Thresholds and Compliance
87+
-----------------------------------------
88+
89+
ScanCode.io also supports **license clarity thresholds**, allowing you to enforce
90+
minimum standards for license detection quality in your codebase. This is managed
91+
through the ``license_clarity_thresholds`` section in your ``policies.yml`` file.
92+
93+
Defining Clarity Thresholds
94+
---------------------------
95+
96+
Add a ``license_clarity_thresholds`` section to your ``policies.yml`` file, for example:
97+
98+
.. code-block:: yaml
99+
100+
license_clarity_thresholds:
101+
91: ok
102+
80: warning
103+
0: error
104+
105+
106+
Clarity Compliance in Results
107+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108+
109+
When you run a pipeline with clarity thresholds defined in your ``policies.yml``,
110+
the computed clarity compliance alert is included in the project's ``extra_data`` field.
111+
112+
For example:
113+
114+
.. code-block:: json
115+
116+
"extra_data": {
117+
"md5": "d23df4a4",
118+
"sha1": "3e9b61cc98c",
119+
"size": 3095,
120+
"sha256": "abacfc8bcee59067",
121+
"sha512": "208f6a83c83a4c770b3c0",
122+
"filename": "cuckoo_filter-1.0.6.tar.gz",
123+
"sha1_git": "3fdb0f82ad59",
124+
"clarity_compliance_alert": "error"
125+
}
126+
127+
The ``clarity_compliance_alert`` value (e.g., ``"error"``, ``"warning"``, or ``"ok"``)
128+
is computed automatically based on the thresholds you configured and reflects the
129+
overall license clarity status of the scanned codebase.
130+
86131
Run the ``check-compliance`` command
87132
------------------------------------
88133

@@ -95,7 +140,7 @@ in the project:
95140
96141
.. code-block:: bash
97142
98-
4 compliance issues detected on this project.
143+
5 compliance issues detected on this project.
99144
[packages]
100145
> ERROR: 3
101146
pkg:pypi/cuckoo-filter@.
@@ -104,7 +149,9 @@ in the project:
104149
[resources]
105150
> ERROR: 1
106151
cuckoo_filter-1.0.6.tar.gz-extract/cuckoo_filter-1.0.6/README.md
152+
[License Clarity Compliance]
153+
> Alert Level: error
107154
108155
.. tip::
109156
In case of compliance alerts, the command returns a non-zero exit code which
110-
may be useful to trigger a failure in an automated process.
157+
may be useful to trigger a failure in an automated process.

scanpipe/api/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,22 @@ def compliance(self, request, *args, **kwargs):
481481
compliance_alerts = get_project_compliance_alerts(project, fail_level)
482482
return Response({"compliance_alerts": compliance_alerts})
483483

484+
@action(detail=True, methods=["get"])
485+
def clarity_compliance(self, request, *args, **kwargs):
486+
"""
487+
Retrieve the clarity compliance alert for a project.
488+
489+
This endpoint returns the clarity compliance alert stored in the
490+
project's extra_data.
491+
492+
Example:
493+
GET /api/projects/{project_id}/clarity_compliance/
494+
495+
"""
496+
project = self.get_object()
497+
clarity_alert = (project.extra_data or {}).get("clarity_compliance_alert")
498+
return Response({"clarity_compliance_alert": clarity_alert})
499+
484500

485501
class RunViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
486502
"""Add actions to the Run viewset."""

0 commit comments

Comments
 (0)