Add check_missing_domains command and tests
This commit is contained in:
parent
4c80860b20
commit
1a6e836631
2 changed files with 124 additions and 1 deletions
|
@ -18,7 +18,9 @@ from __future__ import annotations
|
|||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Dict, List, Optional, Set
|
||||
|
||||
import json
|
||||
|
||||
import typer
|
||||
|
||||
|
@ -110,5 +112,36 @@ def cache_ratio_cmd(domain: Optional[str] = typer.Option(None, help="Filter by d
|
|||
typer.echo(f"Cache hit ratio: {ratio:.2f}%")
|
||||
|
||||
|
||||
@app.command("check-missing-domains")
|
||||
def check_missing_domains(json_output: bool = typer.Option(False, "--json", help="Output missing domains as JSON")) -> None:
|
||||
"""Show domains present in the database but absent from Nginx config."""
|
||||
try:
|
||||
from scripts.generate_reports import _get_domains as _db_domains
|
||||
except Exception: # pragma: no cover - fallback if import fails
|
||||
_db_domains = load_domains_from_db
|
||||
|
||||
if not isinstance(json_output, bool):
|
||||
json_output = False
|
||||
|
||||
db_domains = set(_db_domains())
|
||||
|
||||
paths = nginx_config.discover_configs()
|
||||
servers = nginx_config.parse_servers(paths)
|
||||
config_domains: Set[str] = set()
|
||||
for server in servers:
|
||||
names = server.get("server_name", "")
|
||||
for name in names.split():
|
||||
if name:
|
||||
config_domains.add(name)
|
||||
|
||||
missing = sorted(db_domains - config_domains)
|
||||
|
||||
if json_output:
|
||||
typer.echo(json.dumps(missing))
|
||||
else:
|
||||
for d in missing:
|
||||
typer.echo(d)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue