Skip to content

Commit bdce652

Browse files
Generate kms
1 parent 875e273 commit bdce652

23 files changed

Lines changed: 109 additions & 81 deletions

services/kms/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
467fe4d305e48699c34835e45fd1c7b486be01d2
1+
182c1a61931c30e8dc0cf37167f2995bcb2e09e5

services/kms/src/stackit/kms/api_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ApiClient:
6666
"date": datetime.date,
6767
"datetime": datetime.datetime,
6868
"decimal": decimal.Decimal,
69+
"UUID": uuid.UUID,
6970
"object": object,
7071
}
7172
_pool = None
@@ -265,7 +266,7 @@ def response_deserialize(
265266
response_text = None
266267
return_data = None
267268
try:
268-
if response_type == "bytearray":
269+
if response_type in ("bytearray", "bytes"):
269270
return_data = response_data.data
270271
elif response_type == "file":
271272
return_data = self.__deserialize_file(response_data)
@@ -326,25 +327,20 @@ def sanitize_for_serialization(self, obj):
326327
return obj.isoformat()
327328
elif isinstance(obj, decimal.Decimal):
328329
return str(obj)
329-
330330
elif isinstance(obj, dict):
331-
obj_dict = obj
331+
return {key: self.sanitize_for_serialization(val) for key, val in obj.items()}
332+
333+
# Convert model obj to dict except
334+
# attributes `openapi_types`, `attribute_map`
335+
# and attributes which value is not None.
336+
# Convert attribute name to json key in
337+
# model definition for request.
338+
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
339+
obj_dict = obj.to_dict()
332340
else:
333-
# Convert model obj to dict except
334-
# attributes `openapi_types`, `attribute_map`
335-
# and attributes which value is not None.
336-
# Convert attribute name to json key in
337-
# model definition for request.
338-
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
339-
obj_dict = obj.to_dict()
340-
else:
341-
obj_dict = obj.__dict__
342-
343-
if isinstance(obj_dict, list):
344-
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() # noqa: E501
345-
return self.sanitize_for_serialization(obj_dict)
341+
obj_dict = obj.__dict__
346342

347-
return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()}
343+
return self.sanitize_for_serialization(obj_dict)
348344

349345
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
350346
"""Deserializes response into an object.
@@ -417,6 +413,8 @@ def __deserialize(self, data, klass):
417413
return self.__deserialize_datetime(data)
418414
elif klass is decimal.Decimal:
419415
return decimal.Decimal(data)
416+
elif klass is uuid.UUID:
417+
return uuid.UUID(data)
420418
elif issubclass(klass, Enum):
421419
return self.__deserialize_enum(data, klass)
422420
else:

services/kms/src/stackit/kms/models/create_key_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
StrictStr,
2727
field_validator,
2828
)
29+
from pydantic_core import to_jsonable_python
2930
from typing_extensions import Annotated, Self
3031

3132
from stackit.kms.models.access_scope import AccessScope
@@ -66,12 +67,16 @@ class CreateKeyPayload(BaseModel):
6667
@field_validator("display_name")
6768
def display_name_validate_regular_expression(cls, value):
6869
"""Validates the regular expression"""
70+
if not isinstance(value, str):
71+
value = str(value)
72+
6973
if not re.match(r"^[a-zA-Z0-9_-]+$", value):
7074
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
7175
return value
7276

7377
model_config = ConfigDict(
74-
populate_by_name=True,
78+
validate_by_name=True,
79+
validate_by_alias=True,
7580
validate_assignment=True,
7681
protected_namespaces=(),
7782
)
@@ -82,8 +87,7 @@ def to_str(self) -> str:
8287

8388
def to_json(self) -> str:
8489
"""Returns the JSON representation of the model using alias"""
85-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
86-
return json.dumps(self.to_dict())
90+
return json.dumps(to_jsonable_python(self.to_dict()))
8791

8892
@classmethod
8993
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/create_key_ring_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -39,12 +40,16 @@ class CreateKeyRingPayload(BaseModel):
3940
@field_validator("display_name")
4041
def display_name_validate_regular_expression(cls, value):
4142
"""Validates the regular expression"""
43+
if not isinstance(value, str):
44+
value = str(value)
45+
4246
if not re.match(r"^[a-zA-Z0-9_-]+$", value):
4347
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
4448
return value
4549

4650
model_config = ConfigDict(
47-
populate_by_name=True,
51+
validate_by_name=True,
52+
validate_by_alias=True,
4853
validate_assignment=True,
4954
protected_namespaces=(),
5055
)
@@ -55,8 +60,7 @@ def to_str(self) -> str:
5560

5661
def to_json(self) -> str:
5762
"""Returns the JSON representation of the model using alias"""
58-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
59-
return json.dumps(self.to_dict())
63+
return json.dumps(to_jsonable_python(self.to_dict()))
6064

6165
@classmethod
6266
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/create_wrapping_key_payload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.kms.models.access_scope import AccessScope
@@ -55,12 +56,16 @@ class CreateWrappingKeyPayload(BaseModel):
5556
@field_validator("display_name")
5657
def display_name_validate_regular_expression(cls, value):
5758
"""Validates the regular expression"""
59+
if not isinstance(value, str):
60+
value = str(value)
61+
5862
if not re.match(r"^[a-zA-Z0-9_-]+$", value):
5963
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
6064
return value
6165

6266
model_config = ConfigDict(
63-
populate_by_name=True,
67+
validate_by_name=True,
68+
validate_by_alias=True,
6469
validate_assignment=True,
6570
protected_namespaces=(),
6671
)
@@ -71,8 +76,7 @@ def to_str(self) -> str:
7176

7277
def to_json(self) -> str:
7378
"""Returns the JSON representation of the model using alias"""
74-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
75-
return json.dumps(self.to_dict())
79+
return json.dumps(to_jsonable_python(self.to_dict()))
7680

7781
@classmethod
7882
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/decrypt_payload.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictBytes,
2525
StrictStr,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Self
2829

2930

@@ -36,7 +37,8 @@ class DecryptPayload(BaseModel):
3637
__properties: ClassVar[List[str]] = ["data"]
3738

3839
model_config = ConfigDict(
39-
populate_by_name=True,
40+
validate_by_name=True,
41+
validate_by_alias=True,
4042
validate_assignment=True,
4143
protected_namespaces=(),
4244
)
@@ -47,8 +49,7 @@ def to_str(self) -> str:
4749

4850
def to_json(self) -> str:
4951
"""Returns the JSON representation of the model using alias"""
50-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51-
return json.dumps(self.to_dict())
52+
return json.dumps(to_jsonable_python(self.to_dict()))
5253

5354
@classmethod
5455
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/decrypted_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictBytes,
2525
StrictStr,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Self
2829

2930

@@ -36,7 +37,8 @@ class DecryptedData(BaseModel):
3637
__properties: ClassVar[List[str]] = ["data"]
3738

3839
model_config = ConfigDict(
39-
populate_by_name=True,
40+
validate_by_name=True,
41+
validate_by_alias=True,
4042
validate_assignment=True,
4143
protected_namespaces=(),
4244
)
@@ -47,8 +49,7 @@ def to_str(self) -> str:
4749

4850
def to_json(self) -> str:
4951
"""Returns the JSON representation of the model using alias"""
50-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51-
return json.dumps(self.to_dict())
52+
return json.dumps(to_jsonable_python(self.to_dict()))
5253

5354
@classmethod
5455
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/encrypt_payload.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictBytes,
2525
StrictStr,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Self
2829

2930

@@ -36,7 +37,8 @@ class EncryptPayload(BaseModel):
3637
__properties: ClassVar[List[str]] = ["data"]
3738

3839
model_config = ConfigDict(
39-
populate_by_name=True,
40+
validate_by_name=True,
41+
validate_by_alias=True,
4042
validate_assignment=True,
4143
protected_namespaces=(),
4244
)
@@ -47,8 +49,7 @@ def to_str(self) -> str:
4749

4850
def to_json(self) -> str:
4951
"""Returns the JSON representation of the model using alias"""
50-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51-
return json.dumps(self.to_dict())
52+
return json.dumps(to_jsonable_python(self.to_dict()))
5253

5354
@classmethod
5455
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/encrypted_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StrictBytes,
2525
StrictStr,
2626
)
27+
from pydantic_core import to_jsonable_python
2728
from typing_extensions import Self
2829

2930

@@ -36,7 +37,8 @@ class EncryptedData(BaseModel):
3637
__properties: ClassVar[List[str]] = ["data"]
3738

3839
model_config = ConfigDict(
39-
populate_by_name=True,
40+
validate_by_name=True,
41+
validate_by_alias=True,
4042
validate_assignment=True,
4143
protected_namespaces=(),
4244
)
@@ -47,8 +49,7 @@ def to_str(self) -> str:
4749

4850
def to_json(self) -> str:
4951
"""Returns the JSON representation of the model using alias"""
50-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51-
return json.dumps(self.to_dict())
52+
return json.dumps(to_jsonable_python(self.to_dict()))
5253

5354
@classmethod
5455
def from_json(cls, json_str: str) -> Optional[Self]:

services/kms/src/stackit/kms/models/http_error.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324

@@ -30,7 +31,8 @@ class HttpError(BaseModel):
3031
__properties: ClassVar[List[str]] = ["message"]
3132

3233
model_config = ConfigDict(
33-
populate_by_name=True,
34+
validate_by_name=True,
35+
validate_by_alias=True,
3436
validate_assignment=True,
3537
protected_namespaces=(),
3638
)
@@ -41,8 +43,7 @@ def to_str(self) -> str:
4143

4244
def to_json(self) -> str:
4345
"""Returns the JSON representation of the model using alias"""
44-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
45-
return json.dumps(self.to_dict())
46+
return json.dumps(to_jsonable_python(self.to_dict()))
4647

4748
@classmethod
4849
def from_json(cls, json_str: str) -> Optional[Self]:

0 commit comments

Comments
 (0)