Skip to content

Commit e80d150

Browse files
feat: Add hidden audit-logs export endpoint
1 parent 70d4214 commit e80d150

6 files changed

Lines changed: 392 additions & 6 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 124
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-4c243ff089133bd49322d98a6943647589972f71ecadc993fe9e5029972b3995.yml
3-
openapi_spec_hash: a2cb637a19a070d07a1a4343c75444ee
4-
config_hash: fb167e754ebb3a14649463725891c9d0
1+
configured_endpoints: 125
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-55409ab573762d8bc010fb34c885651ca858a97d4353b4776b7aafeaaa313257.yml
3+
openapi_spec_hash: 0cf678d80f2a2b73fb9ec82d05c8cc0a
4+
config_hash: 06186eb40e0058a2a87ac251fc07415d

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ from kernel.types import AuditLogEntry
454454
Methods:
455455

456456
- <code title="get /audit-logs">client.audit_logs.<a href="./src/kernel/resources/audit_logs.py">list</a>(\*\*<a href="src/kernel/types/audit_log_list_params.py">params</a>) -> <a href="./src/kernel/types/audit_log_entry.py">SyncPageTokenPagination[AuditLogEntry]</a></code>
457+
- <code title="get /audit-logs/export/chunk">client.audit_logs.<a href="./src/kernel/resources/audit_logs.py">export_chunk</a>(\*\*<a href="src/kernel/types/audit_log_export_chunk_params.py">params</a>) -> BinaryAPIResponse</code>
457458

458459
# APIKeys
459460

src/kernel/resources/audit_logs.py

Lines changed: 197 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44

55
from typing import Union
66
from datetime import datetime
7+
from typing_extensions import Literal
78

89
import httpx
910

10-
from ..types import audit_log_list_params
11+
from ..types import audit_log_list_params, audit_log_export_chunk_params
1112
from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
12-
from .._utils import maybe_transform
13+
from .._utils import maybe_transform, async_maybe_transform
1314
from .._compat import cached_property
1415
from .._resource import SyncAPIResource, AsyncAPIResource
1516
from .._response import (
17+
BinaryAPIResponse,
18+
AsyncBinaryAPIResponse,
19+
StreamedBinaryAPIResponse,
20+
AsyncStreamedBinaryAPIResponse,
1621
to_raw_response_wrapper,
1722
to_streamed_response_wrapper,
1823
async_to_raw_response_wrapper,
24+
to_custom_raw_response_wrapper,
1925
async_to_streamed_response_wrapper,
26+
to_custom_streamed_response_wrapper,
27+
async_to_custom_raw_response_wrapper,
28+
async_to_custom_streamed_response_wrapper,
2029
)
2130
from ..pagination import SyncPageTokenPagination, AsyncPageTokenPagination
2231
from .._base_client import AsyncPaginator, make_request_options
@@ -128,6 +137,91 @@ def list(
128137
model=AuditLogEntry,
129138
)
130139

140+
def export_chunk(
141+
self,
142+
*,
143+
end: Union[str, datetime],
144+
start: Union[str, datetime],
145+
auth_strategy: str | Omit = omit,
146+
cursor: str | Omit = omit,
147+
exclude_method: str | Omit = omit,
148+
format: Literal["jsonl", "jsonl.gz"] | Omit = omit,
149+
limit: int | Omit = omit,
150+
method: str | Omit = omit,
151+
search: str | Omit = omit,
152+
search_user_id: SequenceNotStr[str] | Omit = omit,
153+
service: str | Omit = omit,
154+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
155+
# The extra values given here take precedence over values defined on the client or passed to this method.
156+
extra_headers: Headers | None = None,
157+
extra_query: Query | None = None,
158+
extra_body: Body | None = None,
159+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
160+
) -> BinaryAPIResponse:
161+
"""
162+
Download an organization's audit log records for a time range as a file, for
163+
archival, compliance, or offline analysis. For interactive browsing, use GET
164+
/audit-logs.
165+
166+
Args:
167+
end: Upper bound (exclusive) for the audit record timestamp.
168+
169+
start: Lower bound (inclusive) for the audit record timestamp.
170+
171+
auth_strategy: Filter by authentication strategy.
172+
173+
cursor: Opaque cursor from X-Next-Cursor for the next chunk of older records.
174+
175+
exclude_method: Filter out results by HTTP method.
176+
177+
format: Encoding for the returned chunk.
178+
179+
limit: Maximum number of records to return in this chunk.
180+
181+
method: Filter by HTTP method.
182+
183+
search: Free-text search over path, user ID, email, client IP, and status.
184+
185+
search_user_id: Additional user IDs to OR into free-text search.
186+
187+
service: Filter by service name.
188+
189+
extra_headers: Send extra headers
190+
191+
extra_query: Add additional query parameters to the request
192+
193+
extra_body: Add additional JSON properties to the request
194+
195+
timeout: Override the client-level default timeout for this request, in seconds
196+
"""
197+
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
198+
return self._get(
199+
"/audit-logs/export/chunk",
200+
options=make_request_options(
201+
extra_headers=extra_headers,
202+
extra_query=extra_query,
203+
extra_body=extra_body,
204+
timeout=timeout,
205+
query=maybe_transform(
206+
{
207+
"end": end,
208+
"start": start,
209+
"auth_strategy": auth_strategy,
210+
"cursor": cursor,
211+
"exclude_method": exclude_method,
212+
"format": format,
213+
"limit": limit,
214+
"method": method,
215+
"search": search,
216+
"search_user_id": search_user_id,
217+
"service": service,
218+
},
219+
audit_log_export_chunk_params.AuditLogExportChunkParams,
220+
),
221+
),
222+
cast_to=BinaryAPIResponse,
223+
)
224+
131225

132226
class AsyncAuditLogsResource(AsyncAPIResource):
133227
"""Read audit log records for the authenticated organization."""
@@ -232,6 +326,91 @@ def list(
232326
model=AuditLogEntry,
233327
)
234328

329+
async def export_chunk(
330+
self,
331+
*,
332+
end: Union[str, datetime],
333+
start: Union[str, datetime],
334+
auth_strategy: str | Omit = omit,
335+
cursor: str | Omit = omit,
336+
exclude_method: str | Omit = omit,
337+
format: Literal["jsonl", "jsonl.gz"] | Omit = omit,
338+
limit: int | Omit = omit,
339+
method: str | Omit = omit,
340+
search: str | Omit = omit,
341+
search_user_id: SequenceNotStr[str] | Omit = omit,
342+
service: str | Omit = omit,
343+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
344+
# The extra values given here take precedence over values defined on the client or passed to this method.
345+
extra_headers: Headers | None = None,
346+
extra_query: Query | None = None,
347+
extra_body: Body | None = None,
348+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
349+
) -> AsyncBinaryAPIResponse:
350+
"""
351+
Download an organization's audit log records for a time range as a file, for
352+
archival, compliance, or offline analysis. For interactive browsing, use GET
353+
/audit-logs.
354+
355+
Args:
356+
end: Upper bound (exclusive) for the audit record timestamp.
357+
358+
start: Lower bound (inclusive) for the audit record timestamp.
359+
360+
auth_strategy: Filter by authentication strategy.
361+
362+
cursor: Opaque cursor from X-Next-Cursor for the next chunk of older records.
363+
364+
exclude_method: Filter out results by HTTP method.
365+
366+
format: Encoding for the returned chunk.
367+
368+
limit: Maximum number of records to return in this chunk.
369+
370+
method: Filter by HTTP method.
371+
372+
search: Free-text search over path, user ID, email, client IP, and status.
373+
374+
search_user_id: Additional user IDs to OR into free-text search.
375+
376+
service: Filter by service name.
377+
378+
extra_headers: Send extra headers
379+
380+
extra_query: Add additional query parameters to the request
381+
382+
extra_body: Add additional JSON properties to the request
383+
384+
timeout: Override the client-level default timeout for this request, in seconds
385+
"""
386+
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
387+
return await self._get(
388+
"/audit-logs/export/chunk",
389+
options=make_request_options(
390+
extra_headers=extra_headers,
391+
extra_query=extra_query,
392+
extra_body=extra_body,
393+
timeout=timeout,
394+
query=await async_maybe_transform(
395+
{
396+
"end": end,
397+
"start": start,
398+
"auth_strategy": auth_strategy,
399+
"cursor": cursor,
400+
"exclude_method": exclude_method,
401+
"format": format,
402+
"limit": limit,
403+
"method": method,
404+
"search": search,
405+
"search_user_id": search_user_id,
406+
"service": service,
407+
},
408+
audit_log_export_chunk_params.AuditLogExportChunkParams,
409+
),
410+
),
411+
cast_to=AsyncBinaryAPIResponse,
412+
)
413+
235414

236415
class AuditLogsResourceWithRawResponse:
237416
def __init__(self, audit_logs: AuditLogsResource) -> None:
@@ -240,6 +419,10 @@ def __init__(self, audit_logs: AuditLogsResource) -> None:
240419
self.list = to_raw_response_wrapper(
241420
audit_logs.list,
242421
)
422+
self.export_chunk = to_custom_raw_response_wrapper(
423+
audit_logs.export_chunk,
424+
BinaryAPIResponse,
425+
)
243426

244427

245428
class AsyncAuditLogsResourceWithRawResponse:
@@ -249,6 +432,10 @@ def __init__(self, audit_logs: AsyncAuditLogsResource) -> None:
249432
self.list = async_to_raw_response_wrapper(
250433
audit_logs.list,
251434
)
435+
self.export_chunk = async_to_custom_raw_response_wrapper(
436+
audit_logs.export_chunk,
437+
AsyncBinaryAPIResponse,
438+
)
252439

253440

254441
class AuditLogsResourceWithStreamingResponse:
@@ -258,6 +445,10 @@ def __init__(self, audit_logs: AuditLogsResource) -> None:
258445
self.list = to_streamed_response_wrapper(
259446
audit_logs.list,
260447
)
448+
self.export_chunk = to_custom_streamed_response_wrapper(
449+
audit_logs.export_chunk,
450+
StreamedBinaryAPIResponse,
451+
)
261452

262453

263454
class AsyncAuditLogsResourceWithStreamingResponse:
@@ -267,3 +458,7 @@ def __init__(self, audit_logs: AsyncAuditLogsResource) -> None:
267458
self.list = async_to_streamed_response_wrapper(
268459
audit_logs.list,
269460
)
461+
self.export_chunk = async_to_custom_streamed_response_wrapper(
462+
audit_logs.export_chunk,
463+
AsyncStreamedBinaryAPIResponse,
464+
)

src/kernel/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from .browser_pool_release_params import BrowserPoolReleaseParams as BrowserPoolReleaseParams
9191
from .deployment_retrieve_response import DeploymentRetrieveResponse as DeploymentRetrieveResponse
9292
from .invocation_retrieve_response import InvocationRetrieveResponse as InvocationRetrieveResponse
93+
from .audit_log_export_chunk_params import AuditLogExportChunkParams as AuditLogExportChunkParams
9394
from .browser_pool_acquire_response import BrowserPoolAcquireResponse as BrowserPoolAcquireResponse
9495
from .credential_totp_code_response import CredentialTotpCodeResponse as CredentialTotpCodeResponse
9596
from .browser_load_extensions_params import BrowserLoadExtensionsParams as BrowserLoadExtensionsParams
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Union
6+
from datetime import datetime
7+
from typing_extensions import Literal, Required, Annotated, TypedDict
8+
9+
from .._types import SequenceNotStr
10+
from .._utils import PropertyInfo
11+
12+
__all__ = ["AuditLogExportChunkParams"]
13+
14+
15+
class AuditLogExportChunkParams(TypedDict, total=False):
16+
end: Required[Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]]
17+
"""Upper bound (exclusive) for the audit record timestamp."""
18+
19+
start: Required[Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]]
20+
"""Lower bound (inclusive) for the audit record timestamp."""
21+
22+
auth_strategy: str
23+
"""Filter by authentication strategy."""
24+
25+
cursor: str
26+
"""Opaque cursor from X-Next-Cursor for the next chunk of older records."""
27+
28+
exclude_method: str
29+
"""Filter out results by HTTP method."""
30+
31+
format: Literal["jsonl", "jsonl.gz"]
32+
"""Encoding for the returned chunk."""
33+
34+
limit: int
35+
"""Maximum number of records to return in this chunk."""
36+
37+
method: str
38+
"""Filter by HTTP method."""
39+
40+
search: str
41+
"""Free-text search over path, user ID, email, client IP, and status."""
42+
43+
search_user_id: SequenceNotStr[str]
44+
"""Additional user IDs to OR into free-text search."""
45+
46+
service: str
47+
"""Filter by service name."""

0 commit comments

Comments
 (0)