Skip to content

Commit

Permalink
Merge pull request #4 from stuartmaxwell:report-improvements
Browse files Browse the repository at this point in the history
Report-improvements
  • Loading branch information
stuartmaxwell authored Dec 12, 2024
2 parents e047d40 + b9418ac commit 671d8e9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "dmarc-report"
version = "1.0.5"
version = "2.0.0"
description = "Displays a nicely formatted report in your terminal from a DMARC XML report."
readme = "README.md"
authors = [{ name = "Stuart Maxwell", email = "[email protected]" }]
Expand Down Expand Up @@ -67,7 +67,7 @@ convention = "google" # Accepts: "google", "numpy", or "pep257".
python_files = "test_*.py"

[tool.bumpver]
current_version = "1.0.5"
current_version = "2.0.0"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "👍 bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion src/dmarc_report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""DMARC report parser and display tool."""

__version__ = "1.0.5"
__version__ = "2.0.0"
57 changes: 40 additions & 17 deletions src/dmarc_report/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from rich.console import Console, Group
from rich.panel import Panel
from rich.table import Table
from rich.text import Text

from dmarc_report.schema import Report


def display_console(dmarc_report: Report) -> None:
def display_console(dmarc_report: Report) -> None: # noqa: PLR0915
"""Display the DMARC report using Rich tables and panels."""
# Create the tables
metadata_table = Table(
Expand All @@ -19,7 +20,7 @@ def display_console(dmarc_report: Report) -> None:
expand=True,
)
metadata_table.add_column("Field", style="cyan", width=20)
metadata_table.add_column("Value", style="green", width=52)
metadata_table.add_column("Value", width=52)

policy_table = Table(
title="DMARC Policy Details",
Expand All @@ -29,7 +30,7 @@ def display_console(dmarc_report: Report) -> None:
expand=True,
)
policy_table.add_column("Setting", style="cyan", width=20)
policy_table.add_column("Value", style="green", width=52)
policy_table.add_column("Value", width=52)

stats_table = Table(
title="Summary",
Expand All @@ -39,7 +40,7 @@ def display_console(dmarc_report: Report) -> None:
expand=True,
)
stats_table.add_column("Metric", style="cyan", width=20)
stats_table.add_column("Value", style="green", width=52)
stats_table.add_column("Value", width=52)

records_table = Table(
title="Message Records",
Expand All @@ -49,9 +50,9 @@ def display_console(dmarc_report: Report) -> None:
)
records_table.add_column("Source IP", style="cyan")
records_table.add_column("Count", style="magenta")
records_table.add_column("DKIM", style="yellow")
records_table.add_column("SPF", style="yellow")
records_table.add_column("Auth Results", style="green")
records_table.add_column("DKIM")
records_table.add_column("SPF")
records_table.add_column("Auth Results")

# Rich Layout
panel_group = Group(
Expand Down Expand Up @@ -92,19 +93,41 @@ def display_console(dmarc_report: Report) -> None:
policy_table.add_row("Failure Options", dmarc_report.policy_published.fo)

# Populate the records table
for record in dmarc_report.records:
dkim_auth_results_str = "\n".join(
f"dkim: {ar_d.domain} ({ar_d.result.value})" for ar_d in record.auth_results.dkim
)
spf_auth_results_str = "\n".join(
f"spf: {ar_s.domain} ({ar_s.result.value})" for ar_s in record.auth_results.spf
)

# Sort by count field descending, and by source_ip field ascending
records = sorted(dmarc_report.records, key=lambda record: (-record.count, record.source_ip))

for record in records:
auth_results = Text()
for ar_d in record.auth_results.dkim:
auth_results.append("dkim: ", style="cyan")
auth_results.append(ar_d.domain)
auth_results.append(" ")
auth_results.append(
ar_d.result.value,
style=f"{'green' if ar_d.result.value == 'pass' else 'bold red'}",
)
auth_results.append("\n")

for ar_d in record.auth_results.spf:
auth_results.append("spf: ", style="cyan")
auth_results.append(ar_d.domain)
auth_results.append(" ")
auth_results.append(
ar_d.result.value,
style=f"{'green' if ar_d.result.value == 'pass' else 'bold red'}",
)
auth_results.append("\n")

dkim_style = "green" if record.policy_evaluated.dkim.value == "pass" else "bold red"
spf_style = "green" if record.policy_evaluated.spf.value == "pass" else "bold red"

records_table.add_row(
record.source_ip,
str(record.count),
record.policy_evaluated.dkim.value,
record.policy_evaluated.spf.value,
dkim_auth_results_str + "\n" + spf_auth_results_str,
Text(record.policy_evaluated.dkim.value, style=dkim_style),
Text(record.policy_evaluated.spf.value, style=spf_style),
auth_results,
)

console = Console()
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 671d8e9

Please sign in to comment.