DKIM selectors where queried separatedly
This commit is contained in:
+18
-7
@@ -400,9 +400,9 @@ def _json_list(value: str | None) -> list:
|
||||
return data if isinstance(data, list) else []
|
||||
|
||||
|
||||
def _observed_dkim_selectors(session: Session, domain: str) -> list[str]:
|
||||
def _observed_dkim_selectors(session: Session, domain: str) -> list[tuple[str, str]]:
|
||||
rows = session.execute(
|
||||
select(AuthResult.selector)
|
||||
select(AuthResult.selector, AuthResult.domain)
|
||||
.select_from(AuthResult)
|
||||
.join(Record)
|
||||
.join(Report)
|
||||
@@ -410,11 +410,12 @@ def _observed_dkim_selectors(session: Session, domain: str) -> list[str]:
|
||||
Report.domain == domain,
|
||||
AuthResult.auth_type == "dkim",
|
||||
AuthResult.selector.is_not(None),
|
||||
AuthResult.domain.is_not(None),
|
||||
)
|
||||
.distinct()
|
||||
.order_by(AuthResult.selector)
|
||||
).scalars().all()
|
||||
return [row for row in rows if row]
|
||||
.order_by(AuthResult.domain, AuthResult.selector)
|
||||
).all()
|
||||
return [(selector, auth_domain) for selector, auth_domain in rows if selector and auth_domain]
|
||||
|
||||
|
||||
def _snapshot_model(domain: str, policy: DomainDnsPolicy) -> DomainDnsSnapshot:
|
||||
@@ -447,6 +448,14 @@ def _latest_dns_snapshot(session: Session, domain: str) -> SimpleNamespace | Non
|
||||
)
|
||||
if not snapshot:
|
||||
return None
|
||||
dkim_records = _json_list(snapshot.dkim_records_json)
|
||||
dkim_found = [item for item in dkim_records if isinstance(item, dict) and item.get("record")]
|
||||
dkim_missing = [item for item in dkim_records if isinstance(item, dict) and not item.get("record")]
|
||||
dns_errors = [
|
||||
item
|
||||
for item in _json_list(snapshot.errors_json)
|
||||
if isinstance(item, str) and not item.startswith("DKIM lookup failed") and not item.startswith("DKIM record not found")
|
||||
]
|
||||
return SimpleNamespace(
|
||||
id=snapshot.id,
|
||||
domain=snapshot.domain,
|
||||
@@ -463,9 +472,11 @@ def _latest_dns_snapshot(session: Session, domain: str) -> SimpleNamespace | Non
|
||||
spf_record=snapshot.spf_record,
|
||||
spf_all=snapshot.spf_all,
|
||||
spf_includes=_json_list(snapshot.spf_includes_json),
|
||||
dkim_records=_json_list(snapshot.dkim_records_json),
|
||||
dkim_records=dkim_records,
|
||||
dkim_found=dkim_found,
|
||||
dkim_missing=dkim_missing,
|
||||
mx_records=_json_list(snapshot.mx_records_json),
|
||||
errors=_json_list(snapshot.errors_json),
|
||||
errors=dns_errors,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user