-
-
Notifications
You must be signed in to change notification settings - Fork 127
Add compliance support based on OpenSSF Scorecard score #1800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a1ffa0
Add compliance_thresholds.py and related support files
NucleonGodX f88a57d
fix tests
NucleonGodX e63a9ab
integrate scorecard compliance
NucleonGodX c6b591b
fix tests
NucleonGodX efa0f4b
minor fix
NucleonGodX 5ab30e7
merge main
NucleonGodX 8c9dc8f
create a new pipe for compliancing
NucleonGodX dd1d7d5
fix code format
NucleonGodX 8b83b30
add documentation and changelog
NucleonGodX 7d7323f
add changelog
NucleonGodX 7d657fe
add test for integration of scorecard-compliance
NucleonGodX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -497,6 +497,22 @@ def license_clarity_compliance(self, request, *args, **kwargs): | |
| clarity_alert = project.get_license_clarity_compliance_alert() | ||
| return Response({"license_clarity_compliance_alert": clarity_alert}) | ||
|
|
||
| @action(detail=True, methods=["get"]) | ||
| def scorecard_compliance(self, request, *args, **kwargs): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a new entry in the REST API documentation, see |
||
| """ | ||
| Retrieve the scorecard compliance alert for a project. | ||
|
|
||
| This endpoint returns the scorecard compliance alert stored in the | ||
| project's extra_data. | ||
|
|
||
| Example: | ||
| GET /api/projects/{project_id}/scorecard_compliance/ | ||
|
|
||
| """ | ||
| project = self.get_object() | ||
| scorecard_alert = project.get_scorecard_compliance_alert() | ||
| return Response({"scorecard_compliance_alert": scorecard_alert}) | ||
|
|
||
|
|
||
| class RunViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet): | ||
| """Add actions to the Run viewset.""" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # http://nexb.com and https://github.com/aboutcode-org/scancode.io | ||
| # The ScanCode.io software is licensed under the Apache License version 2.0. | ||
| # Data generated with ScanCode.io is provided as-is without warranties. | ||
| # ScanCode is a trademark of nexB Inc. | ||
| # | ||
| # You may not use this software except in compliance with the License. | ||
| # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software distributed | ||
| # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
| # | ||
| # Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
| # OR CONDITIONS OF ANY KIND, either express or implied. No content created from | ||
| # ScanCode.io should be considered or used as legal advice. Consult an Attorney | ||
| # for any legal advice. | ||
| # | ||
| # ScanCode.io is a free software code scanning tool from nexB Inc. and others. | ||
| # Visit https://github.com/aboutcode-org/scancode.io for support and download. | ||
|
|
||
| from scanpipe.pipes.compliance_thresholds import get_project_scorecard_thresholds | ||
|
|
||
|
|
||
| def evaluate_scorecard_compliance(project): | ||
| """ | ||
| Evaluate scorecard compliance for all discovered packages in the project. | ||
|
|
||
| This function checks OpenSSF Scorecard scores against project-defined | ||
| thresholds and determines the worst compliance alert level across all packages. | ||
| Updates the project's extra_data with the overall compliance status. | ||
| """ | ||
| scorecard_policy = get_project_scorecard_thresholds(project) | ||
| if not scorecard_policy: | ||
| return | ||
|
|
||
| worst_alert = None | ||
| packages_with_scores = project.discoveredpackages.filter( | ||
| scores__scoring_tool="ossf-scorecard" | ||
| ).distinct() | ||
|
|
||
| for package in packages_with_scores: | ||
| latest_score = ( | ||
| package.scores.filter(scoring_tool="ossf-scorecard") | ||
| .order_by("-score_date") | ||
| .first() | ||
| ) | ||
|
|
||
| if not latest_score or latest_score.score is None: | ||
| continue | ||
|
|
||
| try: | ||
| score = float(latest_score.score) | ||
| alert = scorecard_policy.get_alert_for_score(score) | ||
| except Exception: | ||
| alert = "error" | ||
|
|
||
| order = {"ok": 0, "warning": 1, "error": 2} | ||
| if worst_alert is None or order[alert] > order.get(worst_alert, -1): | ||
| worst_alert = alert | ||
|
|
||
| if worst_alert is not None: | ||
| project.update_extra_data({"scorecard_compliance_alert": worst_alert}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be inside the v35.2.0 section since it is already released.