diff --git a/services/alb/src/stackit/alb/__init__.py b/services/alb/src/stackit/alb/__init__.py index 38e7ff75..71e37e80 100644 --- a/services/alb/src/stackit/alb/__init__.py +++ b/services/alb/src/stackit/alb/__init__.py @@ -62,6 +62,7 @@ LoadbalancerOptionObservability, ) from stackit.alb.models.network import Network +from stackit.alb.models.path import Path from stackit.alb.models.plan_details import PlanDetails from stackit.alb.models.protocol_options_http import ProtocolOptionsHTTP from stackit.alb.models.protocol_options_https import ProtocolOptionsHTTPS diff --git a/services/alb/src/stackit/alb/models/__init__.py b/services/alb/src/stackit/alb/models/__init__.py index e4dba07e..55bedd8d 100644 --- a/services/alb/src/stackit/alb/models/__init__.py +++ b/services/alb/src/stackit/alb/models/__init__.py @@ -43,6 +43,7 @@ LoadbalancerOptionObservability, ) from stackit.alb.models.network import Network +from stackit.alb.models.path import Path from stackit.alb.models.plan_details import PlanDetails from stackit.alb.models.protocol_options_http import ProtocolOptionsHTTP from stackit.alb.models.protocol_options_https import ProtocolOptionsHTTPS diff --git a/services/alb/src/stackit/alb/models/path.py b/services/alb/src/stackit/alb/models/path.py new file mode 100644 index 00000000..c3f28f86 --- /dev/null +++ b/services/alb/src/stackit/alb/models/path.py @@ -0,0 +1,88 @@ +# coding: utf-8 + +""" + Application Load Balancer API + + This API offers an interface to provision and manage load balancing servers in your STACKIT project. It also has the possibility of pooling target servers for load balancing purposes. For each application load balancer provided, two VMs are deployed in your OpenStack project subject to a fee. + + The version of the OpenAPI document: 2beta2.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 docstring might be too long + +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 Path(BaseModel): + """ + Path + """ + + exact: Optional[StrictStr] = Field( + default=None, + description="Exact path match. Only a request path exactly equal to the value will match, e.g. '/foo' matches only '/foo', not '/foo/bar' or '/foobar'.", + ) + prefix: Optional[StrictStr] = Field( + default=None, + description="Prefix path match. Only matches on full segment boundaries, e.g. '/foo' matches '/foo' and '/foo/bar' but NOT '/foobar'.", + ) + __properties: ClassVar[List[str]] = ["exact", "prefix"] + + 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 Path 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 Path from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"exact": obj.get("exact"), "prefix": obj.get("prefix")}) + return _obj diff --git a/services/alb/src/stackit/alb/models/rule.py b/services/alb/src/stackit/alb/models/rule.py index ca7dd2de..9b4cc2e4 100644 --- a/services/alb/src/stackit/alb/models/rule.py +++ b/services/alb/src/stackit/alb/models/rule.py @@ -22,6 +22,7 @@ from stackit.alb.models.cookie_persistence import CookiePersistence from stackit.alb.models.http_header import HttpHeader +from stackit.alb.models.path import Path from stackit.alb.models.query_parameter import QueryParameter @@ -32,9 +33,10 @@ class Rule(BaseModel): cookie_persistence: Optional[CookiePersistence] = Field(default=None, alias="cookiePersistence") headers: Optional[List[HttpHeader]] = Field(default=None, description="Headers for the rule.") + path: Optional[Path] = None path_prefix: Optional[StrictStr] = Field( default=None, - description="Path prefix for the rule. If empty or '/', it matches the root path.", + description="Legacy path prefix match. Optional. If not set, defaults to root path '/'. Cannot be set if 'path' is used. Prefer using 'path.prefix' instead. Only matches on full segment boundaries, e.g. '/foo' matches '/foo' and '/foo/bar' but NOT '/foobar'.", alias="pathPrefix", ) query_parameters: Optional[List[QueryParameter]] = Field( @@ -51,6 +53,7 @@ class Rule(BaseModel): __properties: ClassVar[List[str]] = [ "cookiePersistence", "headers", + "path", "pathPrefix", "queryParameters", "targetPool", @@ -104,6 +107,9 @@ def to_dict(self) -> Dict[str, Any]: if _item: _items.append(_item.to_dict()) _dict["headers"] = _items + # override the default output from pydantic by calling `to_dict()` of path + if self.path: + _dict["path"] = self.path.to_dict() # override the default output from pydantic by calling `to_dict()` of each item in query_parameters (list) _items = [] if self.query_parameters: @@ -134,6 +140,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: if obj.get("headers") is not None else None ), + "path": Path.from_dict(obj["path"]) if obj.get("path") is not None else None, "pathPrefix": obj.get("pathPrefix"), "queryParameters": ( [QueryParameter.from_dict(_item) for _item in obj["queryParameters"]]