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/iaas/oas_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cb550f3c2129447568c2855337b1874968e033bb
0e64886dd0847341800d7191ed193b75413be998
6,079 changes: 1,579 additions & 4,500 deletions services/iaas/src/stackit/iaas/api/default_api.py

Large diffs are not rendered by default.

31 changes: 22 additions & 9 deletions services/iaas/src/stackit/iaas/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
""" # noqa: E501

import datetime
import decimal
import json
import mimetypes
import os
import re
import tempfile
import uuid
from enum import Enum
from typing import Dict, List, Optional, Tuple, Union
from urllib.parse import quote
Expand Down Expand Up @@ -64,8 +66,10 @@ class ApiClient:
"bool": bool,
"date": datetime.date,
"datetime": datetime.datetime,
"decimal": decimal.Decimal,
"object": object,
}
_pool = None

def __init__(self, configuration, header_name=None, header_value=None, cookie=None) -> None:
self.config: Configuration = configuration
Expand Down Expand Up @@ -268,7 +272,7 @@ def response_deserialize(
return_data = self.__deserialize_file(response_data)
elif response_type is not None:
match = None
content_type = response_data.getheader("content-type")
content_type = response_data.headers.get("content-type")
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
Expand All @@ -285,7 +289,7 @@ def response_deserialize(
return ApiResponse(
status_code=response_data.status,
data=return_data,
headers=response_data.getheaders(),
headers=response_data.headers,
raw_data=response_data.data,
)

Expand All @@ -297,6 +301,7 @@ def sanitize_for_serialization(self, obj):
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is decimal.Decimal return string representation.
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
Expand All @@ -312,12 +317,16 @@ def sanitize_for_serialization(self, obj):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, uuid.UUID):
return str(obj)
elif isinstance(obj, list):
return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
elif isinstance(obj, tuple):
return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj)
elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
elif isinstance(obj, decimal.Decimal):
return str(obj)

elif isinstance(obj, dict):
obj_dict = obj
Expand All @@ -327,7 +336,7 @@ def sanitize_for_serialization(self, obj):
# 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(obj.to_dict):
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__
Expand Down Expand Up @@ -355,7 +364,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
data = json.loads(response_text)
except ValueError:
data = response_text
elif re.match(r"^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE):
elif re.match(r"^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE):
if response_text == "":
data = ""
else:
Expand Down Expand Up @@ -401,12 +410,14 @@ def __deserialize(self, data, klass):

if klass in self.PRIMITIVE_TYPES:
return self.__deserialize_primitive(data, klass)
elif klass == object:
elif klass is object:
return self.__deserialize_object(data)
elif klass == datetime.date:
elif klass is datetime.date:
return self.__deserialize_date(data)
elif klass == datetime.datetime:
elif klass is datetime.datetime:
return self.__deserialize_datetime(data)
elif klass is decimal.Decimal:
return decimal.Decimal(data)
elif issubclass(klass, Enum):
return self.__deserialize_enum(data, klass)
else:
Expand Down Expand Up @@ -554,12 +565,14 @@ def __deserialize_file(self, response):
os.close(fd)
os.remove(path)

content_disposition = response.getheader("Content-Disposition")
content_disposition = response.headers.get("Content-Disposition")
if content_disposition:
m = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition)
if m is None:
raise ValueError("Unexpected 'content-disposition' header value")
filename = m.group(1)
filename = os.path.basename(m.group(1)) # Strip any directory traversal
if filename in ("", ".", ".."): # fall back to tmp filename
filename = os.path.basename(path)
path = os.path.join(os.path.dirname(path), filename)

with open(path, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion services/iaas/src/stackit/iaas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(
self.body = http_resp.data.decode("utf-8")
except Exception: # noqa: S110
pass
self.headers = http_resp.getheaders()
self.headers = http_resp.headers

@classmethod
def from_response(
Expand Down
1 change: 0 additions & 1 deletion services/iaas/src/stackit/iaas/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Do not edit the class manually.
""" # noqa: E501


# import models into model package
from stackit.iaas.models.add_routes_to_routing_table_payload import (
AddRoutesToRoutingTablePayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]:
# override the default output from pydantic by calling `to_dict()` of each item in items (list)
_items = []
if self.items:
for _item in self.items:
if _item:
_items.append(_item.to_dict())
for _item_items in self.items:
if _item_items:
_items.append(_item_items.to_dict())
_dict["items"] = _items
return _dict

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import re # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field, StrictBool, field_validator
from typing_extensions import Annotated, Self
Expand All @@ -44,9 +45,7 @@ class AddRoutingTableToAreaPayload(BaseModel):
description="A config setting for a routing table which allows propagation of dynamic routes to this routing table.",
alias="dynamicRoutes",
)
id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
default=None, description="Universally Unique Identifier (UUID)."
)
id: Optional[UUID] = Field(default=None, description="Universally Unique Identifier (UUID).")
labels: Optional[Dict[str, Any]] = Field(
default=None,
description="Object that represents the labels of an object. Regex for keys: `^(?=.{1,63}$)([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`. Regex for values: `^(?=.{0,63}$)(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])*$`. Providing a `null` value for a key will remove that key. The `stackit-` prefix is reserved and cannot be used for Keys.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field, StrictBool, field_validator
from typing_extensions import Annotated, Self
from typing_extensions import Self


class AddVolumeToServerPayload(BaseModel):
Expand All @@ -33,10 +34,10 @@ class AddVolumeToServerPayload(BaseModel):
description="Delete the volume during the termination of the server. Defaults to false.",
alias="deleteOnTermination",
)
server_id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
server_id: Optional[UUID] = Field(
default=None, description="Universally Unique Identifier (UUID).", alias="serverId"
)
volume_id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
volume_id: Optional[UUID] = Field(
default=None, description="Universally Unique Identifier (UUID).", alias="volumeId"
)
__properties: ClassVar[List[str]] = ["deleteOnTermination", "serverId", "volumeId"]
Expand Down
9 changes: 3 additions & 6 deletions services/iaas/src/stackit/iaas/models/affinity_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing_extensions import Annotated, Self
Expand All @@ -28,12 +29,8 @@ class AffinityGroup(BaseModel):
Definition of an affinity group.
""" # noqa: E501

id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
default=None, description="Universally Unique Identifier (UUID)."
)
members: Optional[List[Annotated[str, Field(min_length=36, strict=True, max_length=36)]]] = Field(
default=None, description="The servers that are part of the affinity group."
)
id: Optional[UUID] = Field(default=None, description="Universally Unique Identifier (UUID).")
members: Optional[List[UUID]] = Field(default=None, description="The servers that are part of the affinity group.")
name: Annotated[str, Field(strict=True, max_length=127)] = Field(
description="The name for a General Object. Matches Names and also UUIDs."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]:
# override the default output from pydantic by calling `to_dict()` of each item in items (list)
_items = []
if self.items:
for _item in self.items:
if _item:
_items.append(_item.to_dict())
for _item_items in self.items:
if _item_items:
_items.append(_item_items.to_dict())
_dict["items"] = _items
return _dict

Expand Down
27 changes: 15 additions & 12 deletions services/iaas/src/stackit/iaas/models/area_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pprint
import re
from typing import Any, Dict, Optional, Set, Union
from uuid import UUID

from pydantic import (
BaseModel,
Expand All @@ -26,34 +27,36 @@
ValidationError,
field_validator,
)
from typing_extensions import Annotated, Self
from typing_extensions import Self

from stackit.iaas.models.static_area_id import StaticAreaID

from typing import Annotated

AREAID_ONE_OF_SCHEMAS = ["StaticAreaID", "str"]

AREAID_ONE_OF_SCHEMAS = ["StaticAreaID", "UUID"]


class AreaId(BaseModel):
"""
The identifier (ID) of an area.
"""

# data type: str
# data type: UUID
# BEGIN of the workaround until upstream issues are fixed:
# https://github.com/OpenAPITools/openapi-generator/issues/19034 from Jun 28, 2024
# and https://github.com/OpenAPITools/openapi-generator/issues/19842 from Oct 11, 2024
# Tracking issue on our side: https://jira.schwarz/browse/STACKITSDK-227
oneof_schema_1_validator: Optional[Annotated[str, Field(strict=True)]] = Field(
oneof_schema_1_validator: Optional[Annotated[UUID, Field(strict=True)]] = Field(
default=None,
description="Universally Unique Identifier (UUID).",
pattern=re.sub(r"^\/|\/$", "", r"/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/"),
)
# END of the workaround
# data type: StaticAreaID
oneof_schema_2_validator: Optional[StaticAreaID] = None
actual_instance: Optional[Union[StaticAreaID, str]] = None
one_of_schemas: Set[str] = {"StaticAreaID", "str"}
actual_instance: Optional[Union[StaticAreaID, UUID]] = None
one_of_schemas: Set[str] = {"StaticAreaID", "UUID"}

model_config = ConfigDict(
validate_assignment=True,
Expand All @@ -75,7 +78,7 @@ def actual_instance_must_validate_oneof(cls, v):
instance = AreaId.model_construct()
error_messages = []
match = 0
# validate data type: str
# validate data type: UUID
try:
instance.oneof_schema_1_validator = v
match += 1
Expand All @@ -89,7 +92,7 @@ def actual_instance_must_validate_oneof(cls, v):
if match == 0:
# no match
raise ValueError(
"No match found when setting `actual_instance` in AreaId with oneOf schemas: StaticAreaID, str. Details: "
"No match found when setting `actual_instance` in AreaId with oneOf schemas: StaticAreaID, UUID. Details: "
+ ", ".join(error_messages)
)
else:
Expand All @@ -106,7 +109,7 @@ def from_json(cls, json_str: str) -> Self:
error_messages = []
match = 0

# deserialize data into str
# deserialize data into UUID
try:
# validation
instance.oneof_schema_1_validator = json.loads(json_str)
Expand All @@ -125,13 +128,13 @@ def from_json(cls, json_str: str) -> Self:
if match > 1:
# more than 1 match
raise ValueError(
"Multiple matches found when deserializing the JSON string into AreaId with oneOf schemas: StaticAreaID, str. Details: "
"Multiple matches found when deserializing the JSON string into AreaId with oneOf schemas: StaticAreaID, UUID. Details: "
+ ", ".join(error_messages)
)
elif match == 0:
# no match
raise ValueError(
"No match found when deserializing the JSON string into AreaId with oneOf schemas: StaticAreaID, str. Details: "
"No match found when deserializing the JSON string into AreaId with oneOf schemas: StaticAreaID, UUID. Details: "
+ ", ".join(error_messages)
)
else:
Expand All @@ -147,7 +150,7 @@ def to_json(self) -> str:
else:
return json.dumps(self.actual_instance)

def to_dict(self) -> Optional[Union[Dict[str, Any], StaticAreaID, str]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], StaticAreaID, UUID]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None
Expand Down
9 changes: 4 additions & 5 deletions services/iaas/src/stackit/iaas/models/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import re # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set
from uuid import UUID

from pydantic import (
BaseModel,
Expand Down Expand Up @@ -47,9 +48,7 @@ class Backup(BaseModel):
default=None, description="Description Object. Allows string up to 255 Characters."
)
encrypted: Optional[StrictBool] = Field(default=None, description="Indicates if a volume is encrypted.")
id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
default=None, description="Universally Unique Identifier (UUID)."
)
id: Optional[UUID] = Field(default=None, description="Universally Unique Identifier (UUID).")
labels: Optional[Dict[str, Any]] = Field(
default=None,
description="Object that represents the labels of an object. Regex for keys: `^(?=.{1,63}$)([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`. Regex for values: `^(?=.{0,63}$)(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])*$`. Providing a `null` value for a key will remove that key. The `stackit-` prefix is reserved and cannot be used for Keys.",
Expand All @@ -58,7 +57,7 @@ class Backup(BaseModel):
default=None, description="The name for a General Object. Matches Names and also UUIDs."
)
size: Optional[StrictInt] = Field(default=None, description="Size in Gigabyte.")
snapshot_id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
snapshot_id: Optional[UUID] = Field(
default=None, description="Universally Unique Identifier (UUID).", alias="snapshotId"
)
status: Optional[StrictStr] = Field(
Expand All @@ -68,7 +67,7 @@ class Backup(BaseModel):
updated_at: Optional[datetime] = Field(
default=None, description="Date-time when resource was last updated.", alias="updatedAt"
)
volume_id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(
volume_id: Optional[UUID] = Field(
default=None, description="Universally Unique Identifier (UUID).", alias="volumeId"
)
__properties: ClassVar[List[str]] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]:
# override the default output from pydantic by calling `to_dict()` of each item in items (list)
_items = []
if self.items:
for _item in self.items:
if _item:
_items.append(_item.to_dict())
for _item_items in self.items:
if _item_items:
_items.append(_item_items.to_dict())
_dict["items"] = _items
return _dict

Expand Down
Loading
Loading