|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +STACKIT CDN API |
| 5 | +
|
| 6 | +API used to create and manage your CDN distributions. |
| 7 | +
|
| 8 | +The version of the OpenAPI document: 1.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 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 19 | + |
| 20 | +from pydantic import BaseModel, ConfigDict, Field, StrictBool |
| 21 | +from pydantic_core import to_jsonable_python |
| 22 | +from typing_extensions import Annotated, Self |
| 23 | + |
| 24 | + |
| 25 | +class CacheConfigCreate(BaseModel): |
| 26 | + """ |
| 27 | + Groups the cache options that influence how the CDN builds its cache key on distribution creation. **Cache cardinality warning:** enabling query-string vary produces one cache entry per unique query-string combination (**unbounded** when `queryStringVaryParameters` is empty). Each entry in `cacheKeyHeaders` multiplies the number of cache variants by the number of distinct values observed for that header. Use these settings sparingly. `queryStringVaryParameters` is stored independently of `queryStringVaryEnabled` so that this feature can be toggled on and off without losing the configured allowlist. Only `queryStringVaryEnabled` gates whether the parameter allowlist actually varies the cache. **Optimizer interaction:** when the Optimizer is enabled, the CDN automatically enables query-string vary for image responses regardless of this setting. |
| 28 | + """ # noqa: E501 |
| 29 | + |
| 30 | + cache_key_headers: Optional[List[Annotated[str, Field(strict=True)]]] = Field( |
| 31 | + default=None, |
| 32 | + description="HTTP request header names whose values participate in the cache key. Each entry multiplies the number of cache variants by the number of distinct values observed for that header. ", |
| 33 | + alias="cacheKeyHeaders", |
| 34 | + ) |
| 35 | + query_string_vary_enabled: Optional[StrictBool] = Field( |
| 36 | + default=False, |
| 37 | + description="When true, the CDN varies its cache by the request query string. If `queryStringVaryParameters` is empty, every unique query-string combination produces its own cache entry; if non-empty, only the listed parameters influence the cache key. ", |
| 38 | + alias="queryStringVaryEnabled", |
| 39 | + ) |
| 40 | + query_string_vary_parameters: Optional[List[Annotated[str, Field(strict=True)]]] = Field( |
| 41 | + default=None, |
| 42 | + description="Allowlist of query-string parameter names that participate in the cache key when `queryStringVaryEnabled` is true. Ignored while `queryStringVaryEnabled` is false, but still stored so it can be re-activated without losing the list. ", |
| 43 | + alias="queryStringVaryParameters", |
| 44 | + ) |
| 45 | + __properties: ClassVar[List[str]] = ["cacheKeyHeaders", "queryStringVaryEnabled", "queryStringVaryParameters"] |
| 46 | + |
| 47 | + model_config = ConfigDict( |
| 48 | + validate_by_name=True, |
| 49 | + validate_by_alias=True, |
| 50 | + validate_assignment=True, |
| 51 | + protected_namespaces=(), |
| 52 | + ) |
| 53 | + |
| 54 | + def to_str(self) -> str: |
| 55 | + """Returns the string representation of the model using alias""" |
| 56 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 57 | + |
| 58 | + def to_json(self) -> str: |
| 59 | + """Returns the JSON representation of the model using alias""" |
| 60 | + return json.dumps(to_jsonable_python(self.to_dict())) |
| 61 | + |
| 62 | + @classmethod |
| 63 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 64 | + """Create an instance of CacheConfigCreate from a JSON string""" |
| 65 | + return cls.from_dict(json.loads(json_str)) |
| 66 | + |
| 67 | + def to_dict(self) -> Dict[str, Any]: |
| 68 | + """Return the dictionary representation of the model using alias. |
| 69 | +
|
| 70 | + This has the following differences from calling pydantic's |
| 71 | + `self.model_dump(by_alias=True)`: |
| 72 | +
|
| 73 | + * `None` is only added to the output dict for nullable fields that |
| 74 | + were set at model initialization. Other fields with value `None` |
| 75 | + are ignored. |
| 76 | + """ |
| 77 | + excluded_fields: Set[str] = set([]) |
| 78 | + |
| 79 | + _dict = self.model_dump( |
| 80 | + by_alias=True, |
| 81 | + exclude=excluded_fields, |
| 82 | + exclude_none=True, |
| 83 | + ) |
| 84 | + return _dict |
| 85 | + |
| 86 | + @classmethod |
| 87 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 88 | + """Create an instance of CacheConfigCreate from a dict""" |
| 89 | + if obj is None: |
| 90 | + return None |
| 91 | + |
| 92 | + if not isinstance(obj, dict): |
| 93 | + return cls.model_validate(obj) |
| 94 | + |
| 95 | + _obj = cls.model_validate( |
| 96 | + { |
| 97 | + "cacheKeyHeaders": obj.get("cacheKeyHeaders"), |
| 98 | + "queryStringVaryEnabled": ( |
| 99 | + obj.get("queryStringVaryEnabled") if obj.get("queryStringVaryEnabled") is not None else False |
| 100 | + ), |
| 101 | + "queryStringVaryParameters": obj.get("queryStringVaryParameters"), |
| 102 | + } |
| 103 | + ) |
| 104 | + return _obj |
0 commit comments