763e06c127
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.9 KiB
Python
75 lines
2.9 KiB
Python
"""Muestra un perfil Chromium del catalogo osint_db con todas sus cuentas.
|
|
|
|
Wrapper cliente del service local `osint_db`: hace dos POST /api/query (read-only):
|
|
1. El perfil (1 fila de `browser_profiles` WHERE profile_dir=?).
|
|
2. Sus cuentas (N filas de `browser_profile_accounts` WHERE profile_dir=?).
|
|
|
|
Funcion impura: hace red (HTTP al service). No lanza; devuelve un dict de estado.
|
|
"""
|
|
|
|
from browser._osint_db_client import query, rows_to_dicts
|
|
|
|
_SQL_PROFILE = (
|
|
"SELECT profile_dir, user_data_dir, label, persona, purpose, status, note_path, "
|
|
"tags, notes, created_at, updated_at "
|
|
"FROM browser_profiles WHERE profile_dir = ?"
|
|
)
|
|
|
|
_SQL_ACCOUNTS = (
|
|
"SELECT id, profile_dir, service, identity, secret_ref, role, status, notes, "
|
|
"created_at, updated_at "
|
|
"FROM browser_profile_accounts WHERE profile_dir = ? ORDER BY service, identity"
|
|
)
|
|
|
|
|
|
def browser_profile_show(
|
|
profile_dir: str,
|
|
base_url: str = "http://127.0.0.1:8771",
|
|
) -> dict:
|
|
"""Muestra un perfil Chromium concreto con todas sus cuentas.
|
|
|
|
Args:
|
|
profile_dir: nombre del directorio real del perfil Chromium (ej. "Profile 1",
|
|
"osint_01"). Es la PK por la que se busca.
|
|
base_url: base del service osint_db. Default http://127.0.0.1:8771.
|
|
|
|
Returns:
|
|
Caso ok: {"status":"ok", "profile": dict (metadata del perfil),
|
|
"accounts": list de dicts (cuentas, posiblemente vacia)}.
|
|
Caso no existe: {"status":"error", "error": "perfil no encontrado: <profile_dir>"}.
|
|
Caso error (service caido o query rechazada): {"status":"error", "error": str}.
|
|
"""
|
|
try:
|
|
prof_resp = query(base_url, _SQL_PROFILE, [profile_dir], max_rows=1)
|
|
if prof_resp.get("status") != "ok":
|
|
return {
|
|
"status": "error",
|
|
"error": prof_resp.get("error", f"el service rechazo la query: {prof_resp}"),
|
|
}
|
|
profiles = rows_to_dicts(prof_resp)
|
|
if not profiles:
|
|
return {"status": "error", "error": f"perfil no encontrado: {profile_dir}"}
|
|
|
|
acc_resp = query(base_url, _SQL_ACCOUNTS, [profile_dir])
|
|
if acc_resp.get("status") != "ok":
|
|
return {
|
|
"status": "error",
|
|
"error": acc_resp.get("error", f"el service rechazo la query de cuentas: {acc_resp}"),
|
|
}
|
|
|
|
return {
|
|
"status": "ok",
|
|
"profile": profiles[0],
|
|
"accounts": rows_to_dicts(acc_resp),
|
|
}
|
|
except Exception as e: # noqa: BLE001 - contrato: nunca lanzar
|
|
return {"status": "error", "error": f"{type(e).__name__}: {e}"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Smoke contra un puerto muerto: ejercita la degradacion graceful (service inaccesible).
|
|
res = browser_profile_show("Profile 1", base_url="http://127.0.0.1:1")
|
|
assert res["status"] == "error", res
|
|
print("browser_profile_show smoke OK (service caido -> status error)")
|
|
print(f" {res}")
|