Coverage for frappe_manager / commands / ssl / list.py: 38%
42 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
1"""List SSL certificates command."""
3from typing import Annotated
5import typer
6from typer_examples import example
8from frappe_manager import CLI_BENCHES_DIRECTORY
9from frappe_manager.logger.context import LoggerContext
10from frappe_manager.output_manager import temporary_stop
11from frappe_manager.site_manager.bench_service import BenchService
12from frappe_manager.utils.callbacks import prompt_for_bench_selection, sites_autocompletion_callback
14from .bench_helpers import _list_bench_certificates
15from .external_helpers import _list_external_certificates
16from .helpers import get_output_handler
19@example(
20 "List SSL certificates for a bench",
21 "{benchname}",
22 detail="Shows certificates installed for a specific bench.",
23 benchname="mybench",
24)
25@example(
26 "List all external (standalone) certificates",
27 "--standalone",
28 detail="Lists certificates managed in standalone (external project) mode.",
29)
30@example(
31 "List all certificates (bench + external)",
32 "--all",
33 detail="Lists both bench-installed and external certificates together.",
34)
35def list_certificates(
36 ctx: typer.Context,
37 benchname: Annotated[
38 str | None,
39 typer.Argument(
40 help="Name of the bench (omit for standalone mode).",
41 autocompletion=sites_autocompletion_callback,
42 ),
43 ] = None,
44 standalone: Annotated[
45 bool,
46 typer.Option("--standalone", help="List certificates for external (non-bench) domains"),
47 ] = False,
48 all: Annotated[
49 bool,
50 typer.Option("--all", help="List all certificates (bench + external)"),
51 ] = False,
52):
53 """
54 List SSL certificates.
56 Use without flags to list certificates for a bench, or pass --standalone or --all to change scope.
57 """
59 if all:
60 _list_all_certificates(ctx)
61 elif standalone:
62 _list_external_certificates(ctx)
63 else:
64 benchname = prompt_for_bench_selection(benchname)
66 if not benchname:
67 context = LoggerContext(operation="ssl-list")
68 output = get_output_handler(ctx, context=context)
69 output.display_error("Benchname required in bench mode")
70 with temporary_stop(output):
71 typer.echo(ctx.get_help())
72 raise typer.Exit(1)
74 _list_bench_certificates(ctx, benchname)
77def _list_all_certificates(ctx: typer.Context):
78 """List all SSL certificates (bench + external)."""
80 services_manager = ctx.obj["services"]
81 context = LoggerContext(operation="ssl-list-all")
82 output = get_output_handler(ctx, context=context)
84 output.print("\n[bold cyan]═══ External Certificates ═══[/bold cyan]\n", emoji_code="")
85 _list_external_certificates(ctx)
87 output.print("\n[bold cyan]═══ Bench Certificates ═══[/bold cyan]\n", emoji_code="")
89 bench_service = BenchService(CLI_BENCHES_DIRECTORY, services_manager)
90 benches = bench_service.get_bench_names()
92 if not benches:
93 output.print("No benches found", emoji_code=":information_source:")
94 else:
95 for bench_name in benches:
96 output.print(f"\n[bold]Bench: {bench_name}[/bold]", emoji_code="")
97 _list_bench_certificates(ctx, bench_name)