Skip to content

Commit

Permalink
feat: #comment updated version string resolution, single source of tr…
Browse files Browse the repository at this point in the history
…uth is now in pyproject.toml, set default ASH_OUTPUT_FORMAT value
  • Loading branch information
scrthq committed Jun 24, 2024
1 parent 6cfd934 commit 559dc32
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 18 deletions.
1 change: 0 additions & 1 deletion __version__

This file was deleted.

4 changes: 2 additions & 2 deletions ash-multi
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ run_security_check() {

set -e
START_TIME=$(date +%s)
VERSION=$(cat "$(dirname "${BASH_SOURCE[0]}")"/"__version__")
VERSION=v$(cat "$(dirname "${BASH_SOURCE[0]}")"/"pyproject.toml" | sed -n 's/^version = "\(.*\)"$/\1/p' | head -n 1)
OCI_RUNNER="docker"

# Overrides default OCI Runner used by ASH
Expand Down Expand Up @@ -618,7 +618,7 @@ then
RESOLVED_OUTPUT_DIR=${ACTUAL_OUTPUT_DIR:-${OUTPUT_DIR}}
echo -e "${GREEN}\nYour final report can be found here:${NC} ${RESOLVED_OUTPUT_DIR}/${AGGREGATED_RESULTS_REPORT_FILENAME}"

if [[ "${ASH_OUTPUT_FORMAT}" != "text" ]]; then
if [[ "${ASH_OUTPUT_FORMAT:-text}" != "text" ]]; then
echo -e "${GREEN}Converting${NC} ${RESOLVED_OUTPUT_DIR}/${AGGREGATED_RESULTS_REPORT_FILENAME}${GREEN} to ASHARP JSON model${NC}"
asharp --input "${RESOLVED_OUTPUT_DIR}/${AGGREGATED_RESULTS_REPORT_FILENAME}" --output "${RESOLVED_OUTPUT_DIR}/${AGGREGATED_RESULTS_REPORT_FILENAME}.json"
fi
Expand Down
Empty file removed asharp/adapters/__init__.py
Empty file.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
[tool.poetry]
name = "asharp"
version = "0.1.0"
name = "automated-security-helper"
version = "1.4.0"
description = ""
authors = ["Nate Ferrell <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/awslabs/automated-security-helper"

[tool.poetry.scripts]
asharp = 'asharp.asharp:main'
asharp = 'automated_security_helper.asharp:main'

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
9 changes: 9 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# src/automated_security_helper

This directory contains the Python package code for the automated_security_helper package.

This package provides some Python-based functions for ASH and is intended to be the project
location for any new Python development for ASH.

This package uses Poetry to manage dependencies and packaging. To read more about Poetry,
please see the [Poetry documentation](https://python-poetry.org/docs/).
6 changes: 6 additions & 0 deletions src/automated_security_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import importlib.metadata

__version__ = importlib.metadata.version('automated_security_helper')
File renamed without changes.
6 changes: 2 additions & 4 deletions asharp/asharp.py → src/automated_security_helper/asharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
# asharp.py / Automated Security Helper - Aggregated Report Parser
# A tool to parse, ingest, and output ASH aggregated reports.

version = 'asharp.py/0.1.0'

import datetime
import regex as re
import argparse
import json
from json import JSONEncoder
#import jq
from automated_security_helper import __version__

# default filenames for input and output
DEF_INFILE='aggregated_results.txt'
Expand All @@ -31,7 +29,7 @@

# simply output version and exit
if args.version:
print(version)
print(__version__)
exit(0)

# data parsing/collection from ASH aggregated report
Expand Down
2 changes: 2 additions & 0 deletions src/automated_security_helper/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
18 changes: 18 additions & 0 deletions src/automated_security_helper/models/asharp_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from pydantic import BaseModel, Field
from typing import Literal, Optional, List, Dict, Any, Union


class ASHARPModel(BaseModel):

def to_json_schema(
self,
format: Literal["dict", "str"] = "dict",
*args,
**kwargs,
) -> Dict[str, Any] | str:
if format == "dict":
return self.model_dump(*args, **kwargs)
return self.model_dump_json(*args, **kwargs)
4 changes: 2 additions & 2 deletions utils/grype-docker-execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ scan_paths=("${_ASH_SOURCE_DIR}" "${_ASH_OUTPUT_DIR}/work")
GRYPE_ARGS="-f medium --exclude=**/*-converted.py --exclude=**/*_report_result.txt"
SYFT_ARGS="--exclude=**/*-converted.py --exclude=**/*_report_result.txt"
SEMGREP_ARGS="--legacy --error --config=auto --exclude=\"*-converted.py,*_report_result.txt\""
debug_echo "[grype] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT}'"
if [[ "${ASH_OUTPUT_FORMAT}" != "text" ]]; then
debug_echo "[grype] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT:-text}'"
if [[ "${ASH_OUTPUT_FORMAT:-text}" != "text" ]]; then
debug_echo "[grype] Output format is not 'text', setting output format options to JSON to enable easy translation into desired output format"
GRYPE_ARGS="-o json ${GRYPE_ARGS}"
SYFT_ARGS="-o json ${SYFT_ARGS}"
Expand Down
4 changes: 2 additions & 2 deletions utils/js-docker-execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ touch ${REPORT_PATH}
scan_paths=("${_ASH_SOURCE_DIR}" "${_ASH_OUTPUT_DIR}/work")

AUDIT_ARGS=""
debug_echo "[js] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT}'"
if [[ "${ASH_OUTPUT_FORMAT}" != "text" ]]; then
debug_echo "[js] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT:-text}'"
if [[ "${ASH_OUTPUT_FORMAT:-text}" != "text" ]]; then
debug_echo "[js] Output format is not 'text', setting output format options to JSON to enable easy translation into desired output format"
AUDIT_ARGS="--json ${AUDIT_ARGS}"
fi
Expand Down
4 changes: 2 additions & 2 deletions utils/py-docker-execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ echo "<<<<<< end identifyipynb output for Jupyter notebook conversion <<<<<<" >>
scan_paths=("${_ASH_SOURCE_DIR}" "${_ASH_OUTPUT_DIR}/work")

BANDIT_ARGS="--exclude=\"*venv/*\" --severity-level=all"
debug_echo "[py] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT}'"
if [[ "${ASH_OUTPUT_FORMAT}" != "text" ]]; then
debug_echo "[py] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT:-text}'"
if [[ "${ASH_OUTPUT_FORMAT:-text}" != "text" ]]; then
debug_echo "[py] Output format is not 'text', setting output format options to JSON to enable easy translation into desired output format"
BANDIT_ARGS="-f json ${BANDIT_ARGS}"
fi
Expand Down
4 changes: 2 additions & 2 deletions utils/yaml-docker-execute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ scan_paths=("${_ASH_SOURCE_DIR}" "${_ASH_OUTPUT_DIR}/work")

CHECKOV_ARGS=""
CFNNAG_ARGS="--print-suppression --rule-directory ${_ASH_CFNRULES_LOCATION}"
debug_echo "[yaml] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT}'"
if [[ "${ASH_OUTPUT_FORMAT}" != "text" ]]; then
debug_echo "[yaml] ASH_OUTPUT_FORMAT: '${ASH_OUTPUT_FORMAT:-text}'"
if [[ "${ASH_OUTPUT_FORMAT:-text}" != "text" ]]; then
debug_echo "[yaml] Output format is not 'text', setting output format options to JSON to enable easy translation into desired output format"
CHECKOV_ARGS="--output=json"
CFNNAG_ARGS="--output-format json ${CFNNAG_ARGS}"
Expand Down

0 comments on commit 559dc32

Please sign in to comment.