Skip to content

Commit fa71f81

Browse files
Generate certificates
1 parent 875e273 commit fa71f81

10 files changed

Lines changed: 84 additions & 44 deletions

File tree

services/certificates/oas_commit

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

services/certificates/src/stackit/certificates/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/certificates/src/stackit/certificates/models/certificates_quota.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
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Annotated, Self
2223

2324

@@ -35,7 +36,8 @@ class CertificatesQuota(BaseModel):
3536
__properties: ClassVar[List[str]] = ["limit", "usage"]
3637

3738
model_config = ConfigDict(
38-
populate_by_name=True,
39+
validate_by_name=True,
40+
validate_by_alias=True,
3941
validate_assignment=True,
4042
protected_namespaces=(),
4143
)
@@ -46,8 +48,7 @@ def to_str(self) -> str:
4648

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

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

services/certificates/src/stackit/certificates/models/create_certificate_payload.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from uuid import UUID
2121

2222
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Annotated, Self
2425

2526

@@ -28,6 +29,10 @@ class CreateCertificatePayload(BaseModel):
2829
Uploads a PEM encoded X509 public/private key pair
2930
""" # noqa: E501
3031

32+
labels: Optional[Dict[str, StrictStr]] = Field(
33+
default=None,
34+
description="Labels represent user-defined metadata as key-value pairs. Label count should not exceed 64 per Certificate. **Key Formatting Rules:** Length: 1-63 characters. Characters: Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. Keys starting with 'stackit-' are system-reserved; users MUST NOT manage them. **Value Formatting Rules:** Length: 0-63 characters (empty string explicitly allowed). Characters (for non-empty values): Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. ",
35+
)
3136
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="TLS certificate name")
3237
private_key: Optional[StrictStr] = Field(
3338
default=None, description="The PEM encoded private key part", alias="privateKey"
@@ -37,14 +42,17 @@ class CreateCertificatePayload(BaseModel):
3742
default=None, description="The PEM encoded public key part", alias="publicKey"
3843
)
3944
region: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Region")
40-
__properties: ClassVar[List[str]] = ["name", "privateKey", "projectId", "publicKey", "region"]
45+
__properties: ClassVar[List[str]] = ["labels", "name", "privateKey", "projectId", "publicKey", "region"]
4146

4247
@field_validator("name")
4348
def name_validate_regular_expression(cls, value):
4449
"""Validates the regular expression"""
4550
if value is None:
4651
return value
4752

53+
if not isinstance(value, str):
54+
value = str(value)
55+
4856
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$", value):
4957
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$/")
5058
return value
@@ -55,6 +63,9 @@ def project_id_validate_regular_expression(cls, value):
5563
if value is None:
5664
return value
5765

66+
if not isinstance(value, str):
67+
value = str(value)
68+
5869
if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", value):
5970
raise ValueError(
6071
r"must validate the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/"
@@ -67,12 +78,16 @@ def region_validate_regular_expression(cls, value):
6778
if value is None:
6879
return value
6980

81+
if not isinstance(value, str):
82+
value = str(value)
83+
7084
if not re.match(r"^[a-z]{2,4}[0-9]{2}$", value):
7185
raise ValueError(r"must validate the regular expression /^[a-z]{2,4}[0-9]{2}$/")
7286
return value
7387

7488
model_config = ConfigDict(
75-
populate_by_name=True,
89+
validate_by_name=True,
90+
validate_by_alias=True,
7691
validate_assignment=True,
7792
protected_namespaces=(),
7893
)
@@ -83,8 +98,7 @@ def to_str(self) -> str:
8398

8499
def to_json(self) -> str:
85100
"""Returns the JSON representation of the model using alias"""
86-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
87-
return json.dumps(self.to_dict())
101+
return json.dumps(to_jsonable_python(self.to_dict()))
88102

89103
@classmethod
90104
def from_json(cls, json_str: str) -> Optional[Self]:
@@ -128,6 +142,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
128142

129143
_obj = cls.model_validate(
130144
{
145+
"labels": obj.get("labels"),
131146
"name": obj.get("name"),
132147
"privateKey": obj.get("privateKey"),
133148
"projectId": obj.get("projectId"),

services/certificates/src/stackit/certificates/models/get_certificate_response.py

Lines changed: 16 additions & 4 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

@@ -28,19 +29,26 @@ class GetCertificateResponse(BaseModel):
2829
""" # noqa: E501
2930

3031
id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The certificates resource id")
32+
labels: Optional[Dict[str, StrictStr]] = Field(
33+
default=None,
34+
description="Labels represent user-defined metadata as key-value pairs. Label count should not exceed 64 per Certificate. **Key Formatting Rules:** Length: 1-63 characters. Characters: Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. Keys starting with 'stackit-' are system-reserved; users MUST NOT manage them. **Value Formatting Rules:** Length: 0-63 characters (empty string explicitly allowed). Characters (for non-empty values): Must begin and end with [a-zA-Z0-9]. May contain dashes (-), underscores (_), dots (.), and alphanumerics in between. ",
35+
)
3136
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="TLS certificate name")
3237
public_key: Optional[StrictStr] = Field(
3338
default=None, description="The PEM encoded public key part", alias="publicKey"
3439
)
3540
region: Optional[StrictStr] = Field(default=None, description="Region of the LoadBalancer")
36-
__properties: ClassVar[List[str]] = ["id", "name", "publicKey", "region"]
41+
__properties: ClassVar[List[str]] = ["id", "labels", "name", "publicKey", "region"]
3742

3843
@field_validator("id")
3944
def id_validate_regular_expression(cls, value):
4045
"""Validates the regular expression"""
4146
if value is None:
4247
return value
4348

49+
if not isinstance(value, str):
50+
value = str(value)
51+
4452
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$", value):
4553
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$/")
4654
return value
@@ -51,12 +59,16 @@ def name_validate_regular_expression(cls, value):
5159
if value is None:
5260
return value
5361

62+
if not isinstance(value, str):
63+
value = str(value)
64+
5465
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$", value):
5566
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$/")
5667
return value
5768

5869
model_config = ConfigDict(
59-
populate_by_name=True,
70+
validate_by_name=True,
71+
validate_by_alias=True,
6072
validate_assignment=True,
6173
protected_namespaces=(),
6274
)
@@ -67,8 +79,7 @@ def to_str(self) -> str:
6779

6880
def to_json(self) -> str:
6981
"""Returns the JSON representation of the model using alias"""
70-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
71-
return json.dumps(self.to_dict())
82+
return json.dumps(to_jsonable_python(self.to_dict()))
7283

7384
@classmethod
7485
def from_json(cls, json_str: str) -> Optional[Self]:
@@ -106,6 +117,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
106117
_obj = cls.model_validate(
107118
{
108119
"id": obj.get("id"),
120+
"labels": obj.get("labels"),
109121
"name": obj.get("name"),
110122
"publicKey": obj.get("publicKey"),
111123
"region": obj.get("region"),

services/certificates/src/stackit/certificates/models/get_quota_response.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from uuid import UUID
2121

2222
from pydantic import BaseModel, ConfigDict, Field, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Annotated, Self
2425

2526
from stackit.certificates.models.quotas import Quotas
@@ -41,6 +42,9 @@ def project_id_validate_regular_expression(cls, value):
4142
if value is None:
4243
return value
4344

45+
if not isinstance(value, str):
46+
value = str(value)
47+
4448
if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", value):
4549
raise ValueError(
4650
r"must validate the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/"
@@ -53,12 +57,16 @@ def region_validate_regular_expression(cls, value):
5357
if value is None:
5458
return value
5559

60+
if not isinstance(value, str):
61+
value = str(value)
62+
5663
if not re.match(r"^[a-z]{2,4}[0-9]{2}$", value):
5764
raise ValueError(r"must validate the regular expression /^[a-z]{2,4}[0-9]{2}$/")
5865
return value
5966

6067
model_config = ConfigDict(
61-
populate_by_name=True,
68+
validate_by_name=True,
69+
validate_by_alias=True,
6270
validate_assignment=True,
6371
protected_namespaces=(),
6472
)
@@ -69,8 +77,7 @@ def to_str(self) -> str:
6977

7078
def to_json(self) -> str:
7179
"""Returns the JSON representation of the model using alias"""
72-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
73-
return json.dumps(self.to_dict())
80+
return json.dumps(to_jsonable_python(self.to_dict()))
7481

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

services/certificates/src/stackit/certificates/models/google_protobuf_any.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

@@ -31,7 +32,8 @@ class GoogleProtobufAny(BaseModel):
3132
__properties: ClassVar[List[str]] = ["@type"]
3233

3334
model_config = ConfigDict(
34-
populate_by_name=True,
35+
validate_by_name=True,
36+
validate_by_alias=True,
3537
validate_assignment=True,
3638
protected_namespaces=(),
3739
)
@@ -42,8 +44,7 @@ def to_str(self) -> str:
4244

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

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

services/certificates/src/stackit/certificates/models/list_certificates_response.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, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.certificates.models.get_certificate_response import GetCertificateResponse
@@ -43,12 +44,16 @@ def next_page_id_validate_regular_expression(cls, value):
4344
if value is None:
4445
return value
4546

47+
if not isinstance(value, str):
48+
value = str(value)
49+
4650
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$", value):
4751
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$/")
4852
return value
4953

5054
model_config = ConfigDict(
51-
populate_by_name=True,
55+
validate_by_name=True,
56+
validate_by_alias=True,
5257
validate_assignment=True,
5358
protected_namespaces=(),
5459
)
@@ -59,8 +64,7 @@ def to_str(self) -> str:
5964

6065
def to_json(self) -> str:
6166
"""Returns the JSON representation of the model using alias"""
62-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
63-
return json.dumps(self.to_dict())
67+
return json.dumps(to_jsonable_python(self.to_dict()))
6468

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

services/certificates/src/stackit/certificates/models/quotas.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
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324
from stackit.certificates.models.certificates_quota import CertificatesQuota
@@ -32,7 +33,8 @@ class Quotas(BaseModel):
3233
__properties: ClassVar[List[str]] = ["certificates"]
3334

3435
model_config = ConfigDict(
35-
populate_by_name=True,
36+
validate_by_name=True,
37+
validate_by_alias=True,
3638
validate_assignment=True,
3739
protected_namespaces=(),
3840
)
@@ -43,8 +45,7 @@ def to_str(self) -> str:
4345

4446
def to_json(self) -> str:
4547
"""Returns the JSON representation of the model using alias"""
46-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47-
return json.dumps(self.to_dict())
48+
return json.dumps(to_jsonable_python(self.to_dict()))
4849

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

0 commit comments

Comments
 (0)