-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaudit_log_entry_response.py
More file actions
266 lines (239 loc) · 11.6 KB
/
audit_log_entry_response.py
File metadata and controls
266 lines (239 loc) · 11.6 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# coding: utf-8
"""
Audit Log API
API Endpoints to retrieve recorded actions and resulting changes in the system. ### Documentation The user documentation with explanations how to use the api can be found [here](https://docs.stackit.cloud/stackit/en/retrieve-audit-log-per-api-request-134415907.html). ### Audit Logging Changes on organizations, folders and projects and respective cloud resources are logged and collected in the audit log. ### API Constraints The audit log API allows to download messages from the last 90 days. The maximum duration that can be queried at once is 24 hours. Requests are rate limited - the current maximum is 60 requests per minute.
The version of the OpenAPI document: 2.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing_extensions import Annotated, Self
from stackit.auditlog.models.audit_log_entry_context_response import (
AuditLogEntryContextResponse,
)
from stackit.auditlog.models.audit_log_entry_initiator_response import (
AuditLogEntryInitiatorResponse,
)
from stackit.auditlog.models.audit_log_entry_request_response import (
AuditLogEntryRequestResponse,
)
from stackit.auditlog.models.audit_log_entry_service_account_delegation_info_response import (
AuditLogEntryServiceAccountDelegationInfoResponse,
)
class AuditLogEntryResponse(BaseModel):
"""
AuditLogEntryResponse
""" # noqa: E501
context: Optional[AuditLogEntryContextResponse] = None
correlation_id: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(
default=None,
description="Unique ID which identifies the request from the sender point of view.",
alias="correlationId",
)
details: Optional[Dict[str, Any]] = Field(
default=None,
description="Additional information about the event that is not part of the request or response. May contain arbitrary data.",
)
event_name: Annotated[str, Field(min_length=1, strict=True, max_length=255)] = Field(
description="Name of the operation this event represents.", alias="eventName"
)
event_source: StrictStr = Field(
description="The service in which the causing event was handled.", alias="eventSource"
)
event_time_stamp: datetime = Field(
description="Timestamp at which the event was triggered.", alias="eventTimeStamp"
)
event_type: StrictStr = Field(
description='Type that can be assigned to the event. For example, an event "Organization created" can be assigned to the type ADMIN_EVENT',
alias="eventType",
)
event_version: StrictStr = Field(description="Version of the log event format.", alias="eventVersion")
id: StrictStr = Field(description="Unique ID generated by the audit log.")
initiator: AuditLogEntryInitiatorResponse
received_time_stamp: datetime = Field(
description="Timestamp at which the event was received by the audit log.", alias="receivedTimeStamp"
)
region: StrictStr = Field(description="Region from which the event has been emitted.")
request: AuditLogEntryRequestResponse
resource_id: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(
default=None, description="Unique id of the resource that is target of the operation", alias="resourceId"
)
resource_name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(
default=None, description="Name of the resource that is target of the operation", alias="resourceName"
)
result: Optional[Dict[str, Any]] = Field(
default=None,
description="Object representing the change resulting from this event. May be omitted if no change has been applied. May contain arbitrary data.",
)
service_account_delegation_info: Optional[AuditLogEntryServiceAccountDelegationInfoResponse] = Field(
default=None, alias="serviceAccountDelegationInfo"
)
severity: StrictStr = Field(description="The severity of this request.")
source_ip_address: StrictStr = Field(
description="IP address that the request was made from", alias="sourceIpAddress"
)
user_agent: Annotated[str, Field(min_length=1, strict=True, max_length=255)] = Field(
description="Agent through which the request was made from (e.g. Portal, CLI, SDK, ...) ", alias="userAgent"
)
visibility: StrictStr = Field(
description="PUBLIC for entries that are intended for end users, while PRIVATE entries can only be viewed with system privileges."
)
__properties: ClassVar[List[str]] = [
"context",
"correlationId",
"details",
"eventName",
"eventSource",
"eventTimeStamp",
"eventType",
"eventVersion",
"id",
"initiator",
"receivedTimeStamp",
"region",
"request",
"resourceId",
"resourceName",
"result",
"serviceAccountDelegationInfo",
"severity",
"sourceIpAddress",
"userAgent",
"visibility",
]
@field_validator("event_time_stamp", mode="before")
def event_time_stamp_change_year_zero_to_one(cls, value):
"""Workaround which prevents year 0 issue"""
if isinstance(value, str):
# Check for year "0000" at the beginning of the string
# This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
if value.startswith("0000-01-01T") and re.match(
r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value
):
# Workaround: Replace "0000" with "0001"
return "0001" + value[4:] # Take "0001" and append the rest of the string
return value
@field_validator("event_type")
def event_type_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(["ADMIN_ACTIVITY", "SYSTEM_EVENT", "POLICY_DENIED"]):
raise ValueError("must be one of enum values ('ADMIN_ACTIVITY', 'SYSTEM_EVENT', 'POLICY_DENIED')")
return value
@field_validator("received_time_stamp", mode="before")
def received_time_stamp_change_year_zero_to_one(cls, value):
"""Workaround which prevents year 0 issue"""
if isinstance(value, str):
# Check for year "0000" at the beginning of the string
# This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
if value.startswith("0000-01-01T") and re.match(
r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value
):
# Workaround: Replace "0000" with "0001"
return "0001" + value[4:] # Take "0001" and append the rest of the string
return value
@field_validator("severity")
def severity_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(["INFO", "ERROR"]):
raise ValueError("must be one of enum values ('INFO', 'ERROR')")
return value
@field_validator("visibility")
def visibility_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(["PUBLIC", "PRIVATE"]):
raise ValueError("must be one of enum values ('PUBLIC', 'PRIVATE')")
return value
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of AuditLogEntryResponse from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of context
if self.context:
_dict["context"] = self.context.to_dict()
# override the default output from pydantic by calling `to_dict()` of initiator
if self.initiator:
_dict["initiator"] = self.initiator.to_dict()
# override the default output from pydantic by calling `to_dict()` of request
if self.request:
_dict["request"] = self.request.to_dict()
# override the default output from pydantic by calling `to_dict()` of service_account_delegation_info
if self.service_account_delegation_info:
_dict["serviceAccountDelegationInfo"] = self.service_account_delegation_info.to_dict()
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AuditLogEntryResponse from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate(
{
"context": (
AuditLogEntryContextResponse.from_dict(obj["context"]) if obj.get("context") is not None else None
),
"correlationId": obj.get("correlationId"),
"details": obj.get("details"),
"eventName": obj.get("eventName"),
"eventSource": obj.get("eventSource"),
"eventTimeStamp": obj.get("eventTimeStamp"),
"eventType": obj.get("eventType"),
"eventVersion": obj.get("eventVersion"),
"id": obj.get("id"),
"initiator": (
AuditLogEntryInitiatorResponse.from_dict(obj["initiator"])
if obj.get("initiator") is not None
else None
),
"receivedTimeStamp": obj.get("receivedTimeStamp"),
"region": obj.get("region"),
"request": (
AuditLogEntryRequestResponse.from_dict(obj["request"]) if obj.get("request") is not None else None
),
"resourceId": obj.get("resourceId"),
"resourceName": obj.get("resourceName"),
"result": obj.get("result"),
"serviceAccountDelegationInfo": (
AuditLogEntryServiceAccountDelegationInfoResponse.from_dict(obj["serviceAccountDelegationInfo"])
if obj.get("serviceAccountDelegationInfo") is not None
else None
),
"severity": obj.get("severity"),
"sourceIpAddress": obj.get("sourceIpAddress"),
"userAgent": obj.get("userAgent"),
"visibility": obj.get("visibility"),
}
)
return _obj