feat(auth): decouple credential resolution from legacy tea config
This commit is contained in:
1 parent
6c524b2ed5
commit
750f0cad35
1 file changed
+191
-153
+191
-153
@@ -18,6 +18,7 @@ from __future__ import annotations
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import urllib.error
|
import urllib.error
|
||||||
@@ -53,14 +54,34 @@ class Credentials:
|
|||||||
ssh_key: str | None = None
|
ssh_key: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def redact_sensitive(text: str, *sensitive_values: str | None) -> str:
|
||||||
|
"""Scrub sensitive tokens, credentials, and URL userinfo from string."""
|
||||||
|
if not text:
|
||||||
|
return text
|
||||||
|
result = text
|
||||||
|
# 1. Explicitly replace known sensitive values
|
||||||
|
for val in sensitive_values:
|
||||||
|
if val and isinstance(val, str) and len(val.strip()) > 3:
|
||||||
|
result = result.replace(val.strip(), "[REDACTED]")
|
||||||
|
# 2. Redact credentials embedded in URLs: http(s)://user:pass@host or http(s)://token@host
|
||||||
|
result = re.sub(r"(https?://)([^:]+):([^@]+)@", r"\1\2:[REDACTED]@", result)
|
||||||
|
result = re.sub(r"(https?://)([^@/:]+)@", r"\1[REDACTED]@", result)
|
||||||
|
# 3. Redact Authorization header values if present in text
|
||||||
|
result = re.sub(
|
||||||
|
r"(?i)(token|bearer)\s+[a-zA-Z0-9_\-\.]{8,}", r"\1 [REDACTED]", result
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class SecretProvider:
|
class SecretProvider:
|
||||||
"""Resolves API credentials using a multi-tier fallback strategy.
|
"""Resolves API credentials using a multi-tier fallback strategy.
|
||||||
|
|
||||||
Hierarchy:
|
Precedence Hierarchy:
|
||||||
1. Process environment variables (GITEA_TOKEN, GITHUB_TOKEN, etc.).
|
1. Direct environment variables (GITEA_URL, GITEA_USER, GITEA_TOKEN, GITHUB_TOKEN).
|
||||||
2. Local .env file in the current working directory or repository root.
|
2. Local .env file (development overrides).
|
||||||
3. Laptop SOPS encrypted secrets file (~/Config/secrets.yaml).
|
3. Persona-scoped SOPS (~/Config/secrets.<persona>.yaml or persona secrets file when --as <persona> is passed).
|
||||||
4. Legacy fallbacks (tea CLI config for Gitea, Homelab SOPS file for GitHub).
|
4. Default SOPS (~/Config/secrets.yaml, ~/Homelab/secrets.yaml).
|
||||||
|
5. System host CLI fallback: gt token via environment or gt auth token execution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -113,95 +134,24 @@ class SecretProvider:
|
|||||||
return None
|
return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parse_tea_logins(tea_cfg: Path) -> list[dict[str, Any]]:
|
|
||||||
"""Parse ~/.config/tea/config.yml into discrete login dictionaries."""
|
|
||||||
if not tea_cfg.is_file():
|
|
||||||
return []
|
|
||||||
logins: list[dict[str, Any]] = []
|
|
||||||
current: dict[str, Any] | None = None
|
|
||||||
in_logins = False
|
|
||||||
try:
|
|
||||||
with open(tea_cfg, "r", encoding="utf-8") as f:
|
|
||||||
for raw_line in f:
|
|
||||||
stripped = raw_line.strip()
|
|
||||||
if not stripped or stripped.startswith("#"):
|
|
||||||
continue
|
|
||||||
if stripped == "logins:":
|
|
||||||
in_logins = True
|
|
||||||
continue
|
|
||||||
if in_logins and not raw_line.startswith((" ", "\t", "-")):
|
|
||||||
break
|
|
||||||
if not in_logins:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if stripped.startswith("- "):
|
|
||||||
if current is not None:
|
|
||||||
logins.append(current)
|
|
||||||
current = {}
|
|
||||||
rest = stripped[2:].strip()
|
|
||||||
if ":" in rest:
|
|
||||||
k, v = rest.split(":", 1)
|
|
||||||
val = v.strip().strip("'\"")
|
|
||||||
current[k.strip()] = True if val.lower() == "true" else False if val.lower() == "false" else val
|
|
||||||
elif current is not None and ":" in stripped:
|
|
||||||
k, v = stripped.split(":", 1)
|
|
||||||
val = v.strip().strip("'\"")
|
|
||||||
current[k.strip()] = True if val.lower() == "true" else False if val.lower() == "false" else val
|
|
||||||
if current is not None:
|
|
||||||
logins.append(current)
|
|
||||||
except OSError:
|
|
||||||
return []
|
|
||||||
return logins
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _extract_tea_login(
|
def _extract_gt_token(cls, target_persona: str | None = None) -> str | None:
|
||||||
cls, target_persona: str | None = None
|
"""Extract Gitea token from host 'gt' CLI fallback."""
|
||||||
) -> tuple[str | None, str | None, str | None, str | None]:
|
cmd = ["gt", "auth", "token"]
|
||||||
"""Extract Gitea credentials from ~/.config/tea/config.yml for a target persona or default.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
A tuple of (token, url, user, ssh_key), or (None, None, None, None).
|
|
||||||
"""
|
|
||||||
tea_cfg = Path.home() / ".config" / "tea" / "config.yml"
|
|
||||||
logins = cls._parse_tea_logins(tea_cfg)
|
|
||||||
if not logins:
|
|
||||||
return None, None, None, None
|
|
||||||
|
|
||||||
selected: dict[str, Any] | None = None
|
|
||||||
if target_persona:
|
if target_persona:
|
||||||
target_norm = target_persona.strip().lower()
|
cmd.extend(["--user", target_persona])
|
||||||
for entry in logins:
|
try:
|
||||||
name = str(entry.get("name", "")).strip().lower()
|
res = subprocess.run(
|
||||||
user = str(entry.get("user", "")).strip().lower()
|
cmd,
|
||||||
if target_norm in (name, user):
|
capture_output=True,
|
||||||
selected = entry
|
text=True,
|
||||||
break
|
check=False,
|
||||||
if not selected:
|
)
|
||||||
available = ", ".join(str(e.get("name", "")) for e in logins)
|
if res.returncode == 0 and res.stdout.strip():
|
||||||
print(
|
return res.stdout.strip()
|
||||||
f"❌ Error: Persona / login '{target_persona}' not found in tea configuration ({tea_cfg}).\n"
|
except FileNotFoundError:
|
||||||
f" Available tea logins: {available}",
|
return None
|
||||||
file=sys.stderr,
|
return None
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
for entry in logins:
|
|
||||||
if entry.get("default") is True:
|
|
||||||
selected = entry
|
|
||||||
break
|
|
||||||
if not selected and logins:
|
|
||||||
selected = logins[0]
|
|
||||||
|
|
||||||
if not selected:
|
|
||||||
return None, None, None, None
|
|
||||||
|
|
||||||
return (
|
|
||||||
selected.get("token"),
|
|
||||||
selected.get("url"),
|
|
||||||
selected.get("user") or selected.get("name"),
|
|
||||||
selected.get("ssh_key"),
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve(cls, as_persona: str | None = None) -> Credentials:
|
def resolve(cls, as_persona: str | None = None) -> Credentials:
|
||||||
@@ -221,83 +171,149 @@ class SecretProvider:
|
|||||||
|
|
||||||
persona = as_persona or get_val("NEW_REPO_AS") or get_val("TEA_LOGIN")
|
persona = as_persona or get_val("NEW_REPO_AS") or get_val("TEA_LOGIN")
|
||||||
|
|
||||||
secrets_file_env = os.environ.get("SECRETS_FILE")
|
gitea_url = get_val("GITEA_URL") or "https://gitea.roadtotech.me"
|
||||||
config_secrets = (
|
|
||||||
Path(secrets_file_env)
|
|
||||||
if secrets_file_env
|
|
||||||
else Path.home() / "Config" / "secrets.yaml"
|
|
||||||
)
|
|
||||||
homelab_secrets = (
|
|
||||||
Path(os.environ["HOMELAB_SECRETS_FILE"])
|
|
||||||
if "HOMELAB_SECRETS_FILE" in os.environ
|
|
||||||
else Path.home() / "Homelab" / "Core" / "nixos" / "secrets.yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
tea_token, tea_url, tea_user, tea_ssh_key = cls._extract_tea_login(target_persona=persona)
|
|
||||||
|
|
||||||
persona_sops: Path | None = None
|
|
||||||
if persona:
|
if persona:
|
||||||
candidates = [
|
# ------------------------------------------------------------------
|
||||||
Path.home() / "Config" / f"{persona}-secrets.yaml",
|
# Persona-Scoped Credential Resolution
|
||||||
Path.home() / "Config" / f"{persona.rstrip('ux')}-secrets.yaml",
|
# Strict isolation: NEVER fall through to default root credentials.
|
||||||
]
|
# ------------------------------------------------------------------
|
||||||
for c in candidates:
|
persona_norm = persona.strip()
|
||||||
|
persona_upper = persona_norm.upper()
|
||||||
|
env_gitea_user = get_val("GITEA_USER")
|
||||||
|
|
||||||
|
# Check if env/dotenv explicitly provides credentials for this persona.
|
||||||
|
# If GITEA_USER is set and does not match the persona, direct GITEA_TOKEN
|
||||||
|
# belongs to a different forge user and must not be used.
|
||||||
|
persona_env_token = get_val(f"GITEA_TOKEN_{persona_upper}")
|
||||||
|
if not persona_env_token:
|
||||||
|
if env_gitea_user is None or env_gitea_user.lower() == persona_norm.lower():
|
||||||
|
persona_env_token = get_val("GITEA_TOKEN")
|
||||||
|
|
||||||
|
persona_gh_token = get_val(f"GITHUB_TOKEN_{persona_upper}") or get_val("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
# Candidate persona SOPS files
|
||||||
|
persona_sops: Path | None = None
|
||||||
|
persona_candidates: list[Path] = []
|
||||||
|
if os.environ.get("PERSONA_SECRETS_FILE"):
|
||||||
|
persona_candidates.append(Path(os.environ["PERSONA_SECRETS_FILE"]))
|
||||||
|
persona_candidates.extend([
|
||||||
|
Path.home() / "Config" / f"secrets.{persona_norm}.yaml",
|
||||||
|
Path.home() / "Config" / f"{persona_norm}-secrets.yaml",
|
||||||
|
Path.home() / "Config" / f"secrets.{persona_norm.rstrip('ux')}.yaml",
|
||||||
|
Path.home() / "Config" / f"{persona_norm.rstrip('ux')}-secrets.yaml",
|
||||||
|
])
|
||||||
|
for c in persona_candidates:
|
||||||
if c.is_file():
|
if c.is_file():
|
||||||
persona_sops = c
|
persona_sops = c
|
||||||
break
|
break
|
||||||
|
|
||||||
gitea_url = get_val("GITEA_URL") or tea_url or "https://gitea.roadtotech.me"
|
gitea_user = persona_norm
|
||||||
|
|
||||||
if persona:
|
|
||||||
gitea_user = get_val("GITEA_USER") or tea_user or persona
|
|
||||||
gitea_token = (
|
gitea_token = (
|
||||||
get_val("GITEA_TOKEN")
|
persona_env_token
|
||||||
or (cls._extract_sops_key(["gitea", "token"], persona_sops) if persona_sops else None)
|
or (cls._extract_sops_key(["gitea", "token"], persona_sops) if persona_sops else None)
|
||||||
or (cls._extract_sops_key(["gitea", "api_token"], persona_sops) if persona_sops else None)
|
or (cls._extract_sops_key(["gitea", "api_token"], persona_sops) if persona_sops else None)
|
||||||
or tea_token
|
or cls._extract_gt_token(target_persona=persona_norm)
|
||||||
)
|
)
|
||||||
github_user = get_val("GITHUB_USER") or persona
|
|
||||||
|
github_user = get_val("GITHUB_USER") or persona_norm
|
||||||
github_token = (
|
github_token = (
|
||||||
get_val("GITHUB_TOKEN")
|
persona_gh_token
|
||||||
or (cls._extract_sops_key(["github", "token"], persona_sops) if persona_sops else None)
|
or (cls._extract_sops_key(["github", "token"], persona_sops) if persona_sops else None)
|
||||||
or cls._extract_sops_key(["system", "gh_repo_token"], config_secrets)
|
or (cls._extract_sops_key(["github", "api_token"], persona_sops) if persona_sops else None)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ssh_key = (
|
||||||
|
get_val("GITEA_SSH_KEY")
|
||||||
|
or (cls._extract_sops_key(["gitea", "ssh_key"], persona_sops) if persona_sops else None)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not gitea_token:
|
||||||
|
print(
|
||||||
|
f"Error: Unable to resolve Gitea API token for persona '{gitea_user}'.\n"
|
||||||
|
"To provide credentials for this persona, either:\n"
|
||||||
|
" 1. Export GITEA_TOKEN in your environment (or define in a .env file)\n"
|
||||||
|
f" 2. Add 'gitea.token' or 'gitea.api_token' to ~/Config/secrets.{persona_norm}.yaml (or {persona_norm}-secrets.yaml) via SOPS\n"
|
||||||
|
f" 3. Authenticate the persona using 'gt auth login --user {gitea_user}'\n\n"
|
||||||
|
"Note: In Gitea, generate a token at: User Settings -> Applications -> Manage Access Tokens.",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not github_token:
|
||||||
|
print(
|
||||||
|
f"Error: Unable to resolve GitHub API token for persona '{github_user}'.\n"
|
||||||
|
"To provide credentials for this persona, either:\n"
|
||||||
|
" 1. Export GITHUB_TOKEN in your environment (or define in a .env file)\n"
|
||||||
|
f" 2. Add 'github.token' or 'github.api_token' to ~/Config/secrets.{persona_norm}.yaml (or {persona_norm}-secrets.yaml) via SOPS\n",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
gitea_user = get_val("GITEA_USER") or tea_user or "kiskaadee"
|
# ------------------------------------------------------------------
|
||||||
|
# Default / Root User Credential Resolution
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
secrets_file_env = os.environ.get("SECRETS_FILE")
|
||||||
|
config_secrets = (
|
||||||
|
Path(secrets_file_env)
|
||||||
|
if secrets_file_env
|
||||||
|
else Path.home() / "Config" / "secrets.yaml"
|
||||||
|
)
|
||||||
|
homelab_secrets_env = os.environ.get("HOMELAB_SECRETS_FILE")
|
||||||
|
homelab_candidates = [
|
||||||
|
Path(homelab_secrets_env) if homelab_secrets_env else None,
|
||||||
|
Path.home() / "Homelab" / "secrets.yaml",
|
||||||
|
Path.home() / "Homelab" / "Core" / "nixos" / "secrets.yaml",
|
||||||
|
]
|
||||||
|
homelab_secrets = next((p for p in homelab_candidates if p and p.is_file()), None)
|
||||||
|
|
||||||
|
gitea_user = get_val("GITEA_USER") or "kiskaadee"
|
||||||
gitea_token = (
|
gitea_token = (
|
||||||
get_val("GITEA_TOKEN")
|
get_val("GITEA_TOKEN")
|
||||||
|
or cls._extract_sops_key(["gitea", "token"], config_secrets)
|
||||||
or cls._extract_sops_key(["gitea", "api_token"], config_secrets)
|
or cls._extract_sops_key(["gitea", "api_token"], config_secrets)
|
||||||
or tea_token
|
or (cls._extract_sops_key(["gitea", "token"], homelab_secrets) if homelab_secrets else None)
|
||||||
|
or (cls._extract_sops_key(["gitea", "api_token"], homelab_secrets) if homelab_secrets else None)
|
||||||
|
or cls._extract_gt_token()
|
||||||
)
|
)
|
||||||
|
|
||||||
github_user = get_val("GITHUB_USER") or "kiskaadee"
|
github_user = get_val("GITHUB_USER") or "kiskaadee"
|
||||||
github_token = (
|
github_token = (
|
||||||
get_val("GITHUB_TOKEN")
|
get_val("GITHUB_TOKEN")
|
||||||
or cls._extract_sops_key(["system", "gh_repo_token"], config_secrets)
|
or cls._extract_sops_key(["system", "gh_repo_token"], config_secrets)
|
||||||
or cls._extract_sops_key(["system", "gh_repo_token"], homelab_secrets)
|
or cls._extract_sops_key(["github", "token"], config_secrets)
|
||||||
|
or (cls._extract_sops_key(["system", "gh_repo_token"], homelab_secrets) if homelab_secrets else None)
|
||||||
|
or (cls._extract_sops_key(["github", "token"], homelab_secrets) if homelab_secrets else None)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not gitea_token:
|
ssh_key = (
|
||||||
print(
|
get_val("GITEA_SSH_KEY")
|
||||||
f"Error: Unable to resolve Gitea API token for persona '{gitea_user}'.\n"
|
or cls._extract_sops_key(["gitea", "ssh_key"], config_secrets)
|
||||||
"To provide credentials, either:\n"
|
or (cls._extract_sops_key(["gitea", "ssh_key"], homelab_secrets) if homelab_secrets else None)
|
||||||
" 1. Export GITEA_TOKEN in your environment (or define in a .env file)\n"
|
|
||||||
" 2. Add 'gitea.api_token' to ~/Config/secrets.yaml via SOPS\n"
|
|
||||||
" 3. Configure tea CLI via 'tea login add'\n"
|
|
||||||
"\n"
|
|
||||||
"Note: In Gitea, generate a token at: User Settings -> Applications -> Manage Access Tokens.",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not github_token:
|
if not gitea_token:
|
||||||
print(
|
print(
|
||||||
f"Error: Unable to resolve GitHub API token for persona '{github_user}'.\n"
|
f"Error: Unable to resolve Gitea API token for user '{gitea_user}'.\n"
|
||||||
"To provide credentials, either:\n"
|
"To provide credentials, either:\n"
|
||||||
" 1. Export GITHUB_TOKEN in your environment (or define in a .env file)\n"
|
" 1. Export GITEA_TOKEN in your environment (or define in a .env file)\n"
|
||||||
" 2. Add 'system.gh_repo_token' to ~/Config/secrets.yaml via SOPS\n",
|
" 2. Add 'gitea.api_token' to ~/Config/secrets.yaml via SOPS\n"
|
||||||
file=sys.stderr,
|
" 3. Authenticate using 'gt auth login'\n\n"
|
||||||
)
|
"Note: In Gitea, generate a token at: User Settings -> Applications -> Manage Access Tokens.",
|
||||||
sys.exit(1)
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not github_token:
|
||||||
|
print(
|
||||||
|
f"Error: Unable to resolve GitHub API token for user '{github_user}'.\n"
|
||||||
|
"To provide credentials, either:\n"
|
||||||
|
" 1. Export GITHUB_TOKEN in your environment (or define in a .env file)\n"
|
||||||
|
" 2. Add 'system.gh_repo_token' to ~/Config/secrets.yaml via SOPS\n",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
return Credentials(
|
return Credentials(
|
||||||
gitea_url=gitea_url,
|
gitea_url=gitea_url,
|
||||||
@@ -305,7 +321,7 @@ class SecretProvider:
|
|||||||
gitea_token=gitea_token,
|
gitea_token=gitea_token,
|
||||||
github_user=github_user,
|
github_user=github_user,
|
||||||
github_token=github_token,
|
github_token=github_token,
|
||||||
ssh_key=tea_ssh_key,
|
ssh_key=ssh_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -407,9 +423,20 @@ class GiteaClient:
|
|||||||
msg = err_data.get("message", raw_err)
|
msg = err_data.get("message", raw_err)
|
||||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||||
msg = raw_err
|
msg = raw_err
|
||||||
raise RuntimeError(f"Gitea API error ({e.code} {e.reason}): {msg}") from e
|
payload_tokens = []
|
||||||
|
if payload and isinstance(payload, dict):
|
||||||
|
for k in ("remote_password", "auth_token", "token", "password"):
|
||||||
|
v = payload.get(k)
|
||||||
|
if isinstance(v, str):
|
||||||
|
payload_tokens.append(v)
|
||||||
|
sanitized_msg = redact_sensitive(msg, self.token, *payload_tokens)
|
||||||
|
sanitized_reason = redact_sensitive(str(e.reason), self.token, *payload_tokens)
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Gitea API error ({e.code} {sanitized_reason}): {sanitized_msg}"
|
||||||
|
) from e
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
raise RuntimeError(f"Gitea network error: {e.reason}") from e
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
|
raise RuntimeError(f"Gitea network error: {sanitized_reason}") from e
|
||||||
|
|
||||||
def get_authenticated_user(self) -> str:
|
def get_authenticated_user(self) -> str:
|
||||||
"""Return the authenticated username associated with the token."""
|
"""Return the authenticated username associated with the token."""
|
||||||
@@ -437,11 +464,14 @@ class GiteaClient:
|
|||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
return False
|
return False
|
||||||
raw_err = e.read().decode("utf-8", errors="replace")
|
raw_err = e.read().decode("utf-8", errors="replace")
|
||||||
|
sanitized_err = redact_sensitive(raw_err, self.token)
|
||||||
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Gitea API error checking org '{org}' ({e.code} {e.reason}): {raw_err}"
|
f"Gitea API error checking org '{org}' ({e.code} {sanitized_reason}): {sanitized_err}"
|
||||||
) from e
|
) from e
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
raise RuntimeError(f"Gitea network error: {e.reason}") from e
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
|
raise RuntimeError(f"Gitea network error: {sanitized_reason}") from e
|
||||||
|
|
||||||
def create_org(
|
def create_org(
|
||||||
self,
|
self,
|
||||||
@@ -534,11 +564,14 @@ class GiteaClient:
|
|||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
return False
|
return False
|
||||||
raw_err = e.read().decode("utf-8", errors="replace")
|
raw_err = e.read().decode("utf-8", errors="replace")
|
||||||
|
sanitized_err = redact_sensitive(raw_err, self.token)
|
||||||
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Gitea API error ({e.code} {e.reason}): {raw_err}"
|
f"Gitea API error ({e.code} {sanitized_reason}): {sanitized_err}"
|
||||||
) from e
|
) from e
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
raise RuntimeError(f"Gitea network error: {e.reason}") from e
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
|
raise RuntimeError(f"Gitea network error: {sanitized_reason}") from e
|
||||||
|
|
||||||
def migrate_repo(
|
def migrate_repo(
|
||||||
self,
|
self,
|
||||||
@@ -643,9 +676,14 @@ class GitHubClient:
|
|||||||
msg = err_data.get("message", raw_err)
|
msg = err_data.get("message", raw_err)
|
||||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||||
msg = raw_err
|
msg = raw_err
|
||||||
raise RuntimeError(f"GitHub API error ({e.code} {e.reason}): {msg}") from e
|
sanitized_msg = redact_sensitive(msg, self.token)
|
||||||
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
|
raise RuntimeError(
|
||||||
|
f"GitHub API error ({e.code} {sanitized_reason}): {sanitized_msg}"
|
||||||
|
) from e
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
raise RuntimeError(f"GitHub network error: {e.reason}") from e
|
sanitized_reason = redact_sensitive(str(e.reason), self.token)
|
||||||
|
raise RuntimeError(f"GitHub network error: {sanitized_reason}") from e
|
||||||
|
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
@@ -1021,7 +1059,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
dest="as_persona",
|
dest="as_persona",
|
||||||
type=str,
|
type=str,
|
||||||
default=None,
|
default=None,
|
||||||
help="Persona / login identity to provision as (matches tea login name or SOPS persona, e.g. anneux)",
|
help="Persona / login identity to provision as (e.g. anneux)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--migrate",
|
"--migrate",
|
||||||
|
|||||||
Reference in new issue
Block a user