Skip to content

Commit 6d4e171

Browse files
authored
Doug/add debug find files (#17)
* Added debug logic to find files * Added more debug logging for find files * Changes to the find_files function to reduce memory usage
1 parent c926a55 commit 6d4e171

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ markdown_security_temp.md
1818
.DS_Store
1919
*.pyc
2020
test.py
21-
*.cpython-312.pyc
21+
*.cpython-312.pyc`
22+
file_generator.py

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ dependencies = [
1111
'mdutils',
1212
'prettytable',
1313
'argparse',
14-
'GitPython'
14+
'GitPython',
15+
'packaging'
1516
]
1617
readme = "README.md"
1718
description = "Socket Security CLI for CI/CD"

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ requests>=2.32.0
22
mdutils~=1.6.0
33
prettytable
44
argparse
5-
gitpython>=3.1.43
5+
gitpython>=3.1.43
6+
packaging>=24.1

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '1.0.7'
2+
__version__ = '1.0.15'

socketsecurity/core/__init__.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
all_new_alerts = False
4747
security_policy = {}
4848
log = logging.getLogger("socketdev")
49+
# log_format = "%(asctime)s %(funcName)20s() %(message)s"
50+
# logging.basicConfig(format=log_format)
4951
log.addHandler(logging.NullHandler())
5052

5153
socket_globs = {
@@ -396,29 +398,35 @@ def find_files(path: str, files: list = None) -> list:
396398
:param files: override finding the manifest files using the glob matcher
397399
:return:
398400
"""
399-
all_files = []
400401
files_provided = False
402+
log.debug("Starting Find Files")
403+
start_time = time.time()
401404
if files is not None and len(files) > 0:
402405
files_provided = True
403406
for ecosystem in socket_globs:
407+
if files is None:
408+
files = []
404409
patterns = socket_globs[ecosystem]
405410
for file_name in patterns:
406411
pattern = patterns[file_name]["pattern"]
407412
file_path = f"{path}/**/{pattern}"
413+
408414
if not files_provided:
409-
files = glob(file_path, recursive=True)
415+
log.debug(f"Globbing {file_path}")
416+
glob_start = time.time()
417+
test = glob(file_path, recursive=True)
418+
files = files + test
419+
glob_end = time.time()
420+
glob_total_time = glob_end - glob_start
421+
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
410422
else:
423+
log.debug("Files found from commit")
411424
files = Core.match_supported_files(path, files)
412-
for file in files:
413-
if platform.system() == "Windows":
414-
file = file.replace("\\", "/")
415-
if path not in file:
416-
file = f"{path}/{file}"
417-
found_path, file_name = file.rsplit("/", 1)
418-
details = (found_path, file_name)
419-
if details not in all_files:
420-
all_files.append(details)
421-
return all_files
425+
log.debug("Finished Find Files")
426+
end_time = time.time()
427+
total_time = end_time - start_time
428+
log.info(f"Found {len(files)} in {total_time:.2f} seconds")
429+
return files
422430

423431
@staticmethod
424432
def create_full_scan(files: list, params: FullScanParams, workspace: str) -> FullScan:
@@ -430,7 +438,16 @@ def create_full_scan(files: list, params: FullScanParams, workspace: str) -> Ful
430438
:return:
431439
"""
432440
send_files = []
433-
for path, name in files:
441+
create_full_start = time.time()
442+
log.debug("Creating new full scan")
443+
for file in files:
444+
if platform.system() == "Windows":
445+
file = file.replace("\\", "/")
446+
if "/" in file:
447+
path, name = file.rsplit("/", 1)
448+
else:
449+
path = "."
450+
name = file
434451
full_path = f"{path}/{name}"
435452
if full_path.startswith(workspace):
436453
key = full_path[len(workspace):]
@@ -452,6 +469,9 @@ def create_full_scan(files: list, params: FullScanParams, workspace: str) -> Ful
452469
results = response.json()
453470
full_scan = FullScan(**results)
454471
full_scan.sbom_artifacts = Core.get_sbom_data(full_scan.id)
472+
create_full_end = time.time()
473+
total_time = create_full_end - create_full_start
474+
log.debug(f"New Full Scan created in {total_time:.2f} seconds")
455475
return full_scan
456476

457477
@staticmethod

socketsecurity/socketcli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import argparse
22
import json
3+
4+
import socketsecurity.core
35
from socketsecurity.core import Core, __version__
46
from socketsecurity.core.classes import FullScanParams, Diff, Package, Issue
57
from socketsecurity.core.messages import Messages
@@ -10,7 +12,9 @@
1012
import sys
1113
import logging
1214

13-
logging.basicConfig(level=logging.INFO)
15+
log_format = "%(asctime)s: %(message)s"
16+
logging.basicConfig(level=logging.INFO, format=log_format)
17+
socketsecurity.core.log.setLevel(level=logging.INFO)
1418
log = logging.getLogger("socketcli")
1519
blocking_disabled = False
1620

@@ -211,7 +215,7 @@ def main_code():
211215
arguments = parser.parse_args()
212216
debug = arguments.enable_debug
213217
if debug:
214-
logging.basicConfig(level=logging.DEBUG)
218+
logging.basicConfig(level=logging.DEBUG, format=log_format)
215219
log.setLevel(logging.DEBUG)
216220
Core.enable_debug_log(logging.DEBUG)
217221
log.debug("Debug logging enabled")
@@ -287,7 +291,7 @@ def main_code():
287291
default_branch = scm.is_default_branch
288292

289293
base_api_url = os.getenv("BASE_API_URL") or None
290-
core = Core(token=api_token, request_timeout=6000, base_api_url=base_api_url)
294+
core = Core(token=api_token, request_timeout=1200, base_api_url=base_api_url)
291295
no_change = True
292296
if ignore_commit_files:
293297
no_change = False

0 commit comments

Comments
 (0)