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/certificates/oas_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8ccf08fdae6320251259ca695f1e7180eeb21275
00b020b2998425397c9a0e51364fe8846fa66880
6 changes: 6 additions & 0 deletions services/certificates/src/stackit/certificates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
"ApiException",
"CertificatesQuota",
"CreateCertificatePayload",
"Data",
"GetCertificateResponse",
"GetQuotaResponse",
"GoogleProtobufAny",
"ListCertificatesResponse",
"Quotas",
"Status",
"Usage",
"UsageItem",
]

# import apis into sdk package
Expand All @@ -59,6 +62,7 @@
from stackit.certificates.models.create_certificate_payload import (
CreateCertificatePayload as CreateCertificatePayload,
)
from stackit.certificates.models.data import Data as Data
from stackit.certificates.models.get_certificate_response import (
GetCertificateResponse as GetCertificateResponse,
)
Expand All @@ -73,3 +77,5 @@
)
from stackit.certificates.models.quotas import Quotas as Quotas
from stackit.certificates.models.status import Status as Status
from stackit.certificates.models.usage import Usage as Usage
from stackit.certificates.models.usage_item import UsageItem as UsageItem
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from stackit.certificates.models.create_certificate_payload import (
CreateCertificatePayload,
)
from stackit.certificates.models.data import Data
from stackit.certificates.models.get_certificate_response import GetCertificateResponse
from stackit.certificates.models.get_quota_response import GetQuotaResponse
from stackit.certificates.models.google_protobuf_any import GoogleProtobufAny
Expand All @@ -25,3 +26,5 @@
)
from stackit.certificates.models.quotas import Quotas
from stackit.certificates.models.status import Status
from stackit.certificates.models.usage import Usage
from stackit.certificates.models.usage_item import UsageItem
220 changes: 220 additions & 0 deletions services/certificates/src/stackit/certificates/models/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# coding: utf-8

"""
STACKIT Application Load Balancer Certificates API

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.

The version of the OpenAPI document: 2.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501

from __future__ import annotations

import json
import pprint
import re # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

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


class Data(BaseModel):
"""
Data
""" # noqa: E501

dns_names: Optional[StrictStr] = Field(
default=None,
description="Comma-separated list of all domains and IP addresses the certificate is valid for (Subject Alternative Names).",
alias="dnsNames",
)
extended_key_usage: Optional[StrictStr] = Field(
default=None,
description="Comma-separated list of purposes the cert is valid for. 'Server Auth' is required for Load Balancer use.",
alias="extendedKeyUsage",
)
fingerprint_sha1: Optional[Annotated[str, Field(strict=True)]] = Field(
default=None,
description="The legacy SHA1 thumbprint. Provided for cross-referencing with older systems and browsers.",
alias="fingerprintSha1",
)
fingerprint_sha256: Optional[Annotated[str, Field(strict=True)]] = Field(
default=None,
description="The unique SHA256 hash of the raw certificate bytes. Use this as the primary unique identifier.",
alias="fingerprintSha256",
)
is_ca: Optional[StrictBool] = Field(
default=None,
description="Indicates if the certificate is a Certificate Authority, meaning it can sign other certificates.",
alias="isCa",
)
is_self_signed: Optional[StrictBool] = Field(
default=None,
description="Indicates if the certificate was signed by its own private key rather than a trusted third-party CA.",
alias="isSelfSigned",
)
issuer_cn: Optional[StrictStr] = Field(
default=None,
description="The Common Name of the Certificate Authority (CA) that signed and issued the certificate.",
alias="issuerCn",
)
key_strength: Optional[StrictStr] = Field(
default=None,
description="Human-readable summary of the public key's algorithm and bit-length or curve name.",
alias="keyStrength",
)
not_after: Optional[StrictStr] = Field(
default=None,
description="The expiration timestamp. After this date, browsers will show security warnings (RFC3339 format).",
alias="notAfter",
)
not_before: Optional[StrictStr] = Field(
default=None,
description="The timestamp indicating when the certificate starts being valid (RFC3339 format).",
alias="notBefore",
)
organization: Optional[StrictStr] = Field(
default=None, description="Organization name associated with the certificate subject."
)
public_key_algorithm: Optional[StrictStr] = Field(
default=None,
description="The cryptographic algorithm used to generate the public/private key pair.",
alias="publicKeyAlgorithm",
)
serial_number: Optional[StrictStr] = Field(
default=None,
description="The unique serial number assigned by the CA, represented in uppercase hexadecimal format.",
alias="serialNumber",
)
signature_algorithm: Optional[StrictStr] = Field(
default=None, description="The algorithm used by the CA to sign this certificate.", alias="signatureAlgorithm"
)
subject_cn: Optional[StrictStr] = Field(
default=None,
description="The primary identity of the certificate. Fallback sequence: Common Name -> First DNS Name -> Full Subject String.",
alias="subjectCn",
)
__properties: ClassVar[List[str]] = [
"dnsNames",
"extendedKeyUsage",
"fingerprintSha1",
"fingerprintSha256",
"isCa",
"isSelfSigned",
"issuerCn",
"keyStrength",
"notAfter",
"notBefore",
"organization",
"publicKeyAlgorithm",
"serialNumber",
"signatureAlgorithm",
"subjectCn",
]

@field_validator("fingerprint_sha1")
def fingerprint_sha1_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if value is None:
return value

if not isinstance(value, str):
value = str(value)

if not re.match(r"^[a-fA-F0-9]{40}$", value):
raise ValueError(r"must validate the regular expression /^[a-fA-F0-9]{40}$/")
return value

@field_validator("fingerprint_sha256")
def fingerprint_sha256_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if value is None:
return value

if not isinstance(value, str):
value = str(value)

if not re.match(r"^[a-fA-F0-9]{64}$", value):
raise ValueError(r"must validate the regular expression /^[a-fA-F0-9]{64}$/")
return value

model_config = ConfigDict(
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)

def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(to_jsonable_python(self.to_dict()))

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of Data from a JSON string"""
return cls.from_dict(json.loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:

* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([])

_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Data from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate(
{
"dnsNames": obj.get("dnsNames"),
"extendedKeyUsage": obj.get("extendedKeyUsage"),
"fingerprintSha1": obj.get("fingerprintSha1"),
"fingerprintSha256": obj.get("fingerprintSha256"),
"isCa": obj.get("isCa"),
"isSelfSigned": obj.get("isSelfSigned"),
"issuerCn": obj.get("issuerCn"),
"keyStrength": obj.get("keyStrength"),
"notAfter": obj.get("notAfter"),
"notBefore": obj.get("notBefore"),
"organization": obj.get("organization"),
"publicKeyAlgorithm": obj.get("publicKeyAlgorithm"),
"serialNumber": obj.get("serialNumber"),
"signatureAlgorithm": obj.get("signatureAlgorithm"),
"subjectCn": obj.get("subjectCn"),
}
)
return _obj
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@
from pydantic_core import to_jsonable_python
from typing_extensions import Annotated, Self

from stackit.certificates.models.data import Data
from stackit.certificates.models.usage import Usage


class GetCertificateResponse(BaseModel):
"""
GetCertificateResponse returns name, id and public key
""" # noqa: E501

data: Optional[Data] = None
id: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The certificates resource id")
labels: Optional[Dict[str, StrictStr]] = Field(
default=None,
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. ",
)
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="TLS certificate name")
name: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Certificate display name")
public_key: Optional[StrictStr] = Field(
default=None, description="The PEM encoded public key part", alias="publicKey"
)
region: Optional[StrictStr] = Field(default=None, description="Region of the LoadBalancer")
__properties: ClassVar[List[str]] = ["id", "labels", "name", "publicKey", "region"]
usage: Optional[Usage] = None
__properties: ClassVar[List[str]] = ["data", "id", "labels", "name", "publicKey", "region", "usage"]

@field_validator("id")
def id_validate_regular_expression(cls, value):
Expand Down Expand Up @@ -103,6 +108,12 @@ def to_dict(self) -> Dict[str, Any]:
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of data
if self.data:
_dict["data"] = self.data.to_dict()
# override the default output from pydantic by calling `to_dict()` of usage
if self.usage:
_dict["usage"] = self.usage.to_dict()
return _dict

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

_obj = cls.model_validate(
{
"data": Data.from_dict(obj["data"]) if obj.get("data") is not None else None,
"id": obj.get("id"),
"labels": obj.get("labels"),
"name": obj.get("name"),
"publicKey": obj.get("publicKey"),
"region": obj.get("region"),
"usage": Usage.from_dict(obj["usage"]) if obj.get("usage") is not None else None,
}
)
return _obj
Loading
Loading