Skip to content

Commit 90d4ccc

Browse files
authored
Doug/fix gitlab issues (#7)
* Added support to pull information from the .git folder * Fixed the logic for detecting changed manifest files * Updating requests version * Added pip lock file * New version for build * Updated required dependencies and CLI version * Updated build script and added fix for detached branch * Moved start message to earlier * Add case to handle detached head for gitlab * Update version for build * Updated build script to bypass building pypi artifacts on demand
1 parent bdb6953 commit 90d4ccc

File tree

14 files changed

+464
-231
lines changed

14 files changed

+464
-231
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM python:3-alpine
22
LABEL org.opencontainers.image.authors="socket.dev"
3-
3+
ARG CLI_VERSION
44
RUN apk update \
55
&& apk add --no-cache git nodejs npm yarn
6-
RUN pip install socketsecurity --upgrade
6+
RUN pip install socketsecurity --upgrade \
7+
&& socketcli -v \
8+
&& socketcli -v | grep -q $CLI_VERSION

Pipfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
requests = ">=2.32.0"
8+
mdutils = "~=1.6.0"
9+
prettytable = "*"
10+
argparse = "*"
11+
gitpython = "*"
12+
13+
[dev-packages]
14+
15+
[requires]
16+
python_version = "3.12"

Pipfile.lock

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

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

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
requests~=2.31.0
1+
requests>=2.32.0
22
mdutils~=1.6.0
33
prettytable
4-
argparse
4+
argparse
5+
gitpython>=3.1.43

scripts/build_container.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
3+
BYPASS_PYPI_BUILD=$1
4+
echo $VERSION
5+
6+
if [ -z $BYPASS_PYPI_BUILD ] || [ $BYPASS_PYPI_BUILD -eq 0 ]; then
7+
python -m build --wheel --sdist
8+
twine upload dist/*$VERSION*
9+
sleep 180
10+
fi
11+
docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:$VERSION . \
12+
&& docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:latest . \
13+
&& docker push socketdev/cli:$VERSION \
14+
&& docker push socketdev/cli:latest

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__ = '0.0.80'
2+
__version__ = '0.0.86'

socketsecurity/core/__init__.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
import platform
2424
from glob import glob
25+
import fnmatch
2526
import time
2627

2728
__all__ = [
@@ -306,25 +307,15 @@ def create_sbom_output(diff: Diff) -> list:
306307
return sbom
307308

308309
@staticmethod
309-
def find_files(path: str) -> list:
310+
def find_files(path: str, new_files: list = None) -> list:
310311
"""
311312
Globs the path for supported manifest files.
312313
Note: Might move the source to a JSON file
313314
:param path: Str - path to where the manifest files are located
315+
:param new_files:
314316
:return:
315317
"""
316318
socket_globs = {
317-
"general": {
318-
"readme": {
319-
"pattern": "*readme*"
320-
},
321-
"notice": {
322-
"pattern": "*notice*"
323-
},
324-
"license": {
325-
"pattern": "{licen{s,c}e{,-*},copying}"
326-
}
327-
},
328319
"npm": {
329320
"package.json": {
330321
"pattern": "package.json"
@@ -399,6 +390,12 @@ def find_files(path: str) -> list:
399390
file_path = f"{path}/**/{pattern}"
400391
files = glob(file_path, recursive=True)
401392
for file in files:
393+
if "/" in file:
394+
_, base_name = file.rsplit("/", 1)
395+
else:
396+
base_name = file
397+
if new_files is not None and base_name not in new_files:
398+
continue
402399
if platform.system() == "Windows":
403400
file = file.replace("\\", "/")
404401
found_path, file_name = file.rsplit("/", 1)
@@ -478,7 +475,7 @@ def get_full_scan(full_scan_id: str) -> FullScan:
478475
return full_scan
479476

480477
@staticmethod
481-
def create_new_diff(path: str, params: FullScanParams, workspace: str) -> Diff:
478+
def create_new_diff(path: str, params: FullScanParams, workspace: str, new_files: list = None) -> Diff:
482479
"""
483480
1. Get the head full scan. If it isn't present because this repo doesn't exist yet return an Empty full scan.
484481
2. Create a new Full scan for the current run
@@ -487,9 +484,10 @@ def create_new_diff(path: str, params: FullScanParams, workspace: str) -> Diff:
487484
:param path: Str - path of where to look for manifest files for the new Full Scan
488485
:param params: FullScanParams - Query params for the Full Scan endpoint
489486
:param workspace: str - Path for workspace
487+
:param new_files:
490488
:return:
491489
"""
492-
files = Core.find_files(path)
490+
files = Core.find_files(path, new_files)
493491
try:
494492
head_full_scan_id = Core.get_head_scan_for_repo(params.repo)
495493
if head_full_scan_id is None or head_full_scan_id == "":

socketsecurity/core/classes.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Repository",
1414
"Diff",
1515
"Purl",
16-
"GithubComment"
16+
"Comment"
1717
]
1818

1919

@@ -423,3 +423,17 @@ def __init__(self, **kwargs):
423423
def __str__(self):
424424
return json.dumps(self.__dict__)
425425

426+
class Comment:
427+
id: int
428+
body: str
429+
body_list: list
430+
431+
def __init__(self, **kwargs):
432+
if kwargs:
433+
for key, value in kwargs.items():
434+
setattr(self, key, value)
435+
if not hasattr(self, "body_list"):
436+
self.body_list = []
437+
438+
def __str__(self):
439+
return json.dumps(self.__dict__)

0 commit comments

Comments
 (0)