|
15 | 15 |
|
16 | 16 | import json |
17 | 17 | import pprint |
| 18 | +import re # noqa: F401 |
18 | 19 | from datetime import datetime |
19 | 20 | from typing import Any, ClassVar, Dict, List, Optional, Set |
20 | 21 |
|
@@ -118,13 +119,39 @@ class AuditLogEntryResponse(BaseModel): |
118 | 119 | "visibility", |
119 | 120 | ] |
120 | 121 |
|
| 122 | + @field_validator("event_time_stamp", mode="before") |
| 123 | + def event_time_stamp_change_year_zero_to_one(cls, value): |
| 124 | + """Workaround which prevents year 0 issue""" |
| 125 | + if isinstance(value, str): |
| 126 | + # Check for year "0000" at the beginning of the string |
| 127 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 128 | + if value.startswith("0000-01-01T") and re.match( |
| 129 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 130 | + ): |
| 131 | + # Workaround: Replace "0000" with "0001" |
| 132 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 133 | + return value |
| 134 | + |
121 | 135 | @field_validator("event_type") |
122 | 136 | def event_type_validate_enum(cls, value): |
123 | 137 | """Validates the enum""" |
124 | 138 | if value not in set(["ADMIN_ACTIVITY", "SYSTEM_EVENT", "POLICY_DENIED"]): |
125 | 139 | raise ValueError("must be one of enum values ('ADMIN_ACTIVITY', 'SYSTEM_EVENT', 'POLICY_DENIED')") |
126 | 140 | return value |
127 | 141 |
|
| 142 | + @field_validator("received_time_stamp", mode="before") |
| 143 | + def received_time_stamp_change_year_zero_to_one(cls, value): |
| 144 | + """Workaround which prevents year 0 issue""" |
| 145 | + if isinstance(value, str): |
| 146 | + # Check for year "0000" at the beginning of the string |
| 147 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 148 | + if value.startswith("0000-01-01T") and re.match( |
| 149 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 150 | + ): |
| 151 | + # Workaround: Replace "0000" with "0001" |
| 152 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 153 | + return value |
| 154 | + |
128 | 155 | @field_validator("severity") |
129 | 156 | def severity_validate_enum(cls, value): |
130 | 157 | """Validates the enum""" |
|
0 commit comments