Skip to content

Commit 5906425

Browse files
authored
CM-40909 - Implement Go restore support for SCA (#256)
1 parent a4010a9 commit 5906425

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cycode/cli/files_collector/sca/go/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
from typing import List
3+
4+
import click
5+
6+
from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies
7+
from cycode.cli.models import Document
8+
9+
GO_PROJECT_FILE_EXTENSIONS = ['.mod']
10+
GO_RESTORE_FILE_NAME = 'go.sum'
11+
BUILD_GO_FILE_NAME = 'go.mod'
12+
13+
14+
class RestoreGoDependencies(BaseRestoreDependencies):
15+
def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None:
16+
super().__init__(context, is_git_diff, command_timeout, create_output_file_manually=True)
17+
18+
def is_project(self, document: Document) -> bool:
19+
return any(document.path.endswith(ext) for ext in GO_PROJECT_FILE_EXTENSIONS)
20+
21+
def get_command(self, manifest_file_path: str) -> List[str]:
22+
return ['cd', self.prepare_tree_file_path_for_command(manifest_file_path), '&&', 'go', 'list', '-m', '-json']
23+
24+
def get_lock_file_name(self) -> str:
25+
return GO_RESTORE_FILE_NAME
26+
27+
def verify_restore_file_already_exist(self, restore_file_path: str) -> bool:
28+
return os.path.isfile(restore_file_path)
29+
30+
def prepare_tree_file_path_for_command(self, manifest_file_path: str) -> str:
31+
return manifest_file_path.replace(os.sep + BUILD_GO_FILE_NAME, '')

0 commit comments

Comments
 (0)