Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/kms/oas_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
467fe4d305e48699c34835e45fd1c7b486be01d2
8f43ed707da765654e4427642c9d978f80d504e1
32 changes: 15 additions & 17 deletions services/kms/src/stackit/kms/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ApiClient:
"date": datetime.date,
"datetime": datetime.datetime,
"decimal": decimal.Decimal,
"UUID": uuid.UUID,
"object": object,
}
_pool = None
Expand Down Expand Up @@ -265,7 +266,7 @@ def response_deserialize(
response_text = None
return_data = None
try:
if response_type == "bytearray":
if response_type in ("bytearray", "bytes"):
return_data = response_data.data
elif response_type == "file":
return_data = self.__deserialize_file(response_data)
Expand Down Expand Up @@ -326,25 +327,20 @@ def sanitize_for_serialization(self, obj):
return obj.isoformat()
elif isinstance(obj, decimal.Decimal):
return str(obj)

elif isinstance(obj, dict):
obj_dict = obj
return {key: self.sanitize_for_serialization(val) for key, val in obj.items()}

# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
obj_dict = obj.to_dict()
else:
# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

if isinstance(obj_dict, list):
# 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
return self.sanitize_for_serialization(obj_dict)
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()}
return self.sanitize_for_serialization(obj_dict)

def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
"""Deserializes response into an object.
Expand Down Expand Up @@ -417,6 +413,8 @@ def __deserialize(self, data, klass):
return self.__deserialize_datetime(data)
elif klass is decimal.Decimal:
return decimal.Decimal(data)
elif klass is uuid.UUID:
return uuid.UUID(data)
elif issubclass(klass, Enum):
return self.__deserialize_enum(data, klass)
else:
Expand Down
10 changes: 7 additions & 3 deletions services/kms/src/stackit/kms/models/create_key_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
StrictStr,
field_validator,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Annotated, Self

from stackit.kms.models.access_scope import AccessScope
Expand Down Expand Up @@ -66,12 +67,16 @@ class CreateKeyPayload(BaseModel):
@field_validator("display_name")
def display_name_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if not isinstance(value, str):
value = str(value)

if not re.match(r"^[a-zA-Z0-9_-]+$", value):
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -82,8 +87,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
10 changes: 7 additions & 3 deletions services/kms/src/stackit/kms/models/create_key_ring_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from pydantic_core import to_jsonable_python
from typing_extensions import Annotated, Self


Expand All @@ -39,12 +40,16 @@ class CreateKeyRingPayload(BaseModel):
@field_validator("display_name")
def display_name_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if not isinstance(value, str):
value = str(value)

if not re.match(r"^[a-zA-Z0-9_-]+$", value):
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -55,8 +60,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from pydantic_core import to_jsonable_python
from typing_extensions import Annotated, Self

from stackit.kms.models.access_scope import AccessScope
Expand Down Expand Up @@ -55,12 +56,16 @@ class CreateWrappingKeyPayload(BaseModel):
@field_validator("display_name")
def display_name_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if not isinstance(value, str):
value = str(value)

if not re.match(r"^[a-zA-Z0-9_-]+$", value):
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_-]+$/")
return value

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -71,8 +76,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/decrypt_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
StrictBytes,
StrictStr,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Self


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

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -47,8 +49,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/decrypted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
StrictBytes,
StrictStr,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Self


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

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -47,8 +49,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/encrypt_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
StrictBytes,
StrictStr,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Self


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

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -47,8 +49,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/encrypted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
StrictBytes,
StrictStr,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Self


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

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -47,8 +49,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/http_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from pydantic_core import to_jsonable_python
from typing_extensions import Self


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

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -41,8 +43,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/import_key_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from pydantic_core import to_jsonable_python
from typing_extensions import Self


Expand All @@ -36,7 +37,8 @@ class ImportKeyPayload(BaseModel):
__properties: ClassVar[List[str]] = ["wrappedKey", "wrappingKeyId"]

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -47,8 +49,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
StrictStr,
field_validator,
)
from pydantic_core import to_jsonable_python
from typing_extensions import Annotated, Self

from stackit.kms.models.access_scope import AccessScope
Expand Down Expand Up @@ -116,7 +117,8 @@ def state_validate_enum(cls, value):
return value

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -127,8 +129,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
7 changes: 4 additions & 3 deletions services/kms/src/stackit/kms/models/key_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict
from pydantic_core import to_jsonable_python
from typing_extensions import Self

from stackit.kms.models.key import Key
Expand All @@ -32,7 +33,8 @@ class KeyList(BaseModel):
__properties: ClassVar[List[str]] = ["keys"]

model_config = ConfigDict(
populate_by_name=True,
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
Expand All @@ -43,8 +45,7 @@ def to_str(self) -> str:

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())
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
Expand Down
Loading
Loading