-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from OWASP/dev
Dev RELEASE: v0.17.1
- Loading branch information
Showing
10 changed files
with
399 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
############################ | ||
# Builder Stage | ||
############################ | ||
# use chainguard hardened images with SBOM | ||
FROM cgr.dev/chainguard/wolfi-base as builder | ||
|
||
WORKDIR /offat | ||
|
||
ARG version=3.12 | ||
|
||
ENV LANG=C.UTF-8 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PATH="/offat/.venv/bin:$PATH" | ||
|
||
|
||
RUN apk add python-${version} py${version}-pip && \ | ||
chown -R nonroot.nonroot /offat | ||
|
||
# install poetry and copy lock file | ||
RUN python -m pip install poetry | ||
COPY pyproject.toml poetry.lock README.md ./ | ||
COPY offat ./offat | ||
|
||
# poetry config | ||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install -E api --without dev | ||
|
||
############################ | ||
# runtime stage | ||
############################ | ||
FROM cgr.dev/chainguard/wolfi-base as runtime | ||
|
||
WORKDIR /offat | ||
|
||
ARG version=3.12 | ||
|
||
ENV LANG=C.UTF-8 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PATH="/offat/.venv/bin:$PATH" | ||
ENV VIRTUAL_ENV=/offat/.venv | ||
|
||
RUN apk add python-${version} py${version}-pip && \ | ||
chown -R nonroot.nonroot /offat | ||
|
||
|
||
# copy venv from builder image | ||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
|
||
# copy necessary files | ||
COPY offat ./offat | ||
COPY README.md CODE_OF_CONDUCT.md DISCLAIMER.md pyproject.toml . | ||
|
||
USER nonroot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
build-local-images: | ||
build-slim-local-images: | ||
@docker build -f DockerFiles/base-Dockerfile -t dmdhrumilmistry/offat-base . | ||
@docker build -f DockerFiles/cli-Dockerfile -t dmdhrumilmistry/offat . | ||
# @docker build -f DockerFiles/main/cli-Dockerfile -t dmdhrumilmistry/offat . | ||
|
||
build-local-image: | ||
@docker build -f DockerFiles/wolfi-base-Dockerfile -t dmdhrumilmistry/offat-base . --no-cache --progress=plain | ||
|
||
scan-vulns: | ||
@trivy image dmdhrumilmistry/offat-base --scanners vuln | ||
|
||
local: build-local-image scan-vulns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" | ||
OWASP OFFAT summarizer class module | ||
""" | ||
from rich.table import Table, Column | ||
|
||
|
||
class ResultSummarizer: | ||
"""class for summarizing results""" | ||
|
||
@staticmethod | ||
def get_counts(results: list[dict], filter_errors: bool = False) -> dict[str, int]: | ||
""" | ||
Processes results and returns test summary of errored, succeeded, failed | ||
and data leak endpoint results count. | ||
Args: | ||
results (list): OFFAT results list of dict | ||
filter_errors (bool): filters errored results before processing count | ||
if True. Default value: False | ||
Returns: | ||
dict: name (str) as key and its associated count (int) | ||
""" | ||
if filter_errors: | ||
results = list(filter(lambda result: result.get('error', False), results)) | ||
|
||
error_count = 0 | ||
data_leak_count = 0 | ||
failed_count = 0 | ||
success_count = 0 | ||
for result in results: | ||
error_count += 1 if result.get('error', False) else 0 | ||
data_leak_count += 1 if result.get('data_leak', False) else 0 | ||
|
||
if result.get('result'): | ||
success_count += 1 | ||
else: | ||
failed_count += 1 | ||
|
||
count_dict = { | ||
'errors': error_count, | ||
'data_leaks': data_leak_count, | ||
'failed': failed_count, | ||
'success': success_count, | ||
} | ||
|
||
return count_dict | ||
|
||
@staticmethod | ||
def generate_count_summary( | ||
results: list[dict], | ||
filter_errors: bool = False, | ||
output_format: str = 'table', | ||
table_title: str | None = None, | ||
) -> Table | str: | ||
""" | ||
Processes results and returns test summary of errored, succeeded, failed | ||
and data leak endpoint results count. | ||
Args: | ||
results (list): OFFAT results list of dict | ||
filter_errors (bool): filters errored results before processing count | ||
if True. Default value: False | ||
output_format (str): expected output format (table, markdown) | ||
Returns: | ||
rich.Table | str : returns summary in expected format | ||
""" | ||
count_summary = ResultSummarizer.get_counts( | ||
results=results, filter_errors=filter_errors | ||
) | ||
match output_format: | ||
case 'markdown': | ||
output = '' | ||
if table_title: | ||
output += f'**{table_title}**\n' | ||
|
||
for key, count in count_summary.items(): | ||
output += f'{key:<15}:\t{count}\n' | ||
|
||
case _: # table format | ||
output = Table( | ||
Column(header='⚔️', overflow='fold', justify='center'), | ||
Column(header='Endpoints Count', overflow='fold'), | ||
title=table_title, | ||
) | ||
|
||
for key, count in count_summary.items(): | ||
output.add_row(*[key, str(count)]) | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.