|
11 | 11 |
|
12 | 12 | from .export import export_profiles, jump_candidates |
13 | 13 | from .generate import generate |
| 14 | +from .hooks import run_hooks |
14 | 15 | from .inventory import DEFAULT_INVENTORY, ROOT, discover, load, save, write_ansible_inventory |
15 | 16 | from .summary import render_summary |
16 | 17 | from .users import active_users, remove_users |
|
20 | 21 | def parser() -> argparse.ArgumentParser: |
21 | 22 | result = argparse.ArgumentParser(description="Configure MegaProxy HTTPS and SSH servers") |
22 | 23 | result.add_argument("--inventory", "-i", help="Inventory configuration path") |
| 24 | + result.add_argument("--no-hooks", action="store_true", help="Do not run local hooks") |
23 | 25 | sub = result.add_subparsers(dest="command") |
24 | | - sub.add_parser("inventory", help="Create a new inventory") |
25 | | - sub.add_parser("validate", help="Validate inventory and Ansible syntax") |
26 | | - sub.add_parser("check", help="Run the complete local/CI test suite") |
| 26 | + commands = [] |
| 27 | + commands.append(sub.add_parser("inventory", help="Create a new inventory")) |
| 28 | + commands.append(sub.add_parser("validate", help="Validate inventory and Ansible syntax")) |
| 29 | + commands.append(sub.add_parser("check", help="Run the complete local/CI test suite")) |
27 | 30 | for name in ("plan", "apply", "verify"): |
28 | 31 | command = sub.add_parser(name) |
| 32 | + commands.append(command) |
29 | 33 | command.add_argument("--limit") |
30 | 34 | command.add_argument("--tags") |
31 | 35 | export = sub.add_parser("export") |
| 36 | + commands.append(export) |
32 | 37 | export.add_argument("--output", default=".generated/megaproxy-profiles.json") |
33 | 38 | export.add_argument("--all-jumps", action="store_true") |
34 | 39 | configs = sub.add_parser("configs", help="Generate all supported client configuration formats") |
| 40 | + commands.append(configs) |
35 | 41 | configs.add_argument("--output-dir", default=".generated/configs") |
36 | 42 | summary = sub.add_parser("summary", help="Print credentials for a password manager") |
| 43 | + commands.append(summary) |
37 | 44 | summary.add_argument("login", nargs="?", help="Show only this login") |
38 | | - sub.add_parser("remove-users", help="Remove one or more proxy user accounts") |
39 | | - sub.add_parser("vault-secrets", help="Encrypt only secret inventory fields with Ansible Vault") |
40 | | - sub.add_parser("jumps", help="List all possible SSH jump chains") |
| 45 | + commands.append(sub.add_parser("remove-users", help="Remove one or more proxy user accounts")) |
| 46 | + commands.append(sub.add_parser("vault-secrets", help="Encrypt only secret inventory fields with Ansible Vault")) |
| 47 | + commands.append(sub.add_parser("jumps", help="List all possible SSH jump chains")) |
| 48 | + for command in commands: |
| 49 | + command.add_argument("--no-hooks", action="store_true", default=argparse.SUPPRESS, help=argparse.SUPPRESS) |
41 | 50 | return result |
42 | 51 |
|
43 | 52 |
|
@@ -196,6 +205,10 @@ def main() -> None: |
196 | 205 | applied_admin = tags is None or "admin" in {tag.strip() for tag in tags.split(",")} |
197 | 206 | if code == 0 and command == "apply" and applied_admin: |
198 | 207 | finish_bootstrap(path, inventory, limit) |
| 208 | + if code == 0 and command == "apply" and not args.no_hooks: |
| 209 | + inventory = load(path) |
| 210 | + generated = write_ansible_inventory(path, inventory) |
| 211 | + code = run_hooks(ROOT, "post-config-change", path, generated) |
199 | 212 | raise SystemExit(code) |
200 | 213 | except (ValidationError, FileNotFoundError, ValueError) as error: |
201 | 214 | print(f"Configuration error: {error}", file=sys.stderr) |
|
0 commit comments