Audit (campus.audit)¶
The /audit/v1 service: trace ingestion and queries, plus management
of the audit service's own API keys. The audit root authenticates with
an audit_v1_... key (AUDIT_API_KEY) as its Bearer — client-secret
Basic auth is rejected by the service.
Ingestion feeds the client-side circuit breaker before raising: a 429 trips the bucket (Retry-After honored), 2xx clears expired trips, and a breaker failure never breaks ingestion. See Tracing for how spans attribute to journeys.
campus.model.* types referenced here are documented in the
campus repo.
Traces¶
campus_python.audit.v1.traces.Traces
¶
Bases: ResourceCollection
Campus Audit traces resource.
Source code in campus_python/audit/v1/traces.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
path = 'traces'
class-attribute
instance-attribute
¶
Trace
¶
Bases: Resource
Single campus audit trace resource.
Source code in campus_python/audit/v1/traces.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
spans: Traces.Trace.Spans
property
¶
Get the spans resource for this trace.
Spans
¶
Bases: Resource
Spans of a single trace.
Source code in campus_python/audit/v1/traces.py
155 156 157 158 159 160 161 162 163 164 | |
__getitem__(span_id: str) -> Traces.Trace.Span
¶
Get a specific span resource by ID.
Source code in campus_python/audit/v1/traces.py
158 159 160 | |
list() -> list[JsonDict]
¶
List all spans in this trace (flat).
Source code in campus_python/audit/v1/traces.py
162 163 164 | |
Span
¶
Bases: Resource
Single span of a trace, with full request/response detail.
Source code in campus_python/audit/v1/traces.py
166 167 168 169 170 171 | |
get() -> JsonDict
¶
Get this span with full request/response detail.
Source code in campus_python/audit/v1/traces.py
169 170 171 | |
get() -> JsonDict
¶
Get the full trace tree.
Returns:
| Type | Description |
|---|---|
JsonDict
|
{"trace_id": ..., "root_span": |
Source code in campus_python/audit/v1/traces.py
147 148 149 150 151 152 153 | |
__getitem__(trace_id: str) -> Traces.Trace
¶
Get a specific trace resource by ID.
Source code in campus_python/audit/v1/traces.py
28 29 30 | |
ingest(spans: list[dict[str, Any]]) -> JsonDict
¶
Ingest a batch of trace spans.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spans
|
list[dict[str, Any]]
|
Span dicts shaped like the server's TraceSpan resource (trace_id, span_id, method, path, ...) |
required |
Returns:
| Type | Description |
|---|---|
JsonDict
|
201 full success: {"created": [...]}; 207 partial failure |
JsonDict
|
adds {"failed": [...]} with per-span statuses. |
Source code in campus_python/audit/v1/traces.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
list(*, since: str | None = None, until: str | None = None, limit: int | None = None, cursor: str | None = None) -> JsonDict
¶
List recent traces, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since
|
str | None
|
ISO 8601 lower bound |
None
|
until
|
str | None
|
ISO 8601 upper bound |
None
|
limit
|
int | None
|
Page size (server clamps to its max) |
None
|
cursor
|
str | None
|
Opaque token from a previous page's cursor.next |
None
|
Returns:
| Type | Description |
|---|---|
JsonDict
|
{"traces": [...], "cursor": {"next": ..., "has_more": bool}} |
Source code in campus_python/audit/v1/traces.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
search(*, path: str | None = None, status: int | str | None = None, api_key_id: str | None = None, client_id: str | None = None, user_id: str | None = None, journey_id: str | None = None, since: str | None = None, until: str | None = None, limit: int | None = None, cursor: str | None = None) -> JsonDict
¶
Filter and search traces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Filter by endpoint path |
None
|
status
|
int | str | None
|
Filter by HTTP status code |
None
|
api_key_id
|
str | None
|
Filter by audit API key |
None
|
client_id
|
str | None
|
Filter by OAuth client |
None
|
user_id
|
str | None
|
Filter by user |
None
|
journey_id
|
str | None
|
Filter by login-journey tag (campus#803) |
None
|
since
|
str | None
|
ISO 8601 lower bound (as in list()) |
None
|
until
|
str | None
|
ISO 8601 upper bound (as in list()) |
None
|
limit
|
int | None
|
Page size (as in list()) |
None
|
cursor
|
str | None
|
Page token (as in list()) |
None
|
Returns:
| Type | Description |
|---|---|
JsonDict
|
{"traces": [...], "cursor": {"next": ..., "has_more": bool}} |
Source code in campus_python/audit/v1/traces.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
APIKeys¶
campus_python.audit.v1.apikeys.APIKeys
¶
Bases: ResourceCollection
Campus Audit API keys resource.
Every write takes a privilege set: either a scope list or a named role the service resolves to one.
Source code in campus_python/audit/v1/apikeys.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
path = 'apikeys'
class-attribute
instance-attribute
¶
APIKey
¶
Bases: Resource
Single campus audit API key resource.
update() takes a privilege set too: a scope list or a named role.
Source code in campus_python/audit/v1/apikeys.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get() -> JsonDict
¶
Get this API key's record (no key hash or plaintext).
Source code in campus_python/audit/v1/apikeys.py
117 118 119 | |
update(*, name: str | None = None, scopes: list[str] | None = None, role: str | None = None, rate_limit: int | None = None) -> JsonDict
¶
Update this API key's mutable fields.
Only name, scopes, and rate_limit are mutable; use revoke() to disable the key. The server rejects an empty update, so at least one field must be provided.
A role re-scopes the key to the scope list the service
resolves that role to. It is mutually exclusive with
scopes server-side: sending both is refused (422) rather
than one silently winning, so this method does not
pre-judge them.
Returns:
| Type | Description |
|---|---|
JsonDict
|
The updated key record |
Source code in campus_python/audit/v1/apikeys.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
revoke() -> None
¶
Revoke this API key (the record is kept for audit).
Source code in campus_python/audit/v1/apikeys.py
151 152 153 154 | |
regenerate() -> str
¶
Regenerate this API key's value.
The old value stops working immediately.
Returns:
| Type | Description |
|---|---|
str
|
The new plaintext key value, shown only here. |
Source code in campus_python/audit/v1/apikeys.py
156 157 158 159 160 161 162 163 164 165 166 | |
__getitem__(api_key_id: str) -> APIKeys.APIKey
¶
Get a specific API key resource by ID.
Source code in campus_python/audit/v1/apikeys.py
37 38 39 | |
new(*, name: str, owner_id: str, scopes: list[str] | None = None, role: str | None = None, rate_limit: int | None = None, expires_at: str | None = None) -> JsonDict
¶
Create an API key.
Give either scopes or a named role — the service resolves a
role to exactly one scope list. The two are mutually exclusive
server-side: sending both is refused (422) rather than one
silently winning, so this method does not pre-judge them. An
unknown role is likewise refused, with the server naming the
roles that exist — the catalogue is the service's, so it is not
duplicated here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Key name |
required |
owner_id
|
str
|
Owner user ID |
required |
scopes
|
list[str] | None
|
Scope strings the key grants (e.g. ["traces:read"]) |
None
|
role
|
str | None
|
A named role the service resolves to a scope list |
None
|
rate_limit
|
int | None
|
Requests per minute (optional) |
None
|
expires_at
|
str | None
|
ISO 8601 expiry (optional) |
None
|
Returns:
| Type | Description |
|---|---|
JsonDict
|
The created key record; its plaintext |
JsonDict
|
shown only here. |
Source code in campus_python/audit/v1/apikeys.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
list(*, owner_id: str | None = None, active_only: bool = True, limit: int | None = None) -> JsonDict
¶
List API keys with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner_id
|
str | None
|
Filter by owner user ID |
None
|
active_only
|
bool
|
Only non-expired, non-revoked keys (default True) |
True
|
limit
|
int | None
|
Page size (server default 50) |
None
|
Returns:
| Type | Description |
|---|---|
JsonDict
|
{"api_keys": [...], "count": int} |
Source code in campus_python/audit/v1/apikeys.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
AuditRoot¶
campus_python.audit.v1.AuditRoot
¶
Bases: ResourceRoot
Campus Audit service resource.
Source code in campus_python/audit/v1/__init__.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
url_prefix = '/audit/v1'
class-attribute
instance-attribute
¶
apikeys: apikeys.APIKeys
property
¶
Get the API keys resource.
traces: traces.Traces
property
¶
Get the traces resource.
__init__(json_client: JsonClient)
¶
Source code in campus_python/audit/v1/__init__.py
20 21 22 23 | |