Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cycode/cli/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
CYCODE_CLI_REQUEST_TIMEOUT_ENV_VAR_NAME = 'CYCODE_CLI_REQUEST_TIMEOUT'
LOGGING_LEVEL_ENV_VAR_NAME = 'LOGGING_LEVEL'
VERBOSE_ENV_VAR_NAME = 'CYCODE_CLI_VERBOSE'
DEBUG_ENV_VAR_NAME = 'CYCODE_CLI_DEBUG'

CYCODE_CONFIGURATION_DIRECTORY: str = '.cycode'

Expand Down
12 changes: 11 additions & 1 deletion cycode/cli/files_collector/models/in_memory_zip.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from io import BytesIO
from sys import getsizeof
from typing import Optional
from typing import TYPE_CHECKING, Optional
from zipfile import ZIP_DEFLATED, ZipFile

from cycode.cli.user_settings.configuration_manager import ConfigurationManager
from cycode.cli.utils.path_utils import concat_unique_id

if TYPE_CHECKING:
from pathlib import Path


class InMemoryZip(object):
def __init__(self) -> None:
self.configuration_manager = ConfigurationManager()

# Create the in-memory file-like object
self.in_memory_zip = BytesIO()
self.zip = ZipFile(self.in_memory_zip, 'a', ZIP_DEFLATED, False)
Expand All @@ -27,6 +33,10 @@ def read(self) -> bytes:
self.in_memory_zip.seek(0)
return self.in_memory_zip.read()

def write_on_disk(self, path: 'Path') -> None:
with open(path, 'wb') as f:
f.write(self.read())

@property
def size(self) -> int:
return getsizeof(self.in_memory_zip)
6 changes: 6 additions & 0 deletions cycode/cli/files_collector/zip_documents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from pathlib import Path
from typing import List, Optional

from cycode.cli import consts
Expand Down Expand Up @@ -37,4 +38,9 @@ def zip_documents(scan_type: str, documents: List[Document], zip_file: Optional[
zip_creation_time = int(end_zip_creation_time - start_zip_creation_time)
logger.debug('finished to create zip file, %s', {'zip_creation_time': zip_creation_time})

if zip_file.configuration_manager.get_debug_flag():
zip_file_path = Path.joinpath(Path.cwd(), f'{scan_type}_scan_{end_zip_creation_time}.zip')
logger.debug('writing zip file to disk, %s', {'zip_file_path': zip_file_path})
zip_file.write_on_disk(zip_file_path)

return zip_file
7 changes: 7 additions & 0 deletions cycode/cli/user_settings/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def get_cycode_app_url(self) -> str:

return consts.DEFAULT_CYCODE_APP_URL

def get_debug_flag_from_environment_variables(self) -> bool:
value = self._get_value_from_environment_variables(consts.DEBUG_ENV_VAR_NAME, '')
return value.lower() in {'true', '1'}

def get_debug_flag(self) -> bool:
return self.get_debug_flag_from_environment_variables()

def get_verbose_flag(self) -> bool:
verbose_flag_env_var = self.get_verbose_flag_from_environment_variables()
verbose_flag_local_config = self.local_config_file_manager.get_verbose_flag()
Expand Down