Skip to content

Commit c32a6a9

Browse files
authored
Doug/fix trivy socket results (#2)
* Fixed build process and changed naming convention to work with uv * Extensive updates to all components for improved functionality
1 parent 4a2985a commit c32a6a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+10782
-3825
lines changed

.gitmodules

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[submodule "app_tests/NodeGoat"]
2+
path = app_tests/NodeGoat
3+
url = https://github.com/OWASP/NodeGoat.git
4+
[submodule "app_tests/DVWA"]
5+
path = app_tests/DVWA
6+
url = https://github.com/digininja/DVWA.git
7+
[submodule "app_tests/WebGoat"]
8+
path = app_tests/WebGoat
9+
url = https://github.com/WebGoat/WebGoat.git
10+
[submodule "app_tests/juice-shop"]
11+
path = app_tests/juice-shop
12+
url = https://github.com/juice-shop/juice-shop.git
13+
[submodule "app_tests/railsgoat"]
14+
path = app_tests/railsgoat
15+
url = https://github.com/OWASP/railsgoat.git
16+
[submodule "app_tests/IWA-DotNet"]
17+
path = app_tests/IWA-DotNet
18+
url = https://github.com/fortify/IWA-DotNet.git
19+
[submodule "app_tests/pygoat"]
20+
path = app_tests/pygoat
21+
url = https://github.com/adeyosemanputra/pygoat.git
22+
[submodule "app_tests/DVIA-v2"]
23+
path = app_tests/DVIA-v2
24+
url = https://github.com/prateek147/DVIA-v2.git
25+
[submodule "app_tests/scala-woof"]
26+
path = app_tests/scala-woof
27+
url = https://github.com/snyk/scala-woof.git

.hooks/version-check.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
#!/usr/bin/env python3
2+
"""
3+
Version management script for Socket Basics.
4+
5+
This script:
6+
1. Ensures version.py and pyproject.toml are in sync
7+
2. Auto-bumps version on commits if unchanged
8+
3. Automatically updates version references in:
9+
- README.md (GitHub Action versions and Docker build tags)
10+
- docs/github-action.md (all action version references)
11+
- docs/pre-commit-hook.md (Docker build tags)
12+
13+
Pattern matching:
14+
- GitHub Actions: SocketDev/[email protected] -> @vNEW_VERSION
15+
- Docker builds: docker build -t IMAGE_NAME -> docker build -t IMAGE_NAME:NEW_VERSION
16+
17+
Usage:
18+
- Normal commit: Will auto-bump patch version if unchanged
19+
- Dev mode: python3 .hooks/version-check.py --dev
20+
"""
221
import subprocess
322
import pathlib
423
import re
@@ -8,9 +27,18 @@
827

928
VERSION_FILE = pathlib.Path("socket_basics/version.py")
1029
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
30+
README_FILES = [
31+
pathlib.Path("README.md"),
32+
pathlib.Path("docs/github-action.md"),
33+
pathlib.Path("docs/pre-commit-hook.md"),
34+
]
1135

1236
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
1337
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*"([^"]+)"$', re.MULTILINE)
38+
# Pattern to match SocketDev/[email protected] or @vX.X.X
39+
ACTION_VERSION_PATTERN = re.compile(r'(SocketDev/socket-basics|socket-basics)@v\d+\.\d+\.\d+')
40+
# Pattern to match docker build with version tag
41+
DOCKER_BUILD_PATTERN = re.compile(r'docker build -t (socketdev/socket-basics|socket-basics)(?::\d+\.\d+\.\d+)?')
1442
# Update this URL to match your actual PyPI package if you publish it
1543
PYPI_API = "https://pypi.org/pypi/security-wrapper/json"
1644

@@ -71,6 +99,31 @@ def find_next_available_dev_version(base_version: str) -> str:
7199
print("❌ Could not find available .devN slot after 100 attempts.")
72100
sys.exit(1)
73101

102+
def update_readme_versions(version: str):
103+
"""Update version references in README files"""
104+
for readme_file in README_FILES:
105+
if not readme_file.exists():
106+
print(f"⚠️ {readme_file} not found, skipping")
107+
continue
108+
109+
content = readme_file.read_text()
110+
original_content = content
111+
112+
# Update action version references (SocketDev/[email protected])
113+
content = ACTION_VERSION_PATTERN.sub(rf'\1@v{version}', content)
114+
115+
# Update docker build commands to include version tag
116+
def docker_replacement(match):
117+
image_name = match.group(1)
118+
return f'docker build -t {image_name}:{version}'
119+
content = DOCKER_BUILD_PATTERN.sub(docker_replacement, content)
120+
121+
if content != original_content:
122+
readme_file.write_text(content)
123+
print(f"✅ Updated version references in {readme_file}")
124+
else:
125+
print(f"ℹ️ No version updates needed in {readme_file}")
126+
74127
def inject_version(version: str):
75128
print(f"🔁 Updating version to: {version}")
76129

@@ -85,6 +138,9 @@ def inject_version(version: str):
85138
print(f"✅ Updated {PYPROJECT_FILE}")
86139
else:
87140
print(f"⚠️ Could not find version field in {PYPROJECT_FILE}")
141+
142+
# Update README files with version references
143+
update_readme_versions(version)
88144

89145
def check_version_sync():
90146
"""Ensure version.py and pyproject.toml are in sync"""

Dockerfile

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,35 @@
22
FROM python:3.12
33

44
# Create application directory
5-
WORKDIR /socket-security-tools
5+
WORKDIR /socket-basics
66
ENV PATH=$PATH:/usr/local/go/bin
77

88
# Install uv
99
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1010

11-
# Install Trivy
12-
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.18.3
13-
14-
# Install Trufflehog
15-
RUN curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
16-
17-
11+
# Install system dependencies
1812
RUN apt-get update && apt-get install -y curl git wget
1913

2014
# Install Trivy
21-
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.18.3
15+
RUN curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.67.2
2216

2317
# Install Trufflehog
2418
RUN curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
2519

2620
# Install OpenGrep (connector/runtime dependency)
2721
RUN curl -fsSL https://raw.githubusercontent.com/opengrep/opengrep/main/install.sh | bash
2822

29-
# Copy socket_basics package so we can install the CLI entrypoint
30-
COPY socket_basics /socket-security-tools/socket_basics
31-
# Also copy the project root so editable install has access to all files
32-
COPY . /socket-security-tools/
33-
34-
COPY pyproject.toml uv.lock LICENSE README.md /scripts/
35-
# Install Python dependencies using uv
36-
WORKDIR /scripts
37-
RUN uv sync --frozen && uv pip install light-s3-client
38-
ENV PATH="/scripts/.venv/bin:/root/.opengrep/cli/latest:$PATH"
39-
40-
# Install this package so the `socket-basics` CLI entrypoint is available
41-
WORKDIR /socket-security-tools
42-
# Ensure python can import package if install doesn't run; prefer installed package
43-
ENV PYTHONPATH="/socket-security-tools:${PYTHONPATH}"
44-
# Ensure pyproject is present for editable install; fail loudly if install fails
45-
RUN uv pip install -e . || pip install -e .
23+
# Copy the specific files needed for the project
24+
COPY socket_basics /socket-basics/socket_basics
25+
COPY pyproject.toml /socket-basics/pyproject.toml
26+
COPY README.md /socket-basics/README.md
27+
COPY LICENSE /socket-basics/LICENSE
28+
COPY uv.lock /socket-basics/uv.lock
29+
30+
# Install Python dependencies using uv from the project root
31+
WORKDIR /socket-basics
32+
RUN pip install -e . && uv sync --frozen --no-dev
33+
ENV PATH="/socket-basics/.venv/bin:/root/.opengrep/cli/latest:$PATH"
4634

4735
# Use socket-basics as the default entrypoint
4836
ENTRYPOINT ["socket-basics"]

0 commit comments

Comments
 (0)