Repository navigation
Expand file tree
/
Copy pathaudit.py
More file actions
61 lines (51 loc) · 2.17 KB
/
Copy pathaudit.py
File metadata and controls
61 lines (51 loc) · 2.17 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Audit log access.
STACK writes the record for every account; reading it is a controls feature, so without controls every call
here raises ``ControlsRequiredError`` (402 ``CONTROLS_REQUIRED``). Switching controls on shows all of it,
including what came before. A self-managed install has every controls feature.
"""
from __future__ import annotations
from typing import Any, cast
from .client import HttpClient
class AuditService:
def __init__(self, client: HttpClient):
self._client = client
def list(
self,
limit: int = 20,
since: int | None = None,
agent_id: str | None = None,
passport_jti: str | None = None,
) -> dict[str, Any]:
"""Tail recent audit entries (newest-first).
Returns ``{"entries": [...], "max_timestamp": int | None}``.
Pass ``since`` (epoch ms) to fetch only entries newer than the
last seen timestamp — useful for incremental polling. Pass
``agent_id`` or ``passport_jti`` to narrow to a single agent
or single passport.
"""
params: dict[str, str] = {"limit": str(limit)}
if since is not None:
params["since"] = str(since)
if agent_id is not None:
params["agent_id"] = agent_id
if passport_jti is not None:
params["passport_jti"] = passport_jti
return cast("dict[str, Any]", self._client.get("/v1/audit", params=params))
def chain_head(self) -> dict[str, Any]:
"""Current chain head — latest entry hash + entry count."""
return cast("dict[str, Any]", self._client.get("/v1/audit/chain-head"))
def verify_chain(
self,
from_date: str | None = None,
to_date: str | None = None,
limit: int | None = None,
) -> dict[str, Any]:
"""Walk the per-operator chain and report tamper status."""
params: dict[str, str] = {}
if from_date is not None:
params["from"] = from_date
if to_date is not None:
params["to"] = to_date
if limit is not None:
params["limit"] = str(limit)
return cast("dict[str, Any]", self._client.get("/v1/audit/verify-chain", params=params))