19 lines
685 B
Python
19 lines
685 B
Python
import hashlib, json
|
|
from datetime import datetime, timezone
|
|
|
|
def now() -> str:
|
|
return datetime.now(timezone.utc).isoformat()
|
|
|
|
def digest(value: bytes | str) -> str:
|
|
return hashlib.sha256(value if isinstance(value, bytes) else value.encode()).hexdigest()
|
|
|
|
def stable_id(tenant: str, source: str, item: str) -> str:
|
|
return digest(f"{tenant}:{source}:{item}")[:32]
|
|
|
|
def require_scope(scope: dict, keys: tuple[str, ...]) -> None:
|
|
if any(not scope.get(key) for key in keys):
|
|
raise ValueError(f"missing required scope: {', '.join(keys)}")
|
|
|
|
def json_headers(token: str) -> dict[str, str]:
|
|
return {"Authorization": f"Bearer {token}", "Accept": "application/json"}
|