|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + CDN API |
| 5 | +
|
| 6 | + API used to create and manage your CDN distributions. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1beta.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 |
| 21 | +from typing_extensions import Self |
| 22 | + |
| 23 | +from stackit.cdn.models.waf_status_rule_block import WAFStatusRuleBlock |
| 24 | + |
| 25 | + |
| 26 | +class DistributionWaf(BaseModel): |
| 27 | + """ |
| 28 | + For this property to be present two pre-conditions must be met: - the WAF was enabled at least once - the query parameter ?withWafStatus is truthy This property contains the waf Status. At this point in time, this contains all resolved rules. Rules are split into 3 groups: - enabledRules - logOnlyRules - disabledRules **Do note that the global waf mode (Disabled, LogOnly, Enabled) is *NOT* reflected in this list!** |
| 29 | + """ # noqa: E501 |
| 30 | + |
| 31 | + disabled_rules: List[WAFStatusRuleBlock] = Field(alias="disabledRules") |
| 32 | + enabled_rules: List[WAFStatusRuleBlock] = Field(alias="enabledRules") |
| 33 | + log_only_rules: List[WAFStatusRuleBlock] = Field(alias="logOnlyRules") |
| 34 | + __properties: ClassVar[List[str]] = ["disabledRules", "enabledRules", "logOnlyRules"] |
| 35 | + |
| 36 | + model_config = ConfigDict( |
| 37 | + populate_by_name=True, |
| 38 | + validate_assignment=True, |
| 39 | + protected_namespaces=(), |
| 40 | + ) |
| 41 | + |
| 42 | + def to_str(self) -> str: |
| 43 | + """Returns the string representation of the model using alias""" |
| 44 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 45 | + |
| 46 | + def to_json(self) -> str: |
| 47 | + """Returns the JSON representation of the model using alias""" |
| 48 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 49 | + return json.dumps(self.to_dict()) |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 53 | + """Create an instance of DistributionWaf from a JSON string""" |
| 54 | + return cls.from_dict(json.loads(json_str)) |
| 55 | + |
| 56 | + def to_dict(self) -> Dict[str, Any]: |
| 57 | + """Return the dictionary representation of the model using alias. |
| 58 | +
|
| 59 | + This has the following differences from calling pydantic's |
| 60 | + `self.model_dump(by_alias=True)`: |
| 61 | +
|
| 62 | + * `None` is only added to the output dict for nullable fields that |
| 63 | + were set at model initialization. Other fields with value `None` |
| 64 | + are ignored. |
| 65 | + """ |
| 66 | + excluded_fields: Set[str] = set([]) |
| 67 | + |
| 68 | + _dict = self.model_dump( |
| 69 | + by_alias=True, |
| 70 | + exclude=excluded_fields, |
| 71 | + exclude_none=True, |
| 72 | + ) |
| 73 | + # override the default output from pydantic by calling `to_dict()` of each item in disabled_rules (list) |
| 74 | + _items = [] |
| 75 | + if self.disabled_rules: |
| 76 | + for _item in self.disabled_rules: |
| 77 | + if _item: |
| 78 | + _items.append(_item.to_dict()) |
| 79 | + _dict["disabledRules"] = _items |
| 80 | + # override the default output from pydantic by calling `to_dict()` of each item in enabled_rules (list) |
| 81 | + _items = [] |
| 82 | + if self.enabled_rules: |
| 83 | + for _item in self.enabled_rules: |
| 84 | + if _item: |
| 85 | + _items.append(_item.to_dict()) |
| 86 | + _dict["enabledRules"] = _items |
| 87 | + # override the default output from pydantic by calling `to_dict()` of each item in log_only_rules (list) |
| 88 | + _items = [] |
| 89 | + if self.log_only_rules: |
| 90 | + for _item in self.log_only_rules: |
| 91 | + if _item: |
| 92 | + _items.append(_item.to_dict()) |
| 93 | + _dict["logOnlyRules"] = _items |
| 94 | + return _dict |
| 95 | + |
| 96 | + @classmethod |
| 97 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 98 | + """Create an instance of DistributionWaf from a dict""" |
| 99 | + if obj is None: |
| 100 | + return None |
| 101 | + |
| 102 | + if not isinstance(obj, dict): |
| 103 | + return cls.model_validate(obj) |
| 104 | + |
| 105 | + _obj = cls.model_validate( |
| 106 | + { |
| 107 | + "disabledRules": ( |
| 108 | + [WAFStatusRuleBlock.from_dict(_item) for _item in obj["disabledRules"]] |
| 109 | + if obj.get("disabledRules") is not None |
| 110 | + else None |
| 111 | + ), |
| 112 | + "enabledRules": ( |
| 113 | + [WAFStatusRuleBlock.from_dict(_item) for _item in obj["enabledRules"]] |
| 114 | + if obj.get("enabledRules") is not None |
| 115 | + else None |
| 116 | + ), |
| 117 | + "logOnlyRules": ( |
| 118 | + [WAFStatusRuleBlock.from_dict(_item) for _item in obj["logOnlyRules"]] |
| 119 | + if obj.get("logOnlyRules") is not None |
| 120 | + else None |
| 121 | + ), |
| 122 | + } |
| 123 | + ) |
| 124 | + return _obj |
0 commit comments