Skip to content

Commit 52719b3

Browse files
Generate certificates
1 parent a6f9daf commit 52719b3

7 files changed

Lines changed: 437 additions & 3 deletions

File tree

services/certificates/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8ccf08fdae6320251259ca695f1e7180eeb21275
1+
00b020b2998425397c9a0e51364fe8846fa66880

services/certificates/src/stackit/certificates/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
"ApiException",
3131
"CertificatesQuota",
3232
"CreateCertificatePayload",
33+
"Data",
3334
"GetCertificateResponse",
3435
"GetQuotaResponse",
3536
"GoogleProtobufAny",
3637
"ListCertificatesResponse",
3738
"Quotas",
3839
"Status",
40+
"Usage",
41+
"UsageItem",
3942
]
4043

4144
# import apis into sdk package
@@ -59,6 +62,7 @@
5962
from stackit.certificates.models.create_certificate_payload import (
6063
CreateCertificatePayload as CreateCertificatePayload,
6164
)
65+
from stackit.certificates.models.data import Data as Data
6266
from stackit.certificates.models.get_certificate_response import (
6367
GetCertificateResponse as GetCertificateResponse,
6468
)
@@ -73,3 +77,5 @@
7377
)
7478
from stackit.certificates.models.quotas import Quotas as Quotas
7579
from stackit.certificates.models.status import Status as Status
80+
from stackit.certificates.models.usage import Usage as Usage
81+
from stackit.certificates.models.usage_item import UsageItem as UsageItem

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from stackit.certificates.models.create_certificate_payload import (
1818
CreateCertificatePayload,
1919
)
20+
from stackit.certificates.models.data import Data
2021
from stackit.certificates.models.get_certificate_response import GetCertificateResponse
2122
from stackit.certificates.models.get_quota_response import GetQuotaResponse
2223
from stackit.certificates.models.google_protobuf_any import GoogleProtobufAny
@@ -25,3 +26,5 @@
2526
)
2627
from stackit.certificates.models.quotas import Quotas
2728
from stackit.certificates.models.status import Status
29+
from stackit.certificates.models.usage import Usage
30+
from stackit.certificates.models.usage_item import UsageItem
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# coding: utf-8
2+
3+
"""
4+
STACKIT Application Load Balancer Certificates API
5+
6+
This API offers the ability to store TLS certificates, which can be used by load balancing servers in STACKIT. They can be between consumer and load balancing server and/or between load balancing server and endpoint server.
7+
8+
The version of the OpenAPI document: 2.0.0
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
""" # noqa: E501
13+
14+
from __future__ import annotations
15+
16+
import json
17+
import pprint
18+
import re # noqa: F401
19+
from typing import Any, ClassVar, Dict, List, Optional, Set
20+
21+
from pydantic import (
22+
BaseModel,
23+
ConfigDict,
24+
Field,
25+
StrictBool,
26+
StrictStr,
27+
field_validator,
28+
)
29+
from pydantic_core import to_jsonable_python
30+
from typing_extensions import Annotated, Self
31+
32+
33+
class Data(BaseModel):
34+
"""
35+
Data
36+
""" # noqa: E501
37+
38+
dns_names: Optional[StrictStr] = Field(
39+
default=None,
40+
description="Comma-separated list of all domains and IP addresses the certificate is valid for (Subject Alternative Names).",
41+
alias="dnsNames",
42+
)
43+
extended_key_usage: Optional[StrictStr] = Field(
44+
default=None,
45+
description="Comma-separated list of purposes the cert is valid for. 'Server Auth' is required for Load Balancer use.",
46+
alias="extendedKeyUsage",
47+
)
48+
fingerprint_sha1: Optional[Annotated[str, Field(strict=True)]] = Field(
49+
default=None,
50+
description="The legacy SHA1 thumbprint. Provided for cross-referencing with older systems and browsers.",
51+
alias="fingerprintSha1",
52+
)
53+
fingerprint_sha256: Optional[Annotated[str, Field(strict=True)]] = Field(
54+
default=None,
55+
description="The unique SHA256 hash of the raw certificate bytes. Use this as the primary unique identifier.",
56+
alias="fingerprintSha256",
57+
)
58+
is_ca: Optional[StrictBool] = Field(
59+
default=None,
60+
description="Indicates if the certificate is a Certificate Authority, meaning it can sign other certificates.",
61+
alias="isCa",
62+
)
63+
is_self_signed: Optional[StrictBool] = Field(
64+
default=None,
65+
description="Indicates if the certificate was signed by its own private key rather than a trusted third-party CA.",
66+
alias="isSelfSigned",
67+
)
68+
issuer_cn: Optional[StrictStr] = Field(
69+
default=None,
70+
description="The Common Name of the Certificate Authority (CA) that signed and issued the certificate.",
71+
alias="issuerCn",
72+
)
73+
key_strength: Optional[StrictStr] = Field(
74+
default=None,
75+
description="Human-readable summary of the public key's algorithm and bit-length or curve name.",
76+
alias="keyStrength",
77+
)
78+
not_after: Optional[StrictStr] = Field(
79+
default=None,
80+
description="The expiration timestamp. After this date, browsers will show security warnings (RFC3339 format).",
81+
alias="notAfter",
82+
)
83+
not_before: Optional[StrictStr] = Field(
84+
default=None,
85+
description="The timestamp indicating when the certificate starts being valid (RFC3339 format).",
86+
alias="notBefore",
87+
)
88+
organization: Optional[StrictStr] = Field(
89+
default=None, description="Organization name associated with the certificate subject."
90+
)
91+
public_key_algorithm: Optional[StrictStr] = Field(
92+
default=None,
93+
description="The cryptographic algorithm used to generate the public/private key pair.",
94+
alias="publicKeyAlgorithm",
95+
)
96+
serial_number: Optional[StrictStr] = Field(
97+
default=None,
98+
description="The unique serial number assigned by the CA, represented in uppercase hexadecimal format.",
99+
alias="serialNumber",
100+
)
101+
signature_algorithm: Optional[StrictStr] = Field(
102+
default=None, description="The algorithm used by the CA to sign this certificate.", alias="signatureAlgorithm"
103+
)
104+
subject_cn: Optional[StrictStr] = Field(
105+
default=None,
106+
description="The primary identity of the certificate. Fallback sequence: Common Name -> First DNS Name -> Full Subject String.",
107+
alias="subjectCn",
108+
)
109+
__properties: ClassVar[List[str]] = [
110+
"dnsNames",
111+
"extendedKeyUsage",
112+
"fingerprintSha1",
113+
"fingerprintSha256",
114+
"isCa",
115+
"isSelfSigned",
116+
"issuerCn",
117+
"keyStrength",
118+
"notAfter",
119+
"notBefore",
120+
"organization",
121+
"publicKeyAlgorithm",
122+
"serialNumber",
123+
"signatureAlgorithm",
124+
"subjectCn",
125+
]
126+
127+
@field_validator("fingerprint_sha1")
128+
def fingerprint_sha1_validate_regular_expression(cls, value):
129+
"""Validates the regular expression"""
130+
if value is None:
131+
return value
132+
133+
if not isinstance(value, str):
134+
value = str(value)
135+
136+
if not re.match(r"^[a-fA-F0-9]{40}$", value):
137+
raise ValueError(r"must validate the regular expression /^[a-fA-F0-9]{40}$/")
138+
return value
139+
140+
@field_validator("fingerprint_sha256")
141+
def fingerprint_sha256_validate_regular_expression(cls, value):
142+
"""Validates the regular expression"""
143+
if value is None:
144+
return value
145+
146+
if not isinstance(value, str):
147+
value = str(value)
148+
149+
if not re.match(r"^[a-fA-F0-9]{64}$", value):
150+
raise ValueError(r"must validate the regular expression /^[a-fA-F0-9]{64}$/")
151+
return value
152+
153+
model_config = ConfigDict(
154+
validate_by_name=True,
155+
validate_by_alias=True,
156+
validate_assignment=True,
157+
protected_namespaces=(),
158+
)
159+
160+
def to_str(self) -> str:
161+
"""Returns the string representation of the model using alias"""
162+
return pprint.pformat(self.model_dump(by_alias=True))
163+
164+
def to_json(self) -> str:
165+
"""Returns the JSON representation of the model using alias"""
166+
return json.dumps(to_jsonable_python(self.to_dict()))
167+
168+
@classmethod
169+
def from_json(cls, json_str: str) -> Optional[Self]:
170+
"""Create an instance of Data from a JSON string"""
171+
return cls.from_dict(json.loads(json_str))
172+
173+
def to_dict(self) -> Dict[str, Any]:
174+
"""Return the dictionary representation of the model using alias.
175+
176+
This has the following differences from calling pydantic's
177+
`self.model_dump(by_alias=True)`:
178+
179+
* `None` is only added to the output dict for nullable fields that
180+
were set at model initialization. Other fields with value `None`
181+
are ignored.
182+
"""
183+
excluded_fields: Set[str] = set([])
184+
185+
_dict = self.model_dump(
186+
by_alias=True,
187+
exclude=excluded_fields,
188+
exclude_none=True,
189+
)
190+
return _dict
191+
192+
@classmethod
193+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
194+
"""Create an instance of Data from a dict"""
195+
if obj is None:
196+
return None
197+
198+
if not isinstance(obj, dict):
199+
return cls.model_validate(obj)
200+
201+
_obj = cls.model_validate(
202+
{
203+
"dnsNames": obj.get("dnsNames"),
204+
"extendedKeyUsage": obj.get("extendedKeyUsage"),
205+
"fingerprintSha1": obj.get("fingerprintSha1"),
206+
"fingerprintSha256": obj.get("fingerprintSha256"),
207+
"isCa": obj.get("isCa"),
208+
"isSelfSigned": obj.get("isSelfSigned"),
209+
"issuerCn": obj.get("issuerCn"),
210+
"keyStrength": obj.get("keyStrength"),
211+
"notAfter": obj.get("notAfter"),
212+
"notBefore": obj.get("notBefore"),
213+
"organization": obj.get("organization"),
214+
"publicKeyAlgorithm": obj.get("publicKeyAlgorithm"),
215+
"serialNumber": obj.get("serialNumber"),
216+
"signatureAlgorithm": obj.get("signatureAlgorithm"),
217+
"subjectCn": obj.get("subjectCn"),
218+
}
219+
)
220+
return _obj

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,28 @@
2222
from pydantic_core import to_jsonable_python
2323
from typing_extensions import Annotated, Self
2424

25+
from stackit.certificates.models.data import Data
26+
from stackit.certificates.models.usage import Usage
27+
2528

2629
class GetCertificateResponse(BaseModel):
2730
"""
2831
GetCertificateResponse returns name, id and public key
2932
""" # noqa: E501
3033

34+
data: Optional[Data] = None
3135
id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The certificates resource id")
3236
labels: Optional[Dict[str, StrictStr]] = Field(
3337
default=None,
3438
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. ",
3539
)
36-
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="TLS certificate name")
40+
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Certificate display name")
3741
public_key: Optional[StrictStr] = Field(
3842
default=None, description="The PEM encoded public key part", alias="publicKey"
3943
)
4044
region: Optional[StrictStr] = Field(default=None, description="Region of the LoadBalancer")
41-
__properties: ClassVar[List[str]] = ["id", "labels", "name", "publicKey", "region"]
45+
usage: Optional[Usage] = None
46+
__properties: ClassVar[List[str]] = ["data", "id", "labels", "name", "publicKey", "region", "usage"]
4247

4348
@field_validator("id")
4449
def id_validate_regular_expression(cls, value):
@@ -103,6 +108,12 @@ def to_dict(self) -> Dict[str, Any]:
103108
exclude=excluded_fields,
104109
exclude_none=True,
105110
)
111+
# override the default output from pydantic by calling `to_dict()` of data
112+
if self.data:
113+
_dict["data"] = self.data.to_dict()
114+
# override the default output from pydantic by calling `to_dict()` of usage
115+
if self.usage:
116+
_dict["usage"] = self.usage.to_dict()
106117
return _dict
107118

108119
@classmethod
@@ -116,11 +127,13 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
116127

117128
_obj = cls.model_validate(
118129
{
130+
"data": Data.from_dict(obj["data"]) if obj.get("data") is not None else None,
119131
"id": obj.get("id"),
120132
"labels": obj.get("labels"),
121133
"name": obj.get("name"),
122134
"publicKey": obj.get("publicKey"),
123135
"region": obj.get("region"),
136+
"usage": Usage.from_dict(obj["usage"]) if obj.get("usage") is not None else None,
124137
}
125138
)
126139
return _obj

0 commit comments

Comments
 (0)