Skip to content

Commit 4415935

Browse files
authored
feat(audit_trail): add exports listing (scaleway#1293)
1 parent 1a81bc4 commit 4415935

File tree

8 files changed

+446
-90
lines changed

8 files changed

+446
-90
lines changed

scaleway-async/scaleway_async/audit_trail/v1alpha1/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .types import ListAuthenticationEventsRequestOrderBy
99
from .types import ListCombinedEventsRequestOrderBy
1010
from .types import ListEventsRequestOrderBy
11+
from .types import ListExportJobsRequestOrderBy
1112
from .types import ResourceType
1213
from .types import SystemEventKind
1314
from .types import AccountOrganizationInfo
@@ -37,19 +38,21 @@
3738
from .types import AuthenticationEvent
3839
from .types import Event
3940
from .types import SystemEvent
40-
from .types import ProductService
4141
from .types import ExportJobS3
42+
from .types import ProductService
4243
from .types import ListCombinedEventsResponseCombinedEvent
44+
from .types import ExportJob
4345
from .types import Product
4446
from .types import CreateExportJobRequest
4547
from .types import DeleteExportJobRequest
46-
from .types import ExportJob
4748
from .types import ListAuthenticationEventsRequest
4849
from .types import ListAuthenticationEventsResponse
4950
from .types import ListCombinedEventsRequest
5051
from .types import ListCombinedEventsResponse
5152
from .types import ListEventsRequest
5253
from .types import ListEventsResponse
54+
from .types import ListExportJobsRequest
55+
from .types import ListExportJobsResponse
5356
from .types import ListProductsRequest
5457
from .types import ListProductsResponse
5558
from .api import AuditTrailV1Alpha1API
@@ -63,6 +66,7 @@
6366
"ListAuthenticationEventsRequestOrderBy",
6467
"ListCombinedEventsRequestOrderBy",
6568
"ListEventsRequestOrderBy",
69+
"ListExportJobsRequestOrderBy",
6670
"ResourceType",
6771
"SystemEventKind",
6872
"AccountOrganizationInfo",
@@ -92,19 +96,21 @@
9296
"AuthenticationEvent",
9397
"Event",
9498
"SystemEvent",
95-
"ProductService",
9699
"ExportJobS3",
100+
"ProductService",
97101
"ListCombinedEventsResponseCombinedEvent",
102+
"ExportJob",
98103
"Product",
99104
"CreateExportJobRequest",
100105
"DeleteExportJobRequest",
101-
"ExportJob",
102106
"ListAuthenticationEventsRequest",
103107
"ListAuthenticationEventsResponse",
104108
"ListCombinedEventsRequest",
105109
"ListCombinedEventsResponse",
106110
"ListEventsRequest",
107111
"ListEventsResponse",
112+
"ListExportJobsRequest",
113+
"ListExportJobsResponse",
108114
"ListProductsRequest",
109115
"ListProductsResponse",
110116
"AuditTrailV1Alpha1API",

scaleway-async/scaleway_async/audit_trail/v1alpha1/api.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010
)
1111
from scaleway_core.utils import (
1212
validate_path_param,
13+
fetch_all_pages_async,
1314
)
1415
from .types import (
1516
ListAuthenticationEventsRequestOrderBy,
1617
ListCombinedEventsRequestOrderBy,
1718
ListEventsRequestOrderBy,
19+
ListExportJobsRequestOrderBy,
1820
ResourceType,
1921
CreateExportJobRequest,
2022
ExportJob,
2123
ExportJobS3,
2224
ListAuthenticationEventsResponse,
2325
ListCombinedEventsResponse,
2426
ListEventsResponse,
27+
ListExportJobsResponse,
2528
ListProductsResponse,
2629
)
2730
from .marshalling import (
2831
unmarshal_ExportJob,
2932
unmarshal_ListAuthenticationEventsResponse,
3033
unmarshal_ListCombinedEventsResponse,
3134
unmarshal_ListEventsResponse,
35+
unmarshal_ListExportJobsResponse,
3236
unmarshal_ListProductsResponse,
3337
marshal_CreateExportJobRequest,
3438
)
@@ -335,3 +339,93 @@ async def delete_export_job(
335339
)
336340

337341
self._throw_on_error(res)
342+
343+
async def list_export_jobs(
344+
self,
345+
*,
346+
region: Optional[ScwRegion] = None,
347+
organization_id: Optional[str] = None,
348+
name: Optional[str] = None,
349+
tags: Optional[dict[str, str]] = None,
350+
page: Optional[int] = None,
351+
page_size: Optional[int] = None,
352+
order_by: Optional[ListExportJobsRequestOrderBy] = None,
353+
) -> ListExportJobsResponse:
354+
"""
355+
:param region: Region to target. If none is passed will use default region from the config.
356+
:param organization_id: Filter by Organization ID.
357+
:param name: (Optional) Filter by export name.
358+
:param tags: (Optional) List of tags to filter on.
359+
:param page:
360+
:param page_size:
361+
:param order_by:
362+
:return: :class:`ListExportJobsResponse <ListExportJobsResponse>`
363+
364+
Usage:
365+
::
366+
367+
result = await api.list_export_jobs()
368+
"""
369+
370+
param_region = validate_path_param(
371+
"region", region or self.client.default_region
372+
)
373+
374+
res = self._request(
375+
"GET",
376+
f"/audit-trail/v1alpha1/regions/{param_region}/export-jobs",
377+
params={
378+
"name": name,
379+
"order_by": order_by,
380+
"organization_id": organization_id
381+
or self.client.default_organization_id,
382+
"page": page,
383+
"page_size": page_size or self.client.default_page_size,
384+
"tags": tags,
385+
},
386+
)
387+
388+
self._throw_on_error(res)
389+
return unmarshal_ListExportJobsResponse(res.json())
390+
391+
async def list_export_jobs_all(
392+
self,
393+
*,
394+
region: Optional[ScwRegion] = None,
395+
organization_id: Optional[str] = None,
396+
name: Optional[str] = None,
397+
tags: Optional[dict[str, str]] = None,
398+
page: Optional[int] = None,
399+
page_size: Optional[int] = None,
400+
order_by: Optional[ListExportJobsRequestOrderBy] = None,
401+
) -> list[ExportJob]:
402+
"""
403+
:param region: Region to target. If none is passed will use default region from the config.
404+
:param organization_id: Filter by Organization ID.
405+
:param name: (Optional) Filter by export name.
406+
:param tags: (Optional) List of tags to filter on.
407+
:param page:
408+
:param page_size:
409+
:param order_by:
410+
:return: :class:`list[ExportJob] <list[ExportJob]>`
411+
412+
Usage:
413+
::
414+
415+
result = await api.list_export_jobs_all()
416+
"""
417+
418+
return await fetch_all_pages_async(
419+
type=ListExportJobsResponse,
420+
key="export_jobs",
421+
fetcher=self.list_export_jobs,
422+
args={
423+
"region": region,
424+
"organization_id": organization_id,
425+
"name": name,
426+
"tags": tags,
427+
"page": page,
428+
"page_size": page_size,
429+
"order_by": order_by,
430+
},
431+
)

scaleway-async/scaleway_async/audit_trail/v1alpha1/marshalling.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
ListCombinedEventsResponseCombinedEvent,
4949
ListCombinedEventsResponse,
5050
ListEventsResponse,
51+
ListExportJobsResponse,
5152
ProductService,
5253
Product,
5354
ListProductsResponse,
@@ -1165,6 +1166,31 @@ def unmarshal_ListEventsResponse(data: Any) -> ListEventsResponse:
11651166
return ListEventsResponse(**args)
11661167

11671168

1169+
def unmarshal_ListExportJobsResponse(data: Any) -> ListExportJobsResponse:
1170+
if not isinstance(data, dict):
1171+
raise TypeError(
1172+
"Unmarshalling the type 'ListExportJobsResponse' failed as data isn't a dictionary."
1173+
)
1174+
1175+
args: dict[str, Any] = {}
1176+
1177+
field = data.get("export_jobs", None)
1178+
if field is not None:
1179+
args["export_jobs"] = (
1180+
[unmarshal_ExportJob(v) for v in field] if field is not None else None
1181+
)
1182+
else:
1183+
args["export_jobs"] = []
1184+
1185+
field = data.get("total_count", None)
1186+
if field is not None:
1187+
args["total_count"] = field
1188+
else:
1189+
args["total_count"] = 0
1190+
1191+
return ListExportJobsResponse(**args)
1192+
1193+
11681194
def unmarshal_ProductService(data: Any) -> ProductService:
11691195
if not isinstance(data, dict):
11701196
raise TypeError(

0 commit comments

Comments
 (0)