Fix code formatting and linting issues

- Auto-format all Python files with black and isort
- Remove unused imports with autoflake
- Fix flake8 issues (missing newlines, blank lines, etc.)
- Fix nonlocal/global scope issues in main.py
- Fix security.py import order (E402)
- Remove f-string without placeholders
- Add nosec comment for intentional exception handling
- Fix test imports to match refactored DMARCParser API

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-09 12:08:51 +00:00
parent f6908fe9ec
commit 6ae017b142
28 changed files with 999 additions and 956 deletions
+19 -21
View File
@@ -1,68 +1,66 @@
from typing import List, Optional
from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text, Index
from sqlalchemy.orm import relationship
from app.core.database import Base
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Index, Integer, String, Text
from sqlalchemy.orm import relationship
class Domain(Base):
"""Domain model representing a monitored domain"""
__tablename__ = "domains"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, unique=True, index=True, nullable=False)
description = Column(Text, nullable=True)
active = Column(Boolean, default=True, index=True)
# DMARC policy information
dmarc_policy = Column(String, nullable=True, index=True)
spf_record = Column(String, nullable=True)
dkim_selectors = Column(String, nullable=True) # Comma-separated list of DKIM selectors
# DNS verification status
verified = Column(Boolean, default=False, index=True)
verification_token = Column(String, nullable=True)
# Date fields
created_at = Column(DateTime, default=datetime.utcnow, index=True)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
reports = relationship("DMARCReport", back_populates="domain", cascade="all, delete-orphan")
user_domains = relationship("UserDomain", back_populates="domain", cascade="all, delete-orphan")
# Indexes for common queries
__table_args__ = (
# Index for finding active and verified domains
Index('ix_domains_active_verified', 'active', 'verified'),
Index("ix_domains_active_verified", "active", "verified"),
# Index for finding domains by policy
Index('ix_domains_policy', 'dmarc_policy'),
Index("ix_domains_policy", "dmarc_policy"),
# Index for finding recently updated domains
Index('ix_domains_updated', 'updated_at'),
Index("ix_domains_updated", "updated_at"),
)
def __repr__(self):
return f"<Domain {self.name}>"
class UserDomain(Base):
"""Association table for users and domains"""
__tablename__ = "user_domains"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
domain_id = Column(Integer, ForeignKey("domains.id"), nullable=False)
# Access level (admin, viewer, etc)
role = Column(String, default="viewer", nullable=False)
# Date fields
created_at = Column(DateTime, default=datetime.utcnow)
# Relationships
user = relationship("User", back_populates="user_domains")
domain = relationship("Domain", back_populates="user_domains")
domain = relationship("Domain", back_populates="user_domains")
+28 -30
View File
@@ -1,91 +1,89 @@
from datetime import datetime
from typing import List, Optional
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text, Index
from sqlalchemy.orm import relationship
from app.core.database import Base
from sqlalchemy import Column, DateTime, ForeignKey, Index, Integer, String, Text
from sqlalchemy.orm import relationship
class DMARCReport(Base):
"""DMARC Aggregate Report model"""
__tablename__ = "dmarc_reports"
id = Column(Integer, primary_key=True, index=True)
domain_id = Column(Integer, ForeignKey("domains.id"), nullable=False, index=True)
# Report metadata
report_id = Column(String, index=True, nullable=False)
org_name = Column(String, nullable=False, index=True)
begin_date = Column(Integer, nullable=False, index=True) # Unix timestamp
end_date = Column(Integer, nullable=False, index=True) # Unix timestamp
source_email = Column(String, nullable=True)
# Policy information
policy = Column(String, nullable=True, index=True) # none, quarantine, reject
subdomain_policy = Column(String, nullable=True)
adkim = Column(String(1), nullable=True) # r (relaxed) or s (strict)
aspf = Column(String(1), nullable=True) # r (relaxed) or s (strict)
aspf = Column(String(1), nullable=True) # r (relaxed) or s (strict)
percentage = Column(Integer, nullable=True)
# Processing metadata
processed_at = Column(DateTime, default=datetime.utcnow, index=True)
raw_data = Column(Text, nullable=True) # Original XML content (optional)
# Relationships
domain = relationship("Domain", back_populates="reports")
records = relationship("ReportRecord", back_populates="report", cascade="all, delete-orphan")
# Indexes for common queries
__table_args__ = (
# Composite index for domain and date range queries (common dashboard queries)
Index('ix_dmarc_reports_domain_dates', 'domain_id', 'begin_date', 'end_date'),
Index("ix_dmarc_reports_domain_dates", "domain_id", "begin_date", "end_date"),
# Index for finding reports by policy
Index('ix_dmarc_reports_policy', 'policy'),
Index("ix_dmarc_reports_policy", "policy"),
# Index for finding recent reports (dashboard statistics)
Index('ix_dmarc_reports_processed', 'processed_at'),
Index("ix_dmarc_reports_processed", "processed_at"),
)
def __repr__(self):
return f"<DMARCReport {self.report_id} for {self.domain_id}>"
class ReportRecord(Base):
"""Individual record within a DMARC report"""
__tablename__ = "report_records"
id = Column(Integer, primary_key=True, index=True)
report_id = Column(Integer, ForeignKey("dmarc_reports.id"), nullable=False, index=True)
# Source information
source_ip = Column(String, nullable=False, index=True)
count = Column(Integer, nullable=False, default=0)
# Policy evaluation
disposition = Column(String, nullable=False, index=True) # none, quarantine, reject
dkim = Column(String, nullable=True, index=True) # pass, fail
spf = Column(String, nullable=True, index=True) # pass, fail
spf = Column(String, nullable=True, index=True) # pass, fail
# Identifiers
header_from = Column(String, nullable=True, index=True)
envelope_from = Column(String, nullable=True)
# Authentication details (optional JSON fields)
dkim_auth_details = Column(Text, nullable=True) # JSON array of DKIM results
spf_auth_details = Column(Text, nullable=True) # JSON array of SPF results
spf_auth_details = Column(Text, nullable=True) # JSON array of SPF results
# Relationships
report = relationship("DMARCReport", back_populates="records")
# Indexes for common queries
__table_args__ = (
# Composite index for source IP and evaluation results (for filtering)
Index('ix_report_records_source_auth', 'source_ip', 'dkim', 'spf'),
Index("ix_report_records_source_auth", "source_ip", "dkim", "spf"),
# Composite index for disposition and count (for statistics)
Index('ix_report_records_disposition', 'disposition', 'count'),
Index("ix_report_records_disposition", "disposition", "count"),
)
def __repr__(self):
return f"<ReportRecord {self.id} ({self.source_ip})>"
return f"<ReportRecord {self.id} ({self.source_ip})>"
+6 -7
View File
@@ -1,13 +1,12 @@
from typing import List, Optional
from sqlalchemy import Boolean, Column, Integer, String
from sqlalchemy.orm import relationship
from app.core.database import Base
from sqlalchemy import Boolean, Column, Integer, String
from sqlalchemy.orm import relationship
class User(Base):
"""User model"""
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
@@ -16,10 +15,10 @@ class User(Base):
is_active = Column(Boolean, default=True)
is_superuser = Column(Boolean, default=False)
is_verified = Column(Boolean, default=False)
# Additional fields
full_name = Column(String, nullable=True)
organization = Column(String, nullable=True)
# Relationships
user_domains = relationship("UserDomain", back_populates="user", cascade="all, delete-orphan")
user_domains = relationship("UserDomain", back_populates="user", cascade="all, delete-orphan")