sync: auto-sync from HOWARD-HOME at 2026-07-05 20:23:39

Author: Howard Enos
Machine: HOWARD-HOME
Timestamp: 2026-07-05 20:23:39
This commit is contained in:
2026-07-05 20:24:08 -07:00
parent 976bfe7957
commit a8e76ba215
10 changed files with 292 additions and 108 deletions

View File

@@ -55,7 +55,7 @@ def _gen_password(n: int = 20) -> str:
return "".join(secrets.choice(alpha) for _ in range(n))
def _resolve_password(args, *, allow_gen: bool = True):
def _resolve_password(args):
"""Return (password, was_generated) from --password / --password-env / --gen-password.
Prefer --password-env or --gen-password: a literal --password lands in shell
history and `ps` on the operator's machine."""
@@ -67,15 +67,18 @@ def _resolve_password(args, *, allow_gen: bool = True):
if not v:
raise SystemExit(f"[ERROR] env var {env_var} is unset/empty")
return v, False
if allow_gen and getattr(args, "gen_password", False):
if getattr(args, "gen_password", False):
return _gen_password(), True
return None, False
def _vault_reminder(uid: str) -> None:
print("[CRITICAL] House rule: store this credential in the SOPS vault now, e.g.:")
def _vault_reminder(uid: str, stream=None) -> None:
out = stream or sys.stdout
print("[CRITICAL] House rule: store this credential in the SOPS vault now, e.g.:",
file=out)
print(f" bash .claude/scripts/vault.sh set-field "
f"infrastructure/owncloud-users/{uid}.sops.yaml credentials.password '<paste-here>'")
f"infrastructure/owncloud-users/{uid}.sops.yaml credentials.password '<paste-here>'",
file=out)
def cmd_status(c: OwncloudClient, args) -> int:
@@ -204,13 +207,20 @@ def cmd_user_add(c: OwncloudClient, args) -> int:
if not _gated(desc, args.confirm):
return 3
res = c.create_user(args.uid, pw, args.display_name, args.email, args.group)
if args.json:
# keep stdout parseable: password + vault reminder go to stderr
if generated:
print(f"[CRITICAL] generated password for '{args.uid}' (shown once); "
"store in vault", file=sys.stderr)
_vault_reminder(args.uid, stream=sys.stderr)
print(json.dumps({"uid": args.uid, "created": True,
"generated_password": pw if generated else None,
"detail": res}, indent=2))
return 0
print(f"[OK] created user '{args.uid}'")
if generated:
print(f"[CRITICAL] generated password (shown once): {pw}")
_vault_reminder(args.uid)
if args.json:
print(json.dumps({"uid": args.uid, "created": True,
"generated_password": generated, "detail": res}, indent=2))
return 0
@@ -246,13 +256,19 @@ def cmd_user_reset_password(c: OwncloudClient, args) -> int:
if not _gated(f"reset password for user '{args.uid}'", args.confirm):
return 3
c.reset_password(args.uid, pw)
if args.json:
if generated:
print(f"[CRITICAL] generated password for '{args.uid}' (shown once); "
"store in vault", file=sys.stderr)
_vault_reminder(args.uid, stream=sys.stderr)
print(json.dumps({"uid": args.uid, "password_reset": True,
"generated_password": pw if generated else None},
indent=2))
return 0
print(f"[OK] reset password for '{args.uid}'")
if generated:
print(f"[CRITICAL] generated password (shown once): {pw}")
_vault_reminder(args.uid)
if args.json:
print(json.dumps({"uid": args.uid, "password_reset": True,
"generated_password": generated}, indent=2))
return 0