Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-security-linter-results-to-workflow-summary #254

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
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}
""")
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved
def _header():
header = ""
markdown_str = ""
markdown_str += "# Security\n\n"
header += "|File|Cve|Cwe|Details|\n"
header += "|---|:-:|:-:|---|\n"
return header
Jannis-Mittenzwei marked this conversation as resolved.
Show resolved Hide resolved

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
Loading