From 7783a9ab9aff1bcd36a92bb10654c2a0baab458b Mon Sep 17 00:00:00 2001 From: SDK Generator Bot Date: Fri, 13 Mar 2026 16:14:15 +0000 Subject: [PATCH] Generate postgresflex --- services/postgresflex/oas_commit | 1 + .../src/stackit/postgresflex/api_client.py | 31 +++++++++++++------ .../src/stackit/postgresflex/exceptions.py | 2 +- .../stackit/postgresflex/models/__init__.py | 1 - .../api_extension_config_load_response.py | 6 ++-- .../api_extension_configure_response.py | 6 ++-- .../models/api_installed_list_response.py | 6 ++-- .../extensions_extension_list_response.py | 6 ++-- .../models/extensions_new_config.py | 6 ++-- .../postgresflex/models/instance_host.py | 6 ++-- .../models/instance_host_metric.py | 6 ++-- .../instance_list_databases_response.py | 6 ++-- .../models/instance_metrics_response.py | 6 ++-- .../models/list_backups_response.py | 6 ++-- .../models/list_flavors_response.py | 6 ++-- .../models/list_instances_response.py | 6 ++-- .../models/list_users_response.py | 6 ++-- .../postgres_database_parameter_response.py | 6 ++-- .../src/stackit/postgresflex/rest.py | 22 +++++++++++-- 19 files changed, 85 insertions(+), 56 deletions(-) create mode 100644 services/postgresflex/oas_commit diff --git a/services/postgresflex/oas_commit b/services/postgresflex/oas_commit new file mode 100644 index 000000000..e3713dde3 --- /dev/null +++ b/services/postgresflex/oas_commit @@ -0,0 +1 @@ +0e64886dd0847341800d7191ed193b75413be998 diff --git a/services/postgresflex/src/stackit/postgresflex/api_client.py b/services/postgresflex/src/stackit/postgresflex/api_client.py index 74ec9ea99..7d529c80d 100644 --- a/services/postgresflex/src/stackit/postgresflex/api_client.py +++ b/services/postgresflex/src/stackit/postgresflex/api_client.py @@ -13,11 +13,13 @@ """ # noqa: E501 import datetime +import decimal import json import mimetypes import os import re import tempfile +import uuid from enum import Enum from typing import Dict, List, Optional, Tuple, Union from urllib.parse import quote @@ -64,8 +66,10 @@ class ApiClient: "bool": bool, "date": datetime.date, "datetime": datetime.datetime, + "decimal": decimal.Decimal, "object": object, } + _pool = None def __init__(self, configuration, header_name=None, header_value=None, cookie=None) -> None: self.config: Configuration = configuration @@ -268,7 +272,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.getheader("content-type") + content_type = response_data.headers.get("content-type") if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -285,7 +289,7 @@ def response_deserialize( return ApiResponse( status_code=response_data.status, data=return_data, - headers=response_data.getheaders(), + headers=response_data.headers, raw_data=response_data.data, ) @@ -297,6 +301,7 @@ def sanitize_for_serialization(self, obj): If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. + If obj is decimal.Decimal return string representation. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is OpenAPI model, return the properties dict. @@ -312,12 +317,16 @@ def sanitize_for_serialization(self, obj): return obj.get_secret_value() elif isinstance(obj, self.PRIMITIVE_TYPES): return obj + elif isinstance(obj, uuid.UUID): + return str(obj) elif isinstance(obj, list): return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj] elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) elif isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() + elif isinstance(obj, decimal.Decimal): + return str(obj) elif isinstance(obj, dict): obj_dict = obj @@ -327,7 +336,7 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, "to_dict") and callable(obj.to_dict): + if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009 obj_dict = obj.to_dict() else: obj_dict = obj.__dict__ @@ -355,7 +364,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti data = json.loads(response_text) except ValueError: data = response_text - elif re.match(r"^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE): + elif re.match(r"^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE): if response_text == "": data = "" else: @@ -401,12 +410,14 @@ def __deserialize(self, data, klass): if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + elif klass is object: return self.__deserialize_object(data) - elif klass == datetime.date: + elif klass is datetime.date: return self.__deserialize_date(data) - elif klass == datetime.datetime: + elif klass is datetime.datetime: return self.__deserialize_datetime(data) + elif klass is decimal.Decimal: + return decimal.Decimal(data) elif issubclass(klass, Enum): return self.__deserialize_enum(data, klass) else: @@ -554,12 +565,14 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.getheader("Content-Disposition") + content_disposition = response.headers.get("Content-Disposition") if content_disposition: m = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition) if m is None: raise ValueError("Unexpected 'content-disposition' header value") - filename = m.group(1) + filename = os.path.basename(m.group(1)) # Strip any directory traversal + if filename in ("", ".", ".."): # fall back to tmp filename + filename = os.path.basename(path) path = os.path.join(os.path.dirname(path), filename) with open(path, "wb") as f: diff --git a/services/postgresflex/src/stackit/postgresflex/exceptions.py b/services/postgresflex/src/stackit/postgresflex/exceptions.py index 0bcb662e4..3c35356ac 100644 --- a/services/postgresflex/src/stackit/postgresflex/exceptions.py +++ b/services/postgresflex/src/stackit/postgresflex/exceptions.py @@ -130,7 +130,7 @@ def __init__( self.body = http_resp.data.decode("utf-8") except Exception: # noqa: S110 pass - self.headers = http_resp.getheaders() + self.headers = http_resp.headers @classmethod def from_response( diff --git a/services/postgresflex/src/stackit/postgresflex/models/__init__.py b/services/postgresflex/src/stackit/postgresflex/models/__init__.py index b7612075b..811954e0a 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/__init__.py +++ b/services/postgresflex/src/stackit/postgresflex/models/__init__.py @@ -13,7 +13,6 @@ Do not edit the class manually. """ # noqa: E501 - # import models into model package from stackit.postgresflex.models.acl import ACL from stackit.postgresflex.models.api_configuration import ApiConfiguration diff --git a/services/postgresflex/src/stackit/postgresflex/models/api_extension_config_load_response.py b/services/postgresflex/src/stackit/postgresflex/models/api_extension_config_load_response.py index cc4bfcf84..e80d6ce40 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/api_extension_config_load_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/api_extension_config_load_response.py @@ -74,9 +74,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in configuration (list) _items = [] if self.configuration: - for _item in self.configuration: - if _item: - _items.append(_item.to_dict()) + for _item_configuration in self.configuration: + if _item_configuration: + _items.append(_item_configuration.to_dict()) _dict["configuration"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/api_extension_configure_response.py b/services/postgresflex/src/stackit/postgresflex/models/api_extension_configure_response.py index 7debe822a..3f408fca9 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/api_extension_configure_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/api_extension_configure_response.py @@ -74,9 +74,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in configuration (list) _items = [] if self.configuration: - for _item in self.configuration: - if _item: - _items.append(_item.to_dict()) + for _item_configuration in self.configuration: + if _item_configuration: + _items.append(_item_configuration.to_dict()) _dict["configuration"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/api_installed_list_response.py b/services/postgresflex/src/stackit/postgresflex/models/api_installed_list_response.py index b5a787ba5..87c9694be 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/api_installed_list_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/api_installed_list_response.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in installed (list) _items = [] if self.installed: - for _item in self.installed: - if _item: - _items.append(_item.to_dict()) + for _item_installed in self.installed: + if _item_installed: + _items.append(_item_installed.to_dict()) _dict["installed"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/extensions_extension_list_response.py b/services/postgresflex/src/stackit/postgresflex/models/extensions_extension_list_response.py index 1898f0b56..2ef9ab5b6 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/extensions_extension_list_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/extensions_extension_list_response.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in list (list) _items = [] if self.list: - for _item in self.list: - if _item: - _items.append(_item.to_dict()) + for _item_list in self.list: + if _item_list: + _items.append(_item_list.to_dict()) _dict["list"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/extensions_new_config.py b/services/postgresflex/src/stackit/postgresflex/models/extensions_new_config.py index 579b181f2..269db363f 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/extensions_new_config.py +++ b/services/postgresflex/src/stackit/postgresflex/models/extensions_new_config.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in configuration (list) _items = [] if self.configuration: - for _item in self.configuration: - if _item: - _items.append(_item.to_dict()) + for _item_configuration in self.configuration: + if _item_configuration: + _items.append(_item_configuration.to_dict()) _dict["configuration"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/instance_host.py b/services/postgresflex/src/stackit/postgresflex/models/instance_host.py index d2f018058..a55a421ad 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/instance_host.py +++ b/services/postgresflex/src/stackit/postgresflex/models/instance_host.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in host_metrics (list) _items = [] if self.host_metrics: - for _item in self.host_metrics: - if _item: - _items.append(_item.to_dict()) + for _item_host_metrics in self.host_metrics: + if _item_host_metrics: + _items.append(_item_host_metrics.to_dict()) _dict["hostMetrics"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/instance_host_metric.py b/services/postgresflex/src/stackit/postgresflex/models/instance_host_metric.py index 09cde5f70..89f74e085 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/instance_host_metric.py +++ b/services/postgresflex/src/stackit/postgresflex/models/instance_host_metric.py @@ -74,9 +74,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in datapoints (list) _items = [] if self.datapoints: - for _item in self.datapoints: - if _item: - _items.append(_item.to_dict()) + for _item_datapoints in self.datapoints: + if _item_datapoints: + _items.append(_item_datapoints.to_dict()) _dict["datapoints"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/instance_list_databases_response.py b/services/postgresflex/src/stackit/postgresflex/models/instance_list_databases_response.py index 9b08c0ea3..5c23325ee 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/instance_list_databases_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/instance_list_databases_response.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in databases (list) _items = [] if self.databases: - for _item in self.databases: - if _item: - _items.append(_item.to_dict()) + for _item_databases in self.databases: + if _item_databases: + _items.append(_item_databases.to_dict()) _dict["databases"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/instance_metrics_response.py b/services/postgresflex/src/stackit/postgresflex/models/instance_metrics_response.py index e0a9463a2..9c4ebd18b 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/instance_metrics_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/instance_metrics_response.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in hosts (list) _items = [] if self.hosts: - for _item in self.hosts: - if _item: - _items.append(_item.to_dict()) + for _item_hosts in self.hosts: + if _item_hosts: + _items.append(_item_hosts.to_dict()) _dict["hosts"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/list_backups_response.py b/services/postgresflex/src/stackit/postgresflex/models/list_backups_response.py index d92771fad..59e179cdd 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/list_backups_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/list_backups_response.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in items (list) _items = [] if self.items: - for _item in self.items: - if _item: - _items.append(_item.to_dict()) + for _item_items in self.items: + if _item_items: + _items.append(_item_items.to_dict()) _dict["items"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/list_flavors_response.py b/services/postgresflex/src/stackit/postgresflex/models/list_flavors_response.py index d72dae979..fd725fc60 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/list_flavors_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/list_flavors_response.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in flavors (list) _items = [] if self.flavors: - for _item in self.flavors: - if _item: - _items.append(_item.to_dict()) + for _item_flavors in self.flavors: + if _item_flavors: + _items.append(_item_flavors.to_dict()) _dict["flavors"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/list_instances_response.py b/services/postgresflex/src/stackit/postgresflex/models/list_instances_response.py index 7a49d9b05..259e4233e 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/list_instances_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/list_instances_response.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in items (list) _items = [] if self.items: - for _item in self.items: - if _item: - _items.append(_item.to_dict()) + for _item_items in self.items: + if _item_items: + _items.append(_item_items.to_dict()) _dict["items"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/list_users_response.py b/services/postgresflex/src/stackit/postgresflex/models/list_users_response.py index 15f360032..32bf7bf87 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/list_users_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/list_users_response.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in items (list) _items = [] if self.items: - for _item in self.items: - if _item: - _items.append(_item.to_dict()) + for _item_items in self.items: + if _item_items: + _items.append(_item_items.to_dict()) _dict["items"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/models/postgres_database_parameter_response.py b/services/postgresflex/src/stackit/postgresflex/models/postgres_database_parameter_response.py index bd49db7db..6838a60ee 100644 --- a/services/postgresflex/src/stackit/postgresflex/models/postgres_database_parameter_response.py +++ b/services/postgresflex/src/stackit/postgresflex/models/postgres_database_parameter_response.py @@ -74,9 +74,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in parameter (list) _items = [] if self.parameter: - for _item in self.parameter: - if _item: - _items.append(_item.to_dict()) + for _item_parameter in self.parameter: + if _item_parameter: + _items.append(_item_parameter.to_dict()) _dict["parameter"] = _items return _dict diff --git a/services/postgresflex/src/stackit/postgresflex/rest.py b/services/postgresflex/src/stackit/postgresflex/rest.py index 141c22efe..4f1f4a4ad 100644 --- a/services/postgresflex/src/stackit/postgresflex/rest.py +++ b/services/postgresflex/src/stackit/postgresflex/rest.py @@ -39,12 +39,17 @@ def read(self): self.data = self.response.content return self.data + @property + def headers(self): + """Returns a dictionary of response headers.""" + return self.response.headers + def getheaders(self): - """Returns a dictionary of the response headers.""" + """Returns a dictionary of the response headers; use ``headers`` instead.""" return self.response.headers def getheader(self, name, default=None): - """Returns a given response header.""" + """Returns a given response header; use ``headers.get()`` instead.""" return self.response.headers.get(name, default) @@ -94,6 +99,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, data=request_body, headers=headers, + timeout=_request_timeout, ) elif content_type == "application/x-www-form-urlencoded": r = self.session.request( @@ -101,6 +107,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, params=post_params, headers=headers, + timeout=_request_timeout, ) elif content_type == "multipart/form-data": # must del headers['Content-Type'], or the correct @@ -114,6 +121,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, files=post_params, headers=headers, + timeout=_request_timeout, ) # Pass a `string` parameter directly in the body to support # other content types than JSON when `body` argument is @@ -124,10 +132,17 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, data=body, headers=headers, + timeout=_request_timeout, ) elif headers["Content-Type"].startswith("text/") and isinstance(body, bool): request_body = "true" if body else "false" - r = self.session.request(method, url, data=request_body, headers=headers) + r = self.session.request( + method, + url, + data=request_body, + headers=headers, + timeout=_request_timeout, + ) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided @@ -141,6 +156,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, params={}, headers=headers, + timeout=_request_timeout, ) except requests.exceptions.SSLError as e: msg = "\n".join([type(e).__name__, str(e)])