-
-
Notifications
You must be signed in to change notification settings - Fork 203
Restructure pipelines for verbosity #1074
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
079d9e1
Restructure pipelines for verbosity
AyanSinhaMahapatra 930b66c
Refactor functions and improve docstrings
AyanSinhaMahapatra 03c21a8
Add unittests for new functions
AyanSinhaMahapatra b9da877
Update docs and add CHANGELOG entry
AyanSinhaMahapatra d92df4d
Improve docstrings for pipelines
AyanSinhaMahapatra 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Generated by Django 5.0.1 on 2024-02-09 15:05 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| pipeline_old_names_mapping = { | ||
| "scan_codebase_packages": "inspect_packages", | ||
| } | ||
|
|
||
|
|
||
| def rename_pipelines_data(apps, schema_editor): | ||
| Run = apps.get_model("scanpipe", "Run") | ||
| for old_name, new_name in pipeline_old_names_mapping.items(): | ||
| Run.objects.filter(pipeline_name=old_name).update(pipeline_name=new_name) | ||
|
|
||
|
|
||
| def reverse_rename_pipelines_data(apps, schema_editor): | ||
| Run = apps.get_model("scanpipe", "Run") | ||
| for old_name, new_name in pipeline_old_names_mapping.items(): | ||
| Run.objects.filter(pipeline_name=new_name).update(pipeline_name=old_name) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("scanpipe", "0052_run_selected_groups"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| rename_pipelines_data, | ||
| reverse_code=reverse_rename_pipelines_data, | ||
| ), | ||
| ] |
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,78 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # http://nexb.com and https://github.com/nexB/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/nexB/scancode.io for support and download. | ||
|
|
||
| from scanpipe.pipelines.scan_codebase import ScanCodebase | ||
| from scanpipe.pipes import resolve | ||
| from scanpipe.pipes import update_or_create_package | ||
|
|
||
|
|
||
| class LoadSBOM(ScanCodebase): | ||
| """ | ||
| Inspect a codebase for SBOMs and gets all associated packages. | ||
|
|
||
| Supported BOMs: | ||
| - SPDX document | ||
| - CycloneDX BOM | ||
| - AboutCode ABOUT file | ||
| """ | ||
|
|
||
| @classmethod | ||
| def steps(cls): | ||
| return ( | ||
| cls.copy_inputs_to_codebase_directory, | ||
| cls.extract_archives, | ||
| cls.collect_and_create_codebase_resources, | ||
| cls.flag_empty_files, | ||
| cls.flag_ignored_resources, | ||
| cls.get_sbom_inputs, | ||
| cls.get_packages_from_sboms, | ||
| ) | ||
|
|
||
| def get_sbom_inputs(self): | ||
| """Locate all the SBOMs from the project's input/ directory.""" | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| self.manifest_resources = resolve.get_manifest_resources(self.project) | ||
|
|
||
| def get_packages_from_sboms(self): | ||
| """Get packages data from manifest files.""" | ||
| self.resolved_packages = [] | ||
|
|
||
| if not self.manifest_resources.exists(): | ||
| self.project.add_warning( | ||
| description="No SBOMs found for resolving packages", | ||
| model="get_packages_from_sboms", | ||
| ) | ||
| return | ||
|
|
||
| for resource in self.manifest_resources: | ||
| if packages := resolve.resolve_packages( | ||
| input_location=resource.location, | ||
| package_registry=resolve.sbom_registry, | ||
| ): | ||
| for package_data in packages: | ||
| package_data = resolve.set_license_expression(package_data) | ||
| update_or_create_package(self.project, package_data) | ||
| else: | ||
| self.project.add_error( | ||
| description="No packages could be resolved for SBOM", | ||
| model="get_packages_from_sboms", | ||
| details={"path": resource.path}, | ||
| ) | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
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,88 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # http://nexb.com and https://github.com/nexB/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/nexB/scancode.io for support and download. | ||
|
|
||
| from scanpipe.pipelines.scan_codebase import ScanCodebase | ||
| from scanpipe.pipes import resolve | ||
| from scanpipe.pipes import update_or_create_package | ||
|
|
||
|
|
||
| class ResolveDependencies(ScanCodebase): | ||
| """ | ||
| Inspect a codebase manifest files and resolve their associated packages. | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
|
|
||
| Supports resolved packages for: | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| - Python: using nexB/python-inspector, supports requirements.txt and | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| setup.py manifests as input | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| """ | ||
|
|
||
| @classmethod | ||
| def steps(cls): | ||
| return ( | ||
| cls.copy_inputs_to_codebase_directory, | ||
| cls.extract_archives, | ||
| cls.collect_and_create_codebase_resources, | ||
| cls.flag_ignored_resources, | ||
| cls.get_manifest_inputs, | ||
| cls.get_packages_from_manifest, | ||
| cls.create_resolved_packages, | ||
| ) | ||
|
|
||
| def get_manifest_inputs(self): | ||
| """Locate all the manifest files from the project's input/ directory.""" | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| self.manifest_resources = resolve.get_manifest_resources(self.project) | ||
|
|
||
| def get_packages_from_manifest(self): | ||
| """Get packages data from manifest files.""" | ||
| self.resolved_packages = [] | ||
|
|
||
| if not self.manifest_resources.exists(): | ||
| self.project.add_warning( | ||
| description="No manifests found for resolving packages", | ||
| model="get_packages_from_manifest", | ||
| ) | ||
| return | ||
|
|
||
| for resource in self.manifest_resources: | ||
| if packages := resolve.resolve_packages( | ||
| input_location=resource.location, | ||
| package_registry=resolve.resolver_registry, | ||
| ): | ||
| self.resolved_packages.extend(packages) | ||
| else: | ||
| self.project.add_error( | ||
| description="No packages could be resolved for", | ||
| model="get_packages_from_manifest", | ||
| details={"path": resource.path}, | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| def create_resolved_packages(self): | ||
| """Create the resolved packages and their dependencies in the database.""" | ||
| for package_data in self.resolved_packages: | ||
| package_data = resolve.set_license_expression(package_data) | ||
| dependencies = package_data.pop("dependencies", []) | ||
| update_or_create_package(self.project, package_data) | ||
|
|
||
| for dependency_data in dependencies: | ||
| resolved_package = dependency_data.get("resolved_package") | ||
| if resolved_package: | ||
| resolved_package.pop("dependencies", []) | ||
| update_or_create_package(self.project, resolved_package) | ||
|
AyanSinhaMahapatra marked this conversation as resolved.
Outdated
|
||
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.