forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_keys.py
More file actions
42 lines (36 loc) · 1.29 KB
/
Copy pathapi_keys.py
File metadata and controls
42 lines (36 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import logging
from collections.abc import Collection
from typing import Literal
from utils.observability.fallback import record_fallback
ApiKeyKind = Literal["mcp", "dev"]
ApiKeyRepairOperation = Literal["list", "auth"]
def record_api_key_repairs(
*,
key_kind: ApiKeyKind,
operation: ApiKeyRepairOperation,
repairs: Collection[object],
log: logging.Logger,
) -> None:
"""Record one bounded event when a key operation repairs internal state."""
if not repairs:
return
repair_values = {getattr(repair, "value", repair) for repair in repairs}
outcome = "degraded" if operation == "list" or (key_kind == "dev" and "scopes" in repair_values) else "recovered"
record_fallback(
component="other",
from_mode=f"{key_kind}_stored_{operation}",
to_mode=f"{key_kind}_safe_{operation}",
reason="local_heal",
outcome=outcome,
log=log,
)
def record_api_key_revocation_exhausted(*, key_kind: ApiKeyKind, log: logging.Logger) -> None:
"""Record a revocation that stopped before deleting persistent state."""
record_fallback(
component="other",
from_mode=f"{key_kind}_revocation_cache",
to_mode=f"{key_kind}_revocation_blocked",
reason="auth",
outcome="exhausted",
log=log,
)