diff --git a/CHANGELOG.md b/CHANGELOG.md index 913c98fd..892ad538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,13 @@ - **Version**: Minimal version is now python 3.9 - `authorization`: [v0.3.0](services/authorization/CHANGELOG.md#v030) - **Version**: Minimal version is now python 3.9 -- `cdn`: [v1.4.0](services/cdn/CHANGELOG.md#v140) - - **Version**: Minimal version is now python 3.9 +- `cdn`: + - [v1.5.0](services/cdn/CHANGELOG.md#v150) + - **Feature:** Added new filter functions `DataCenterRegion`, `RequestCountryCode`, `StatusCode` and `CacheHit` + - **Feature:** Added Attribute `LogSink` and `Certificate` + - **Feature:** Added `ConfigLogSink` and `PatchLokiLogSink` functionality + - [v1.4.0](services/cdn/CHANGELOG.md#v140) + - **Version**: Minimal version is now python 3.9 - `certificates`: [v1.1.0](services/certificates/CHANGELOG.md#v110) - **Version**: Minimal version is now python 3.9 - `dns`: [v0.5.0](services/dns/CHANGELOG.md#v050) diff --git a/services/cdn/CHANGELOG.md b/services/cdn/CHANGELOG.md index 09d1611f..08454539 100644 --- a/services/cdn/CHANGELOG.md +++ b/services/cdn/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.5.0 +- **Feature:** Added new filter functions `DataCenterRegion`, `RequestCountryCode`, `StatusCode` and `CacheHit` +- **Feature:** Added Attribute `LogSink` and `Certificate` +- **Feature:** Added `ConfigLogSink` and `PatchLokiLogSink` functionality + ## v1.4.0 - **Version**: Minimal version is now python 3.9 diff --git a/services/cdn/pyproject.toml b/services/cdn/pyproject.toml index ed7b304a..051c1040 100644 --- a/services/cdn/pyproject.toml +++ b/services/cdn/pyproject.toml @@ -3,7 +3,7 @@ name = "stackit-cdn" [tool.poetry] name = "stackit-cdn" -version = "v1.4.0" +version = "v1.5.0" authors = [ "STACKIT Developer Tools ", ] diff --git a/services/cdn/src/stackit/cdn/__init__.py b/services/cdn/src/stackit/cdn/__init__.py index 87a241e1..4dec4f51 100644 --- a/services/cdn/src/stackit/cdn/__init__.py +++ b/services/cdn/src/stackit/cdn/__init__.py @@ -48,20 +48,29 @@ "GenericJSONResponse", "GetCacheInfoResponse", "GetCacheInfoResponseHistoryEntry", + "GetCustomDomainCustomCertificate", + "GetCustomDomainManagedCertificate", "GetCustomDomainResponse", + "GetCustomDomainResponseCertificate", "GetDistributionResponse", "GetLogsResponse", "GetStatisticsResponse", "HttpBackend", "HttpBackendPatch", "ListDistributionsResponse", + "LokiLogSink", "Optimizer", "OptimizerPatch", "PatchDistributionPayload", "PatchDistributionResponse", + "PatchLokiLogSink", "PurgeCachePayload", + "PutCustomDomainCustomCertificate", + "PutCustomDomainManagedCertificate", "PutCustomDomainPayload", + "PutCustomDomainPayloadCertificate", "PutCustomDomainResponse", + "PutCustomDomainResponseCertificate", "Region", "StatusError", ] @@ -127,9 +136,18 @@ from stackit.cdn.models.get_cache_info_response_history_entry import ( GetCacheInfoResponseHistoryEntry as GetCacheInfoResponseHistoryEntry, ) +from stackit.cdn.models.get_custom_domain_custom_certificate import ( + GetCustomDomainCustomCertificate as GetCustomDomainCustomCertificate, +) +from stackit.cdn.models.get_custom_domain_managed_certificate import ( + GetCustomDomainManagedCertificate as GetCustomDomainManagedCertificate, +) from stackit.cdn.models.get_custom_domain_response import ( GetCustomDomainResponse as GetCustomDomainResponse, ) +from stackit.cdn.models.get_custom_domain_response_certificate import ( + GetCustomDomainResponseCertificate as GetCustomDomainResponseCertificate, +) from stackit.cdn.models.get_distribution_response import ( GetDistributionResponse as GetDistributionResponse, ) @@ -142,6 +160,7 @@ from stackit.cdn.models.list_distributions_response import ( ListDistributionsResponse as ListDistributionsResponse, ) +from stackit.cdn.models.loki_log_sink import LokiLogSink as LokiLogSink from stackit.cdn.models.optimizer import Optimizer as Optimizer from stackit.cdn.models.optimizer_patch import OptimizerPatch as OptimizerPatch from stackit.cdn.models.patch_distribution_payload import ( @@ -150,14 +169,27 @@ from stackit.cdn.models.patch_distribution_response import ( PatchDistributionResponse as PatchDistributionResponse, ) +from stackit.cdn.models.patch_loki_log_sink import PatchLokiLogSink as PatchLokiLogSink from stackit.cdn.models.purge_cache_payload import ( PurgeCachePayload as PurgeCachePayload, ) +from stackit.cdn.models.put_custom_domain_custom_certificate import ( + PutCustomDomainCustomCertificate as PutCustomDomainCustomCertificate, +) +from stackit.cdn.models.put_custom_domain_managed_certificate import ( + PutCustomDomainManagedCertificate as PutCustomDomainManagedCertificate, +) from stackit.cdn.models.put_custom_domain_payload import ( PutCustomDomainPayload as PutCustomDomainPayload, ) +from stackit.cdn.models.put_custom_domain_payload_certificate import ( + PutCustomDomainPayloadCertificate as PutCustomDomainPayloadCertificate, +) from stackit.cdn.models.put_custom_domain_response import ( PutCustomDomainResponse as PutCustomDomainResponse, ) +from stackit.cdn.models.put_custom_domain_response_certificate import ( + PutCustomDomainResponseCertificate as PutCustomDomainResponseCertificate, +) from stackit.cdn.models.region import Region as Region from stackit.cdn.models.status_error import StatusError as StatusError diff --git a/services/cdn/src/stackit/cdn/api/default_api.py b/services/cdn/src/stackit/cdn/api/default_api.py index 8ec31172..6468b2ad 100644 --- a/services/cdn/src/stackit/cdn/api/default_api.py +++ b/services/cdn/src/stackit/cdn/api/default_api.py @@ -16,6 +16,7 @@ from pydantic import ( Field, + StrictBool, StrictFloat, StrictInt, StrictStr, @@ -1971,6 +1972,30 @@ def get_logs( ), ] = None, sort_order: Optional[StrictStr] = None, + data_center_region: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the CDN data center region that served the request. Can be combined with other filters " + ), + ] = None, + request_country_code: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the originating country of the user request. Can be combined with other filters " + ), + ] = None, + status_code: Annotated[ + Optional[StrictInt], + Field( + description="Filters by the HTTP status code returned to the client. Can be combined with other filters " + ), + ] = None, + cache_hit: Annotated[ + Optional[StrictBool], + Field( + description="Filters based on whether the request was served from the CDN cache. Can be combined with other filters " + ), + ] = None, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -2000,6 +2025,14 @@ def get_logs( :type sort_by: str :param sort_order: :type sort_order: str + :param data_center_region: Filters by the CDN data center region that served the request. Can be combined with other filters + :type data_center_region: str + :param request_country_code: Filters by the originating country of the user request. Can be combined with other filters + :type request_country_code: str + :param status_code: Filters by the HTTP status code returned to the client. Can be combined with other filters + :type status_code: int + :param cache_hit: Filters based on whether the request was served from the CDN cache. Can be combined with other filters + :type cache_hit: bool :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -2031,6 +2064,10 @@ def get_logs( page_identifier=page_identifier, sort_by=sort_by, sort_order=sort_order, + data_center_region=data_center_region, + request_country_code=request_country_code, + status_code=status_code, + cache_hit=cache_hit, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -2083,6 +2120,30 @@ def get_logs_with_http_info( ), ] = None, sort_order: Optional[StrictStr] = None, + data_center_region: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the CDN data center region that served the request. Can be combined with other filters " + ), + ] = None, + request_country_code: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the originating country of the user request. Can be combined with other filters " + ), + ] = None, + status_code: Annotated[ + Optional[StrictInt], + Field( + description="Filters by the HTTP status code returned to the client. Can be combined with other filters " + ), + ] = None, + cache_hit: Annotated[ + Optional[StrictBool], + Field( + description="Filters based on whether the request was served from the CDN cache. Can be combined with other filters " + ), + ] = None, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -2112,6 +2173,14 @@ def get_logs_with_http_info( :type sort_by: str :param sort_order: :type sort_order: str + :param data_center_region: Filters by the CDN data center region that served the request. Can be combined with other filters + :type data_center_region: str + :param request_country_code: Filters by the originating country of the user request. Can be combined with other filters + :type request_country_code: str + :param status_code: Filters by the HTTP status code returned to the client. Can be combined with other filters + :type status_code: int + :param cache_hit: Filters based on whether the request was served from the CDN cache. Can be combined with other filters + :type cache_hit: bool :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -2143,6 +2212,10 @@ def get_logs_with_http_info( page_identifier=page_identifier, sort_by=sort_by, sort_order=sort_order, + data_center_region=data_center_region, + request_country_code=request_country_code, + status_code=status_code, + cache_hit=cache_hit, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -2195,6 +2268,30 @@ def get_logs_without_preload_content( ), ] = None, sort_order: Optional[StrictStr] = None, + data_center_region: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the CDN data center region that served the request. Can be combined with other filters " + ), + ] = None, + request_country_code: Annotated[ + Optional[StrictStr], + Field( + description="Filters by the originating country of the user request. Can be combined with other filters " + ), + ] = None, + status_code: Annotated[ + Optional[StrictInt], + Field( + description="Filters by the HTTP status code returned to the client. Can be combined with other filters " + ), + ] = None, + cache_hit: Annotated[ + Optional[StrictBool], + Field( + description="Filters based on whether the request was served from the CDN cache. Can be combined with other filters " + ), + ] = None, _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -2224,6 +2321,14 @@ def get_logs_without_preload_content( :type sort_by: str :param sort_order: :type sort_order: str + :param data_center_region: Filters by the CDN data center region that served the request. Can be combined with other filters + :type data_center_region: str + :param request_country_code: Filters by the originating country of the user request. Can be combined with other filters + :type request_country_code: str + :param status_code: Filters by the HTTP status code returned to the client. Can be combined with other filters + :type status_code: int + :param cache_hit: Filters based on whether the request was served from the CDN cache. Can be combined with other filters + :type cache_hit: bool :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -2255,6 +2360,10 @@ def get_logs_without_preload_content( page_identifier=page_identifier, sort_by=sort_by, sort_order=sort_order, + data_center_region=data_center_region, + request_country_code=request_country_code, + status_code=status_code, + cache_hit=cache_hit, _request_auth=_request_auth, _content_type=_content_type, _headers=_headers, @@ -2280,6 +2389,10 @@ def _get_logs_serialize( page_identifier, sort_by, sort_order, + data_center_region, + request_country_code, + status_code, + cache_hit, _request_auth, _content_type, _headers, @@ -2331,6 +2444,22 @@ def _get_logs_serialize( _query_params.append(("sortOrder", sort_order)) + if data_center_region is not None: + + _query_params.append(("dataCenterRegion", data_center_region)) + + if request_country_code is not None: + + _query_params.append(("requestCountryCode", request_country_code)) + + if status_code is not None: + + _query_params.append(("statusCode", status_code)) + + if cache_hit is not None: + + _query_params.append(("cacheHit", cache_hit)) + # process the header parameters # process the form parameters # process the body parameter diff --git a/services/cdn/src/stackit/cdn/models/__init__.py b/services/cdn/src/stackit/cdn/models/__init__.py index df8cccc5..02646f44 100644 --- a/services/cdn/src/stackit/cdn/models/__init__.py +++ b/services/cdn/src/stackit/cdn/models/__init__.py @@ -44,19 +44,42 @@ from stackit.cdn.models.get_cache_info_response_history_entry import ( GetCacheInfoResponseHistoryEntry, ) +from stackit.cdn.models.get_custom_domain_custom_certificate import ( + GetCustomDomainCustomCertificate, +) +from stackit.cdn.models.get_custom_domain_managed_certificate import ( + GetCustomDomainManagedCertificate, +) from stackit.cdn.models.get_custom_domain_response import GetCustomDomainResponse +from stackit.cdn.models.get_custom_domain_response_certificate import ( + GetCustomDomainResponseCertificate, +) from stackit.cdn.models.get_distribution_response import GetDistributionResponse from stackit.cdn.models.get_logs_response import GetLogsResponse from stackit.cdn.models.get_statistics_response import GetStatisticsResponse from stackit.cdn.models.http_backend import HttpBackend from stackit.cdn.models.http_backend_patch import HttpBackendPatch from stackit.cdn.models.list_distributions_response import ListDistributionsResponse +from stackit.cdn.models.loki_log_sink import LokiLogSink from stackit.cdn.models.optimizer import Optimizer from stackit.cdn.models.optimizer_patch import OptimizerPatch from stackit.cdn.models.patch_distribution_payload import PatchDistributionPayload from stackit.cdn.models.patch_distribution_response import PatchDistributionResponse +from stackit.cdn.models.patch_loki_log_sink import PatchLokiLogSink from stackit.cdn.models.purge_cache_payload import PurgeCachePayload +from stackit.cdn.models.put_custom_domain_custom_certificate import ( + PutCustomDomainCustomCertificate, +) +from stackit.cdn.models.put_custom_domain_managed_certificate import ( + PutCustomDomainManagedCertificate, +) from stackit.cdn.models.put_custom_domain_payload import PutCustomDomainPayload +from stackit.cdn.models.put_custom_domain_payload_certificate import ( + PutCustomDomainPayloadCertificate, +) from stackit.cdn.models.put_custom_domain_response import PutCustomDomainResponse +from stackit.cdn.models.put_custom_domain_response_certificate import ( + PutCustomDomainResponseCertificate, +) from stackit.cdn.models.region import Region from stackit.cdn.models.status_error import StatusError diff --git a/services/cdn/src/stackit/cdn/models/config.py b/services/cdn/src/stackit/cdn/models/config.py index 95987638..f570e172 100644 --- a/services/cdn/src/stackit/cdn/models/config.py +++ b/services/cdn/src/stackit/cdn/models/config.py @@ -21,6 +21,7 @@ from typing_extensions import Annotated, Self from stackit.cdn.models.http_backend import HttpBackend +from stackit.cdn.models.loki_log_sink import LokiLogSink from stackit.cdn.models.optimizer import Optimizer from stackit.cdn.models.region import Region @@ -44,6 +45,7 @@ class Config(BaseModel): description="Sets the default cache duration for the distribution. The default cache duration is applied when a 'Cache-Control' header is not presented in the origin's response. We use ISO8601 duration format for cache duration (e.g. P1DT2H30M) ", alias="defaultCacheDuration", ) + log_sink: Optional[LokiLogSink] = Field(default=None, alias="logSink") monthly_limit_bytes: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field( default=None, description="Sets the monthly limit of bandwidth in bytes that the pullzone is allowed to use. ", @@ -56,6 +58,7 @@ class Config(BaseModel): "blockedCountries", "blockedIPs", "defaultCacheDuration", + "logSink", "monthlyLimitBytes", "optimizer", "regions", @@ -101,6 +104,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of backend if self.backend: _dict["backend"] = self.backend.to_dict() + # override the default output from pydantic by calling `to_dict()` of log_sink + if self.log_sink: + _dict["logSink"] = self.log_sink.to_dict() # override the default output from pydantic by calling `to_dict()` of optimizer if self.optimizer: _dict["optimizer"] = self.optimizer.to_dict() @@ -131,6 +137,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "blockedCountries": obj.get("blockedCountries"), "blockedIPs": obj.get("blockedIPs"), "defaultCacheDuration": obj.get("defaultCacheDuration"), + "logSink": LokiLogSink.from_dict(obj["logSink"]) if obj.get("logSink") is not None else None, "monthlyLimitBytes": obj.get("monthlyLimitBytes"), "optimizer": Optimizer.from_dict(obj["optimizer"]) if obj.get("optimizer") is not None else None, "regions": obj.get("regions"), diff --git a/services/cdn/src/stackit/cdn/models/create_distribution_payload.py b/services/cdn/src/stackit/cdn/models/create_distribution_payload.py index 933962a4..4750e761 100644 --- a/services/cdn/src/stackit/cdn/models/create_distribution_payload.py +++ b/services/cdn/src/stackit/cdn/models/create_distribution_payload.py @@ -21,6 +21,7 @@ from typing_extensions import Annotated, Self from stackit.cdn.models.optimizer import Optimizer +from stackit.cdn.models.patch_loki_log_sink import PatchLokiLogSink from stackit.cdn.models.region import Region @@ -49,6 +50,7 @@ class CreateDistributionPayload(BaseModel): description="While optional, it is greatly encouraged to provide an `intentId`. This is used to deduplicate requests. If multiple POST-Requests with the same `intentId` for a given `projectId` are received, all but the first request are dropped. ", alias="intentId", ) + log_sink: Optional[PatchLokiLogSink] = Field(default=None, alias="logSink") monthly_limit_bytes: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field( default=None, description="Sets the monthly limit of bandwidth in bytes that the pullzone is allowed to use. ", @@ -72,6 +74,7 @@ class CreateDistributionPayload(BaseModel): "blockedIPs", "defaultCacheDuration", "intentId", + "logSink", "monthlyLimitBytes", "optimizer", "originRequestHeaders", @@ -116,6 +119,9 @@ def to_dict(self) -> Dict[str, Any]: exclude=excluded_fields, exclude_none=True, ) + # override the default output from pydantic by calling `to_dict()` of log_sink + if self.log_sink: + _dict["logSink"] = self.log_sink.to_dict() # override the default output from pydantic by calling `to_dict()` of optimizer if self.optimizer: _dict["optimizer"] = self.optimizer.to_dict() @@ -136,6 +142,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "blockedIPs": obj.get("blockedIPs"), "defaultCacheDuration": obj.get("defaultCacheDuration"), "intentId": obj.get("intentId"), + "logSink": PatchLokiLogSink.from_dict(obj["logSink"]) if obj.get("logSink") is not None else None, "monthlyLimitBytes": obj.get("monthlyLimitBytes"), "optimizer": Optimizer.from_dict(obj["optimizer"]) if obj.get("optimizer") is not None else None, "originRequestHeaders": obj.get("originRequestHeaders"), diff --git a/services/cdn/src/stackit/cdn/models/get_custom_domain_custom_certificate.py b/services/cdn/src/stackit/cdn/models/get_custom_domain_custom_certificate.py new file mode 100644 index 00000000..d0c01624 --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/get_custom_domain_custom_certificate.py @@ -0,0 +1,84 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing_extensions import Annotated, Self + + +class GetCustomDomainCustomCertificate(BaseModel): + """ + Returned if a custom certificate is used. Response does not contain the certificate or key. + """ # noqa: E501 + + type: StrictStr + version: Annotated[int, Field(strict=True, ge=1)] = Field( + description="Whenever a new custom certificate is added the version is increased by 1." + ) + __properties: ClassVar[List[str]] = ["type", "version"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of GetCustomDomainCustomCertificate 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 GetCustomDomainCustomCertificate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"type": obj.get("type"), "version": obj.get("version")}) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/get_custom_domain_managed_certificate.py b/services/cdn/src/stackit/cdn/models/get_custom_domain_managed_certificate.py new file mode 100644 index 00000000..ca488ee0 --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/get_custom_domain_managed_certificate.py @@ -0,0 +1,81 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, StrictStr +from typing_extensions import Self + + +class GetCustomDomainManagedCertificate(BaseModel): + """ + This is returned when no custom certificate is used. We provision and manage a Let's Encrypt Certificate for you + """ # noqa: E501 + + type: StrictStr + __properties: ClassVar[List[str]] = ["type"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of GetCustomDomainManagedCertificate 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 GetCustomDomainManagedCertificate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"type": obj.get("type")}) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/get_custom_domain_response.py b/services/cdn/src/stackit/cdn/models/get_custom_domain_response.py index 547c1f47..afdc42d9 100644 --- a/services/cdn/src/stackit/cdn/models/get_custom_domain_response.py +++ b/services/cdn/src/stackit/cdn/models/get_custom_domain_response.py @@ -22,6 +22,9 @@ from typing_extensions import Annotated, Self from stackit.cdn.models.custom_domain import CustomDomain +from stackit.cdn.models.get_custom_domain_response_certificate import ( + GetCustomDomainResponseCertificate, +) class GetCustomDomainResponse(BaseModel): @@ -29,9 +32,10 @@ class GetCustomDomainResponse(BaseModel): GetCustomDomainResponse """ # noqa: E501 + certificate: GetCustomDomainResponseCertificate custom_domain: CustomDomain = Field(alias="customDomain") domain: Annotated[str, Field(strict=True, max_length=72)] - __properties: ClassVar[List[str]] = ["customDomain", "domain"] + __properties: ClassVar[List[str]] = ["certificate", "customDomain", "domain"] @field_validator("domain") def domain_validate_regular_expression(cls, value): @@ -77,6 +81,9 @@ def to_dict(self) -> Dict[str, Any]: exclude=excluded_fields, exclude_none=True, ) + # override the default output from pydantic by calling `to_dict()` of certificate + if self.certificate: + _dict["certificate"] = self.certificate.to_dict() # override the default output from pydantic by calling `to_dict()` of custom_domain if self.custom_domain: _dict["customDomain"] = self.custom_domain.to_dict() @@ -93,6 +100,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: _obj = cls.model_validate( { + "certificate": ( + GetCustomDomainResponseCertificate.from_dict(obj["certificate"]) + if obj.get("certificate") is not None + else None + ), "customDomain": ( CustomDomain.from_dict(obj["customDomain"]) if obj.get("customDomain") is not None else None ), diff --git a/services/cdn/src/stackit/cdn/models/get_custom_domain_response_certificate.py b/services/cdn/src/stackit/cdn/models/get_custom_domain_response_certificate.py new file mode 100644 index 00000000..e43b7631 --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/get_custom_domain_response_certificate.py @@ -0,0 +1,159 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, Dict, Optional, Set, Union + +from pydantic import ( + BaseModel, + ConfigDict, + ValidationError, + field_validator, +) +from typing_extensions import Self + +from stackit.cdn.models.get_custom_domain_custom_certificate import ( + GetCustomDomainCustomCertificate, +) +from stackit.cdn.models.get_custom_domain_managed_certificate import ( + GetCustomDomainManagedCertificate, +) + + +GETCUSTOMDOMAINRESPONSECERTIFICATE_ONE_OF_SCHEMAS = [ + "GetCustomDomainCustomCertificate", + "GetCustomDomainManagedCertificate", +] + + +class GetCustomDomainResponseCertificate(BaseModel): + """ + GetCustomDomainResponseCertificate + """ + + # data type: GetCustomDomainManagedCertificate + oneof_schema_1_validator: Optional[GetCustomDomainManagedCertificate] = None + # data type: GetCustomDomainCustomCertificate + oneof_schema_2_validator: Optional[GetCustomDomainCustomCertificate] = None + actual_instance: Optional[Union[GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate]] = None + one_of_schemas: Set[str] = {"GetCustomDomainCustomCertificate", "GetCustomDomainManagedCertificate"} + + model_config = ConfigDict( + validate_assignment=True, + protected_namespaces=(), + ) + + discriminator_value_class_map: Dict[str, str] = {} + + def __init__(self, *args, **kwargs) -> None: + if args: + if len(args) > 1: + raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") + if kwargs: + raise ValueError("If a position argument is used, keyword arguments cannot be used.") + super().__init__(actual_instance=args[0]) + else: + super().__init__(**kwargs) + + @field_validator("actual_instance") + def actual_instance_must_validate_oneof(cls, v): + instance = GetCustomDomainResponseCertificate.model_construct() + error_messages = [] + match = 0 + # validate data type: GetCustomDomainManagedCertificate + if not isinstance(v, GetCustomDomainManagedCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `GetCustomDomainManagedCertificate`") + else: + match += 1 + # validate data type: GetCustomDomainCustomCertificate + if not isinstance(v, GetCustomDomainCustomCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `GetCustomDomainCustomCertificate`") + else: + match += 1 + if match == 0: + # no match + raise ValueError( + "No match found when setting `actual_instance` in GetCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return v + + @classmethod + def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + instance = cls.model_construct() + error_messages = [] + match = 0 + + # deserialize data into GetCustomDomainManagedCertificate + try: + instance.actual_instance = GetCustomDomainManagedCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + # deserialize data into GetCustomDomainCustomCertificate + try: + instance.actual_instance = GetCustomDomainCustomCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + + if match > 1: + # more than 1 match + raise ValueError( + "Multiple matches found when deserializing the JSON string into GetCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + elif match == 0: + # no match + raise ValueError( + "No match found when deserializing the JSON string into GetCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is None: + return "null" + + if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): + return self.actual_instance.to_json() + else: + return json.dumps(self.actual_instance) + + def to_dict( + self, + ) -> Optional[Union[Dict[str, Any], GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate]]: + """Returns the dict representation of the actual instance""" + if self.actual_instance is None: + return None + + if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): + return self.actual_instance.to_dict() + else: + # primitive type + return self.actual_instance + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.model_dump()) diff --git a/services/cdn/src/stackit/cdn/models/loki_log_sink.py b/services/cdn/src/stackit/cdn/models/loki_log_sink.py new file mode 100644 index 00000000..954fddda --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/loki_log_sink.py @@ -0,0 +1,82 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing_extensions import Self + + +class LokiLogSink(BaseModel): + """ + LokiLogSink + """ # noqa: E501 + + push_url: StrictStr = Field(alias="pushUrl") + type: StrictStr + __properties: ClassVar[List[str]] = ["pushUrl", "type"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of LokiLogSink 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 LokiLogSink from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"pushUrl": obj.get("pushUrl"), "type": obj.get("type")}) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/patch_loki_log_sink.py b/services/cdn/src/stackit/cdn/models/patch_loki_log_sink.py new file mode 100644 index 00000000..26bb0aa2 --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/patch_loki_log_sink.py @@ -0,0 +1,91 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing_extensions import Self + + +class PatchLokiLogSink(BaseModel): + """ + PatchLokiLogSink + """ # noqa: E501 + + password: StrictStr + push_url: StrictStr = Field(alias="pushUrl") + type: StrictStr + username: StrictStr + __properties: ClassVar[List[str]] = ["password", "pushUrl", "type", "username"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of PatchLokiLogSink 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 PatchLokiLogSink from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate( + { + "password": obj.get("password"), + "pushUrl": obj.get("pushUrl"), + "type": obj.get("type"), + "username": obj.get("username"), + } + ) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_custom_certificate.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_custom_certificate.py new file mode 100644 index 00000000..f85caf1a --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_custom_certificate.py @@ -0,0 +1,85 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing_extensions import Self + + +class PutCustomDomainCustomCertificate(BaseModel): + """ + Returned if a custom certificate is used. Response does not contain the certificate or key. + """ # noqa: E501 + + certificate: StrictStr = Field(description="base64-encoded certificate") + key: StrictStr = Field(description="base64-encoded key") + type: StrictStr + __properties: ClassVar[List[str]] = ["certificate", "key", "type"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of PutCustomDomainCustomCertificate 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 PutCustomDomainCustomCertificate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate( + {"certificate": obj.get("certificate"), "key": obj.get("key"), "type": obj.get("type")} + ) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_managed_certificate.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_managed_certificate.py new file mode 100644 index 00000000..66573b2e --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_managed_certificate.py @@ -0,0 +1,81 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, ClassVar, Dict, List, Optional, Set + +from pydantic import BaseModel, ConfigDict, StrictStr +from typing_extensions import Self + + +class PutCustomDomainManagedCertificate(BaseModel): + """ + This is returned when no custom certificate is used. We provision and manage a Let's Encrypt Certificate for you + """ # noqa: E501 + + type: StrictStr + __properties: ClassVar[List[str]] = ["type"] + + model_config = ConfigDict( + populate_by_name=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""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of PutCustomDomainManagedCertificate 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 PutCustomDomainManagedCertificate from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"type": obj.get("type")}) + return _obj diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_payload.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_payload.py index e1b55fc2..1014da22 100644 --- a/services/cdn/src/stackit/cdn/models/put_custom_domain_payload.py +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_payload.py @@ -20,18 +20,23 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing_extensions import Self +from stackit.cdn.models.put_custom_domain_payload_certificate import ( + PutCustomDomainPayloadCertificate, +) + class PutCustomDomainPayload(BaseModel): """ PutCustomDomainPayload """ # noqa: E501 + certificate: Optional[PutCustomDomainPayloadCertificate] = None intent_id: Optional[StrictStr] = Field( default=None, description="While optional, it is greatly encouraged to provide an `intentId`. This is used to deduplicate requests. If multiple modifying Requests with the same `intentId` for a given `projectId` are received, all but the first request are dropped. ", alias="intentId", ) - __properties: ClassVar[List[str]] = ["intentId"] + __properties: ClassVar[List[str]] = ["certificate", "intentId"] model_config = ConfigDict( populate_by_name=True, @@ -70,6 +75,9 @@ def to_dict(self) -> Dict[str, Any]: exclude=excluded_fields, exclude_none=True, ) + # override the default output from pydantic by calling `to_dict()` of certificate + if self.certificate: + _dict["certificate"] = self.certificate.to_dict() return _dict @classmethod @@ -81,5 +89,14 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: if not isinstance(obj, dict): return cls.model_validate(obj) - _obj = cls.model_validate({"intentId": obj.get("intentId")}) + _obj = cls.model_validate( + { + "certificate": ( + PutCustomDomainPayloadCertificate.from_dict(obj["certificate"]) + if obj.get("certificate") is not None + else None + ), + "intentId": obj.get("intentId"), + } + ) return _obj diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_payload_certificate.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_payload_certificate.py new file mode 100644 index 00000000..804d3def --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_payload_certificate.py @@ -0,0 +1,159 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, Dict, Optional, Set, Union + +from pydantic import ( + BaseModel, + ConfigDict, + ValidationError, + field_validator, +) +from typing_extensions import Self + +from stackit.cdn.models.put_custom_domain_custom_certificate import ( + PutCustomDomainCustomCertificate, +) +from stackit.cdn.models.put_custom_domain_managed_certificate import ( + PutCustomDomainManagedCertificate, +) + + +PUTCUSTOMDOMAINPAYLOADCERTIFICATE_ONE_OF_SCHEMAS = [ + "PutCustomDomainCustomCertificate", + "PutCustomDomainManagedCertificate", +] + + +class PutCustomDomainPayloadCertificate(BaseModel): + """ + Pass a custom certificate to be served by the CDN when calling the custom domain. Will use a managed certificate when omitted + """ + + # data type: PutCustomDomainManagedCertificate + oneof_schema_1_validator: Optional[PutCustomDomainManagedCertificate] = None + # data type: PutCustomDomainCustomCertificate + oneof_schema_2_validator: Optional[PutCustomDomainCustomCertificate] = None + actual_instance: Optional[Union[PutCustomDomainCustomCertificate, PutCustomDomainManagedCertificate]] = None + one_of_schemas: Set[str] = {"PutCustomDomainCustomCertificate", "PutCustomDomainManagedCertificate"} + + model_config = ConfigDict( + validate_assignment=True, + protected_namespaces=(), + ) + + discriminator_value_class_map: Dict[str, str] = {} + + def __init__(self, *args, **kwargs) -> None: + if args: + if len(args) > 1: + raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") + if kwargs: + raise ValueError("If a position argument is used, keyword arguments cannot be used.") + super().__init__(actual_instance=args[0]) + else: + super().__init__(**kwargs) + + @field_validator("actual_instance") + def actual_instance_must_validate_oneof(cls, v): + instance = PutCustomDomainPayloadCertificate.model_construct() + error_messages = [] + match = 0 + # validate data type: PutCustomDomainManagedCertificate + if not isinstance(v, PutCustomDomainManagedCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `PutCustomDomainManagedCertificate`") + else: + match += 1 + # validate data type: PutCustomDomainCustomCertificate + if not isinstance(v, PutCustomDomainCustomCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `PutCustomDomainCustomCertificate`") + else: + match += 1 + if match == 0: + # no match + raise ValueError( + "No match found when setting `actual_instance` in PutCustomDomainPayloadCertificate with oneOf schemas: PutCustomDomainCustomCertificate, PutCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return v + + @classmethod + def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + instance = cls.model_construct() + error_messages = [] + match = 0 + + # deserialize data into PutCustomDomainManagedCertificate + try: + instance.actual_instance = PutCustomDomainManagedCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + # deserialize data into PutCustomDomainCustomCertificate + try: + instance.actual_instance = PutCustomDomainCustomCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + + if match > 1: + # more than 1 match + raise ValueError( + "Multiple matches found when deserializing the JSON string into PutCustomDomainPayloadCertificate with oneOf schemas: PutCustomDomainCustomCertificate, PutCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + elif match == 0: + # no match + raise ValueError( + "No match found when deserializing the JSON string into PutCustomDomainPayloadCertificate with oneOf schemas: PutCustomDomainCustomCertificate, PutCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is None: + return "null" + + if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): + return self.actual_instance.to_json() + else: + return json.dumps(self.actual_instance) + + def to_dict( + self, + ) -> Optional[Union[Dict[str, Any], PutCustomDomainCustomCertificate, PutCustomDomainManagedCertificate]]: + """Returns the dict representation of the actual instance""" + if self.actual_instance is None: + return None + + if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): + return self.actual_instance.to_dict() + else: + # primitive type + return self.actual_instance + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.model_dump()) diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_response.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_response.py index 0384c7be..ca5f69e2 100644 --- a/services/cdn/src/stackit/cdn/models/put_custom_domain_response.py +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_response.py @@ -22,6 +22,9 @@ from typing_extensions import Annotated, Self from stackit.cdn.models.custom_domain import CustomDomain +from stackit.cdn.models.put_custom_domain_response_certificate import ( + PutCustomDomainResponseCertificate, +) class PutCustomDomainResponse(BaseModel): @@ -29,9 +32,10 @@ class PutCustomDomainResponse(BaseModel): PutCustomDomainResponse """ # noqa: E501 + certificate: Optional[PutCustomDomainResponseCertificate] = None custom_domain: CustomDomain = Field(alias="customDomain") domain: Annotated[str, Field(strict=True, max_length=72)] - __properties: ClassVar[List[str]] = ["customDomain", "domain"] + __properties: ClassVar[List[str]] = ["certificate", "customDomain", "domain"] @field_validator("domain") def domain_validate_regular_expression(cls, value): @@ -77,6 +81,9 @@ def to_dict(self) -> Dict[str, Any]: exclude=excluded_fields, exclude_none=True, ) + # override the default output from pydantic by calling `to_dict()` of certificate + if self.certificate: + _dict["certificate"] = self.certificate.to_dict() # override the default output from pydantic by calling `to_dict()` of custom_domain if self.custom_domain: _dict["customDomain"] = self.custom_domain.to_dict() @@ -93,6 +100,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: _obj = cls.model_validate( { + "certificate": ( + PutCustomDomainResponseCertificate.from_dict(obj["certificate"]) + if obj.get("certificate") is not None + else None + ), "customDomain": ( CustomDomain.from_dict(obj["customDomain"]) if obj.get("customDomain") is not None else None ), diff --git a/services/cdn/src/stackit/cdn/models/put_custom_domain_response_certificate.py b/services/cdn/src/stackit/cdn/models/put_custom_domain_response_certificate.py new file mode 100644 index 00000000..a23fc0e1 --- /dev/null +++ b/services/cdn/src/stackit/cdn/models/put_custom_domain_response_certificate.py @@ -0,0 +1,159 @@ +# coding: utf-8 + +""" + CDN API + + API used to create and manage your CDN distributions. + + The version of the OpenAPI document: 1beta.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 +from typing import Any, Dict, Optional, Set, Union + +from pydantic import ( + BaseModel, + ConfigDict, + ValidationError, + field_validator, +) +from typing_extensions import Self + +from stackit.cdn.models.get_custom_domain_custom_certificate import ( + GetCustomDomainCustomCertificate, +) +from stackit.cdn.models.get_custom_domain_managed_certificate import ( + GetCustomDomainManagedCertificate, +) + + +PUTCUSTOMDOMAINRESPONSECERTIFICATE_ONE_OF_SCHEMAS = [ + "GetCustomDomainCustomCertificate", + "GetCustomDomainManagedCertificate", +] + + +class PutCustomDomainResponseCertificate(BaseModel): + """ + Pass a custom certificate to be served by the CDN when calling the custom domain. Will use a managed certificate when omitted + """ + + # data type: GetCustomDomainManagedCertificate + oneof_schema_1_validator: Optional[GetCustomDomainManagedCertificate] = None + # data type: GetCustomDomainCustomCertificate + oneof_schema_2_validator: Optional[GetCustomDomainCustomCertificate] = None + actual_instance: Optional[Union[GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate]] = None + one_of_schemas: Set[str] = {"GetCustomDomainCustomCertificate", "GetCustomDomainManagedCertificate"} + + model_config = ConfigDict( + validate_assignment=True, + protected_namespaces=(), + ) + + discriminator_value_class_map: Dict[str, str] = {} + + def __init__(self, *args, **kwargs) -> None: + if args: + if len(args) > 1: + raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") + if kwargs: + raise ValueError("If a position argument is used, keyword arguments cannot be used.") + super().__init__(actual_instance=args[0]) + else: + super().__init__(**kwargs) + + @field_validator("actual_instance") + def actual_instance_must_validate_oneof(cls, v): + instance = PutCustomDomainResponseCertificate.model_construct() + error_messages = [] + match = 0 + # validate data type: GetCustomDomainManagedCertificate + if not isinstance(v, GetCustomDomainManagedCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `GetCustomDomainManagedCertificate`") + else: + match += 1 + # validate data type: GetCustomDomainCustomCertificate + if not isinstance(v, GetCustomDomainCustomCertificate): + error_messages.append(f"Error! Input type `{type(v)}` is not `GetCustomDomainCustomCertificate`") + else: + match += 1 + if match == 0: + # no match + raise ValueError( + "No match found when setting `actual_instance` in PutCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return v + + @classmethod + def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + instance = cls.model_construct() + error_messages = [] + match = 0 + + # deserialize data into GetCustomDomainManagedCertificate + try: + instance.actual_instance = GetCustomDomainManagedCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + # deserialize data into GetCustomDomainCustomCertificate + try: + instance.actual_instance = GetCustomDomainCustomCertificate.from_json(json_str) + match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + + if match > 1: + # more than 1 match + raise ValueError( + "Multiple matches found when deserializing the JSON string into PutCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + elif match == 0: + # no match + raise ValueError( + "No match found when deserializing the JSON string into PutCustomDomainResponseCertificate with oneOf schemas: GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate. Details: " + + ", ".join(error_messages) + ) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is None: + return "null" + + if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): + return self.actual_instance.to_json() + else: + return json.dumps(self.actual_instance) + + def to_dict( + self, + ) -> Optional[Union[Dict[str, Any], GetCustomDomainCustomCertificate, GetCustomDomainManagedCertificate]]: + """Returns the dict representation of the actual instance""" + if self.actual_instance is None: + return None + + if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): + return self.actual_instance.to_dict() + else: + # primitive type + return self.actual_instance + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.model_dump())