Skip to content

Commit c318f58

Browse files
Generate auditlog
1 parent e731cb6 commit c318f58

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

services/auditlog/src/stackit/auditlog/models/audit_log_entry_response.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import json
1717
import pprint
18+
import re # noqa: F401
1819
from datetime import datetime
1920
from typing import Any, ClassVar, Dict, List, Optional, Set
2021

@@ -118,13 +119,39 @@ class AuditLogEntryResponse(BaseModel):
118119
"visibility",
119120
]
120121

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+
121135
@field_validator("event_type")
122136
def event_type_validate_enum(cls, value):
123137
"""Validates the enum"""
124138
if value not in set(["ADMIN_ACTIVITY", "SYSTEM_EVENT", "POLICY_DENIED"]):
125139
raise ValueError("must be one of enum values ('ADMIN_ACTIVITY', 'SYSTEM_EVENT', 'POLICY_DENIED')")
126140
return value
127141

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+
128155
@field_validator("severity")
129156
def severity_validate_enum(cls, value):
130157
"""Validates the enum"""

services/auditlog/src/stackit/auditlog/models/error_response.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515

1616
import json
1717
import pprint
18+
import re # noqa: F401
1819
from datetime import datetime
1920
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
2021

21-
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
22+
from pydantic import (
23+
BaseModel,
24+
ConfigDict,
25+
Field,
26+
StrictFloat,
27+
StrictInt,
28+
StrictStr,
29+
field_validator,
30+
)
2231
from typing_extensions import Self
2332

2433

@@ -33,6 +42,19 @@ class ErrorResponse(BaseModel):
3342
timestamp: Optional[datetime] = Field(default=None, description="Timestamp at which the error occurred.")
3443
__properties: ClassVar[List[str]] = ["message", "path", "status", "timestamp"]
3544

45+
@field_validator("timestamp", mode="before")
46+
def timestamp_change_year_zero_to_one(cls, value):
47+
"""Workaround which prevents year 0 issue"""
48+
if isinstance(value, str):
49+
# Check for year "0000" at the beginning of the string
50+
# This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
51+
if value.startswith("0000-01-01T") and re.match(
52+
r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value
53+
):
54+
# Workaround: Replace "0000" with "0001"
55+
return "0001" + value[4:] # Take "0001" and append the rest of the string
56+
return value
57+
3658
model_config = ConfigDict(
3759
populate_by_name=True,
3860
validate_assignment=True,

services/auditlog/src/stackit/auditlog/models/gateway_error_response.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
import pprint
1818
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
20+
from pydantic import (
21+
BaseModel,
22+
ConfigDict,
23+
Field,
24+
StrictFloat,
25+
StrictInt,
26+
StrictStr,
27+
)
2128
from typing_extensions import Self
2229

2330

services/auditlog/src/stackit/auditlog/models/list_audit_log_entries_response.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
import pprint
1818
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
20+
from pydantic import (
21+
BaseModel,
22+
ConfigDict,
23+
Field,
24+
StrictFloat,
25+
StrictInt,
26+
StrictStr,
27+
)
2128
from typing_extensions import Self
2229

2330
from stackit.auditlog.models.audit_log_entry_response import AuditLogEntryResponse

0 commit comments

Comments
 (0)