-
Notifications
You must be signed in to change notification settings - Fork 55
CM-40909 - Implement Go restore support for SCA #256
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
MarshalX
merged 14 commits into
cycodehq:main
from
naftalicy:CM-40909-supports-go-restore
Oct 22, 2024
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
46365cb
CM-40907 supports restoring npm and refactoring process of generating…
naftalicy 0b720e4
CM-40907 fromatting
naftalicy a347a62
CM-40907 set secured shell command
naftalicy 277d783
CM-40907 fix
naftalicy 98bf549
CM-40907 fix
naftalicy f173e50
CM-40909 init
naftalicy 60e5777
CM-40909 add go restore
naftalicy 0f5b002
CM-40909 implement go restore
naftalicy dde8b9a
CM-40909 format
naftalicy c017636
Merge branch 'main' into CM-40909-supports-go-restore
naftalicy 51a4101
CM-40909 fix
naftalicy fadf6f9
CM-40909 fix
naftalicy ac5c73c
CM-40909 fix
naftalicy 3e96da8
Merge branch 'main' into CM-40909-supports-go-restore
naftalicy 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
Empty file.
31 changes: 31 additions & 0 deletions
31
cycode/cli/files_collector/sca/go/restore_go_dependencies.py
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,31 @@ | ||
| import os | ||
| from typing import List | ||
|
|
||
| import click | ||
|
|
||
| from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies | ||
| from cycode.cli.models import Document | ||
|
|
||
| GO_PROJECT_FILE_EXTENSIONS = ['.mod'] | ||
| GO_RESTORE_FILE_NAME = 'go.sum' | ||
| BUILD_GO_FILE_NAME = 'go.mod' | ||
|
|
||
|
|
||
| class RestoreGoDependencies(BaseRestoreDependencies): | ||
| def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None: | ||
| super().__init__(context, is_git_diff, command_timeout, True) | ||
|
|
||
| def is_project(self, document: Document) -> bool: | ||
| return any(document.path.endswith(ext) for ext in GO_PROJECT_FILE_EXTENSIONS) | ||
MarshalX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def get_command(self, manifest_file_path: str) -> List[str]: | ||
| return ['cd', self.prepare_tree_file_path_for_command(manifest_file_path), '&&', 'go', 'list', '-m', '-json'] | ||
MarshalX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def get_lock_file_name(self) -> str: | ||
| return GO_RESTORE_FILE_NAME | ||
|
|
||
| def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: | ||
| return os.path.isfile(restore_file_path) | ||
|
|
||
| def prepare_tree_file_path_for_command(self, manifest_file_path: str) -> str: | ||
| return manifest_file_path.replace('/' + BUILD_GO_FILE_NAME, '') | ||
MarshalX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
Empty file.
33 changes: 33 additions & 0 deletions
33
cycode/cli/files_collector/sca/npm/restore_npm_dependencies.py
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 @@ | ||
| import os | ||
| from typing import List | ||
|
|
||
| import click | ||
|
|
||
| from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies | ||
| from cycode.cli.models import Document | ||
|
|
||
| NPM_PROJECT_FILE_EXTENSIONS = ['.json'] | ||
| NPM_LOCK_FILE_NAME = 'package-lock.json' | ||
| NPM_MANIFEST_FILE_NAME = 'package.json' | ||
| OUTPUT_FILE_MANUALLY = False | ||
|
|
||
|
|
||
| class RestoreNpmDependencies(BaseRestoreDependencies): | ||
| def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None: | ||
| super().__init__(context, is_git_diff, command_timeout, OUTPUT_FILE_MANUALLY) | ||
|
|
||
| def is_project(self, document: Document) -> bool: | ||
| return any(document.path.endswith(ext) for ext in NPM_PROJECT_FILE_EXTENSIONS) | ||
|
|
||
| def get_command(self, manifest_file_path: str) -> List[str]: | ||
| return ['npm', 'install', '--prefix', self.prepare_manifest_file_path_for_command(manifest_file_path), | ||
| '--package-lock-only', '--ignore-scripts', '--no-audit'] | ||
|
|
||
| def get_lock_file_name(self) -> str: | ||
| return NPM_LOCK_FILE_NAME | ||
|
|
||
| def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: | ||
| return os.path.isfile(restore_file_path) | ||
|
|
||
| def prepare_manifest_file_path_for_command(self, manifest_file_path: str) -> str: | ||
| return '/' + manifest_file_path.strip('/' + NPM_MANIFEST_FILE_NAME) |
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
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.