Skip to content

Commit 79ecae5

Browse files
scaleway-botyfodil
andauthored
feat(audit_trail): support system events (#1246)
Co-authored-by: Yacine Fodil <105779815+yfodil@users.noreply.github.com>
1 parent 8f6608b commit 79ecae5

File tree

8 files changed

+582
-112
lines changed

8 files changed

+582
-112
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from .types import AuthenticationEventOrigin
77
from .types import AuthenticationEventResult
88
from .types import ListAuthenticationEventsRequestOrderBy
9+
from .types import ListCombinedEventsRequestOrderBy
910
from .types import ListEventsRequestOrderBy
1011
from .types import ResourceType
12+
from .types import SystemEventKind
1113
from .types import AccountOrganizationInfo
1214
from .types import AccountProjectInfo
1315
from .types import AccountUserInfo
@@ -32,13 +34,16 @@
3234
from .types import SecretManagerSecretVersionInfo
3335
from .types import Resource
3436
from .types import EventPrincipal
35-
from .types import EventSystem
36-
from .types import ProductService
3737
from .types import AuthenticationEvent
3838
from .types import Event
39+
from .types import SystemEvent
40+
from .types import ProductService
41+
from .types import ListCombinedEventsResponseCombinedEvent
3942
from .types import Product
4043
from .types import ListAuthenticationEventsRequest
4144
from .types import ListAuthenticationEventsResponse
45+
from .types import ListCombinedEventsRequest
46+
from .types import ListCombinedEventsResponse
4247
from .types import ListEventsRequest
4348
from .types import ListEventsResponse
4449
from .types import ListProductsRequest
@@ -52,8 +57,10 @@
5257
"AuthenticationEventOrigin",
5358
"AuthenticationEventResult",
5459
"ListAuthenticationEventsRequestOrderBy",
60+
"ListCombinedEventsRequestOrderBy",
5561
"ListEventsRequestOrderBy",
5662
"ResourceType",
63+
"SystemEventKind",
5764
"AccountOrganizationInfo",
5865
"AccountProjectInfo",
5966
"AccountUserInfo",
@@ -78,13 +85,16 @@
7885
"SecretManagerSecretVersionInfo",
7986
"Resource",
8087
"EventPrincipal",
81-
"EventSystem",
82-
"ProductService",
8388
"AuthenticationEvent",
8489
"Event",
90+
"SystemEvent",
91+
"ProductService",
92+
"ListCombinedEventsResponseCombinedEvent",
8593
"Product",
8694
"ListAuthenticationEventsRequest",
8795
"ListAuthenticationEventsResponse",
96+
"ListCombinedEventsRequest",
97+
"ListCombinedEventsResponse",
8898
"ListEventsRequest",
8999
"ListEventsResponse",
90100
"ListProductsRequest",

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
)
1414
from .types import (
1515
ListAuthenticationEventsRequestOrderBy,
16+
ListCombinedEventsRequestOrderBy,
1617
ListEventsRequestOrderBy,
1718
ResourceType,
1819
ListAuthenticationEventsResponse,
20+
ListCombinedEventsResponse,
1921
ListEventsResponse,
2022
ListProductsResponse,
2123
)
2224
from .marshalling import (
2325
unmarshal_ListAuthenticationEventsResponse,
26+
unmarshal_ListCombinedEventsResponse,
2427
unmarshal_ListEventsResponse,
2528
unmarshal_ListProductsResponse,
2629
)
@@ -158,6 +161,60 @@ async def list_authentication_events(
158161
self._throw_on_error(res)
159162
return unmarshal_ListAuthenticationEventsResponse(res.json())
160163

164+
async def list_combined_events(
165+
self,
166+
*,
167+
region: Optional[ScwRegion] = None,
168+
organization_id: Optional[str] = None,
169+
project_id: Optional[str] = None,
170+
resource_type: Optional[ResourceType] = None,
171+
recorded_after: Optional[datetime] = None,
172+
recorded_before: Optional[datetime] = None,
173+
order_by: Optional[ListCombinedEventsRequestOrderBy] = None,
174+
page_size: Optional[int] = None,
175+
page_token: Optional[str] = None,
176+
) -> ListCombinedEventsResponse:
177+
"""
178+
:param region: Region to target. If none is passed will use default region from the config.
179+
:param organization_id:
180+
:param project_id:
181+
:param resource_type:
182+
:param recorded_after:
183+
:param recorded_before:
184+
:param order_by:
185+
:param page_size:
186+
:param page_token:
187+
:return: :class:`ListCombinedEventsResponse <ListCombinedEventsResponse>`
188+
189+
Usage:
190+
::
191+
192+
result = await api.list_combined_events()
193+
"""
194+
195+
param_region = validate_path_param(
196+
"region", region or self.client.default_region
197+
)
198+
199+
res = self._request(
200+
"GET",
201+
f"/audit-trail/v1alpha1/regions/{param_region}/combined-events",
202+
params={
203+
"order_by": order_by,
204+
"organization_id": organization_id
205+
or self.client.default_organization_id,
206+
"page_size": page_size or self.client.default_page_size,
207+
"page_token": page_token,
208+
"project_id": project_id or self.client.default_project_id,
209+
"recorded_after": recorded_after,
210+
"recorded_before": recorded_before,
211+
"resource_type": resource_type,
212+
},
213+
)
214+
215+
self._throw_on_error(res)
216+
return unmarshal_ListCombinedEventsResponse(res.json())
217+
161218
async def list_products(
162219
self,
163220
*,

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

Lines changed: 152 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
AuthenticationEvent,
3737
ListAuthenticationEventsResponse,
3838
EventPrincipal,
39-
EventSystem,
4039
Event,
40+
SystemEvent,
41+
ListCombinedEventsResponseCombinedEvent,
42+
ListCombinedEventsResponse,
4143
ListEventsResponse,
4244
ProductService,
4345
Product,
@@ -802,23 +804,6 @@ def unmarshal_EventPrincipal(data: Any) -> EventPrincipal:
802804
return EventPrincipal(**args)
803805

804806

805-
def unmarshal_EventSystem(data: Any) -> EventSystem:
806-
if not isinstance(data, dict):
807-
raise TypeError(
808-
"Unmarshalling the type 'EventSystem' failed as data isn't a dictionary."
809-
)
810-
811-
args: dict[str, Any] = {}
812-
813-
field = data.get("name", None)
814-
if field is not None:
815-
args["name"] = field
816-
else:
817-
args["name"] = None
818-
819-
return EventSystem(**args)
820-
821-
822807
def unmarshal_Event(data: Any) -> Event:
823808
if not isinstance(data, dict):
824809
raise TypeError(
@@ -857,18 +842,6 @@ def unmarshal_Event(data: Any) -> Event:
857842
else:
858843
args["product_name"] = None
859844

860-
field = data.get("service_name", None)
861-
if field is not None:
862-
args["service_name"] = field
863-
else:
864-
args["service_name"] = None
865-
866-
field = data.get("method_name", None)
867-
if field is not None:
868-
args["method_name"] = field
869-
else:
870-
args["method_name"] = None
871-
872845
field = data.get("recorded_at", None)
873846
if field is not None:
874847
args["recorded_at"] = (
@@ -883,6 +856,30 @@ def unmarshal_Event(data: Any) -> Event:
883856
else:
884857
args["principal"] = None
885858

859+
field = data.get("project_id", None)
860+
if field is not None:
861+
args["project_id"] = field
862+
else:
863+
args["project_id"] = None
864+
865+
field = data.get("user_agent", None)
866+
if field is not None:
867+
args["user_agent"] = field
868+
else:
869+
args["user_agent"] = None
870+
871+
field = data.get("service_name", None)
872+
if field is not None:
873+
args["service_name"] = field
874+
else:
875+
args["service_name"] = None
876+
877+
field = data.get("method_name", None)
878+
if field is not None:
879+
args["method_name"] = field
880+
else:
881+
args["method_name"] = None
882+
886883
field = data.get("resources", None)
887884
if field is not None:
888885
args["resources"] = (
@@ -903,31 +900,146 @@ def unmarshal_Event(data: Any) -> Event:
903900
else:
904901
args["status_code"] = 0
905902

906-
field = data.get("system", None)
903+
field = data.get("request_body", None)
907904
if field is not None:
908-
args["system"] = unmarshal_EventSystem(field)
905+
args["request_body"] = field
909906
else:
910-
args["system"] = None
907+
args["request_body"] = {}
908+
909+
return Event(**args)
910+
911+
912+
def unmarshal_SystemEvent(data: Any) -> SystemEvent:
913+
if not isinstance(data, dict):
914+
raise TypeError(
915+
"Unmarshalling the type 'SystemEvent' failed as data isn't a dictionary."
916+
)
917+
918+
args: dict[str, Any] = {}
919+
920+
field = data.get("id", None)
921+
if field is not None:
922+
args["id"] = field
923+
else:
924+
args["id"] = None
925+
926+
field = data.get("locality", None)
927+
if field is not None:
928+
args["locality"] = field
929+
else:
930+
args["locality"] = None
931+
932+
field = data.get("organization_id", None)
933+
if field is not None:
934+
args["organization_id"] = field
935+
else:
936+
args["organization_id"] = None
937+
938+
field = data.get("source", None)
939+
if field is not None:
940+
args["source"] = field
941+
else:
942+
args["source"] = None
943+
944+
field = data.get("system_name", None)
945+
if field is not None:
946+
args["system_name"] = field
947+
else:
948+
args["system_name"] = None
949+
950+
field = data.get("resources", None)
951+
if field is not None:
952+
args["resources"] = (
953+
[unmarshal_Resource(v) for v in field] if field is not None else None
954+
)
955+
else:
956+
args["resources"] = None
957+
958+
field = data.get("kind", None)
959+
if field is not None:
960+
args["kind"] = field
961+
else:
962+
args["kind"] = None
963+
964+
field = data.get("product_name", None)
965+
if field is not None:
966+
args["product_name"] = field
967+
else:
968+
args["product_name"] = None
969+
970+
field = data.get("recorded_at", None)
971+
if field is not None:
972+
args["recorded_at"] = (
973+
parser.isoparse(field) if isinstance(field, str) else field
974+
)
975+
else:
976+
args["recorded_at"] = None
911977

912978
field = data.get("project_id", None)
913979
if field is not None:
914980
args["project_id"] = field
915981
else:
916982
args["project_id"] = None
917983

918-
field = data.get("user_agent", None)
984+
return SystemEvent(**args)
985+
986+
987+
def unmarshal_ListCombinedEventsResponseCombinedEvent(
988+
data: Any,
989+
) -> ListCombinedEventsResponseCombinedEvent:
990+
if not isinstance(data, dict):
991+
raise TypeError(
992+
"Unmarshalling the type 'ListCombinedEventsResponseCombinedEvent' failed as data isn't a dictionary."
993+
)
994+
995+
args: dict[str, Any] = {}
996+
997+
field = data.get("api", None)
919998
if field is not None:
920-
args["user_agent"] = field
999+
args["api"] = unmarshal_Event(field)
9211000
else:
922-
args["user_agent"] = None
1001+
args["api"] = None
9231002

924-
field = data.get("request_body", None)
1003+
field = data.get("auth", None)
9251004
if field is not None:
926-
args["request_body"] = field
1005+
args["auth"] = unmarshal_AuthenticationEvent(field)
9271006
else:
928-
args["request_body"] = {}
1007+
args["auth"] = None
9291008

930-
return Event(**args)
1009+
field = data.get("system", None)
1010+
if field is not None:
1011+
args["system"] = unmarshal_SystemEvent(field)
1012+
else:
1013+
args["system"] = None
1014+
1015+
return ListCombinedEventsResponseCombinedEvent(**args)
1016+
1017+
1018+
def unmarshal_ListCombinedEventsResponse(data: Any) -> ListCombinedEventsResponse:
1019+
if not isinstance(data, dict):
1020+
raise TypeError(
1021+
"Unmarshalling the type 'ListCombinedEventsResponse' failed as data isn't a dictionary."
1022+
)
1023+
1024+
args: dict[str, Any] = {}
1025+
1026+
field = data.get("events", None)
1027+
if field is not None:
1028+
args["events"] = (
1029+
[unmarshal_ListCombinedEventsResponseCombinedEvent(v) for v in field]
1030+
if field is not None
1031+
else None
1032+
)
1033+
else:
1034+
args["events"] = None
1035+
1036+
field = data.get("next_page_token", None)
1037+
if field is not None:
1038+
args["next_page_token"] = field
1039+
else:
1040+
args["next_page_token"] = None
1041+
1042+
return ListCombinedEventsResponse(**args)
9311043

9321044

9331045
def unmarshal_ListEventsResponse(data: Any) -> ListEventsResponse:

0 commit comments

Comments
 (0)