-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine_risk): 🚀 New report table with hyperlinks
- Loading branch information
Showing
6 changed files
with
101 additions
and
6 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
Empty file.
58 changes: 58 additions & 0 deletions
58
...s/engine_core/src/infrastructure/driven_adapters/printer_rich_table/printer_rich_table.py
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,58 @@ | ||
from dataclasses import dataclass | ||
|
||
from devsecops_engine_tools.engine_core.src.domain.model.gateway.printer_table_gateway import ( | ||
PrinterTableGateway, | ||
) | ||
from devsecops_engine_tools.engine_core.src.domain.model.finding import ( | ||
Finding, | ||
) | ||
from devsecops_engine_tools.engine_core.src.domain.model.report import ( | ||
Report, | ||
) | ||
from devsecops_engine_tools.engine_core.src.infrastructure.helpers.util import ( | ||
format_date | ||
) | ||
from rich.console import Console | ||
from rich.table import Table | ||
from rich import box | ||
|
||
@dataclass | ||
class PrinterRichTable(PrinterTableGateway): | ||
def print_table_findings(self, finding_list: "list[Finding]"): | ||
# To implement | ||
return | ||
|
||
def print_table_report(self, report_list: "list[Report]"): | ||
sorted_report_list = sorted(report_list, key=lambda report: report.risk_score, reverse=True) | ||
headers = ["Risk Score", "ID", "Tags", "Services"] | ||
table = Table(show_header=True, header_style="bold magenta", box=box.DOUBLE_EDGE) | ||
for header in headers: | ||
table.add_column(header) | ||
for report in sorted_report_list: | ||
row_data = [ | ||
str(report.risk_score), | ||
self._check_spaces(report.vm_id, report.vm_id_url), | ||
", ".join(report.tags), | ||
self._check_spaces(report.service, report.service_url) | ||
] | ||
table.add_row(*row_data) | ||
console = Console() | ||
console.print(table) | ||
|
||
def print_table_exclusions(self, exclusions_list): | ||
# To implement | ||
return | ||
|
||
def _check_spaces(self, value, url): | ||
values = value.split() | ||
urls = url.split() | ||
new_value = "" | ||
if len(values) > 1 or len(urls) > 1: | ||
for value, url in zip(values, urls): | ||
new_value += self._make_hyperlink(value, url) + " " | ||
else: | ||
new_value = self._make_hyperlink(values[0], urls[0]) | ||
return new_value | ||
|
||
def _make_hyperlink(self, value, url): | ||
return f"[link={url}]{value}[/link]" |
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