diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index df8795d..facc8e3 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -51,4 +51,4 @@ jobs: poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY cat .lint.txt >> $GITHUB_STEP_SUMMARY - tbx security prettyprint markdown .security.json >> $GITHUB_STEP_SUMMARY + tbx security prettyprint --format markdown .security.json >> $GITHUB_STEP_SUMMARY diff --git a/exasol/toolbox/tools/security.py b/exasol/toolbox/tools/security.py index facc4a5..b5a8d0f 100644 --- a/exasol/toolbox/tools/security.py +++ b/exasol/toolbox/tools/security.py @@ -123,18 +123,30 @@ def from_json(report_str: str) -> Iterable[Issue]: def issues_to_markdown(issues: Iterable[Issue]) -> str: - markdown_str = "" - markdown_str += "# Security\n\n" - markdown_str += "|File|Cve|Cwe|Details|\n" - markdown_str += "|---|:-:|:-:|---|\n" - for issue in issues: + template = cleandoc(""" + {header}{rows} + """) + def _header(): + header = "" + markdown_str = "" + markdown_str += "# Security\n\n" + header += "|File|Cve|Cwe|Details|\n" + header += "|---|:-:|:-:|---|\n" + return header + + def _row(issue): row = "|" + issue.coordinates + "|" row += issue.cve + "|" row += issue.cwe + "|" for element in issue.references: row += element + " ,
" - markdown_str += row[:-5] + "|\n" - return markdown_str + row += row[:-5] + "|" + return row + + return template.format( + header=_header(), + rows="\n".join(_row(i) for i in issues) + ) def security_issue_title(issue: Issue) -> str: @@ -186,16 +198,14 @@ def create_security_issue(issue: Issue, project="") -> Tuple[str, str]: raise ex std_err = result.stderr.decode("utf-8") - std_out = result.stdout.decode("utf-8r") + std_out = result.stdout.decode("utf-8") return std_err, std_out CLI = typer.Typer() CVE_CLI = typer.Typer() -PP_CLI = typer.Typer() CLI.add_typer(CVE_CLI, name="cve", help="Work with CVE's") -CLI.add_typer(PP_CLI, name="prettyprint", help="Prints pretty") class Format(str, Enum): Maven = "maven" @@ -294,13 +304,18 @@ def create( stdout(format_jsonl(issue_url, issue)) -@PP_CLI.command(name="markdown") +class PPrintFormats(str, Enum): + markdown = "markdown" + + +@CLI.command(name="pretty-print") def json_issue_to_markdown( - json_file: str = typer.Argument(help="json file with issues to convert"), + format: PPrintFormats = typer.Option(default="", help="output format",), + json_file: typer.FileText = typer.Argument(default="", mode="r", help="json file with issues to convert"), ) -> None: - with open(json_file, "r") as file: - issues_ = from_json(file.read()) - print(issues_to_markdown(issues_)) + content = json_file.read() + issues = from_json(content) + print(issues_to_markdown(issues)) def format_jsonl(issue_url: str, issue: Issue) -> str: