Skip to content

Commit

Permalink
resolve conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis-Mittenzwei committed Oct 8, 2024
1 parent 6af66e1 commit e4d6bd4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 30 additions & 15 deletions exasol/toolbox/tools/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + " ,<br>"
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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e4d6bd4

Please sign in to comment.