diff --git a/docs/mozart-api.yaml b/docs/mozart-api.yaml index 0fde226..7fb8c2b 100644 --- a/docs/mozart-api.yaml +++ b/docs/mozart-api.yaml @@ -3866,7 +3866,7 @@ info: - [Beosound Level](https://www.bang-olufsen.com/en/dk/speakers/beosound-level)\n\ - [Beosound Theatre](https://www.bang-olufsen.com/en/dk/soundbars/beosound-theatre)\n\ \n\nThis API documentation has been generated for version 3.4.1.8 of the Mozart\ - \ platform and API generation version 3.4.1.8.7.\n\n## Python API\n\nThe Python\ + \ platform and API generation version 3.4.1.8.8.\n\n## Python API\n\nThe Python\ \ package has been generated using the [OpenAPI Generator](https:/openapi-generator.tech/)\ \ version 7.8.0. On top of the generated API, a helper file, mozart_client.py,\ \ has been made that makes the API more pythonic. We recommend using this.\n\ diff --git a/python_client/PKG-INFO b/python_client/PKG-INFO index 8812594..526bc49 100644 --- a/python_client/PKG-INFO +++ b/python_client/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: mozart_api -Version: 3.4.1.8.5 +Version: 3.4.1.8.8 Summary: Mozart platform API Home-page: https://pypi.org/project/mozart-api/ License: MIT diff --git a/python_client/mozart_api/__init__.py b/python_client/mozart_api/__init__.py index 3d30398..f7f3507 100644 --- a/python_client/mozart_api/__init__.py +++ b/python_client/mozart_api/__init__.py @@ -15,7 +15,7 @@ """ # noqa: E501 -__version__ = "3.4.1.8.7" +__version__ = "3.4.1.8.8" # import apis into sdk package from mozart_api.api.beolink_api import BeolinkApi diff --git a/python_client/mozart_api/api_client.py b/python_client/mozart_api/api_client.py index caa0036..0be724d 100644 --- a/python_client/mozart_api/api_client.py +++ b/python_client/mozart_api/api_client.py @@ -61,20 +61,28 @@ class ApiClient: _pool = None def __init__( - self, configuration=None, header_name=None, header_value=None, cookie=None + self, + configuration=None, + header_name=None, + header_value=None, + cookie=None, + rest_client=None, ) -> None: # use default configuration if none is provided if configuration is None: configuration = Configuration.get_default() self.configuration = configuration - - self.rest_client = rest.RESTClientObject(configuration) + # Add support for user-defined SSLContext through the RESTClientObject + if rest_client is None: + self.rest_client = rest.RESTClientObject(configuration) + else: + self.rest_client = rest_client self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = "OpenAPI-Generator/3.4.1.8.7/python" + self.user_agent = "OpenAPI-Generator/3.4.1.8.8/python" self.client_side_validation = configuration.client_side_validation async def __aenter__(self): diff --git a/python_client/mozart_api/configuration.py b/python_client/mozart_api/configuration.py index 2d1c4dd..afe0f24 100644 --- a/python_client/mozart_api/configuration.py +++ b/python_client/mozart_api/configuration.py @@ -381,7 +381,7 @@ def to_debug_report(self): "OS: {env}\n" "Python Version: {pyversion}\n" "Version of the API: 0.2.0\n" - "SDK Package Version: 3.4.1.8.7".format( + "SDK Package Version: 3.4.1.8.8".format( env=sys.platform, pyversion=sys.version ) ) diff --git a/python_client/mozart_api/models/beolink_experiences_request.py b/python_client/mozart_api/models/beolink_experiences_request.py deleted file mode 100644 index b26b0a8..0000000 --- a/python_client/mozart_api/models/beolink_experiences_request.py +++ /dev/null @@ -1,69 +0,0 @@ -# coding: utf-8 - -""" - Mozart platform API - - API for interacting with the Mozart platform. - - The version of the OpenAPI document: 0.2.0 - Contact: support@bang-olufsen.dk - Generated by OpenAPI Generator (https://openapi-generator.tech) - - Do not edit the class manually. -""" # noqa: E501 - - -from __future__ import annotations -import pprint -import re # noqa: F401 -import json - - -from pydantic import BaseModel, Field, StrictStr - - -class BeolinkExperiencesRequest(BaseModel): - """ - BeolinkExperiencesRequest - """ - - request_id: StrictStr = Field( - ..., alias="requestID", description="Beolink request ID" - ) - __properties = ["requestID"] - - class Config: - """Pydantic configuration""" - - allow_population_by_field_name = True - validate_assignment = True - - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> BeolinkExperiencesRequest: - """Create an instance of BeolinkExperiencesRequest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self): - """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, exclude={}, exclude_none=True) - return _dict - - @classmethod - def from_dict(cls, obj: dict) -> BeolinkExperiencesRequest: - """Create an instance of BeolinkExperiencesRequest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return BeolinkExperiencesRequest.parse_obj(obj) - - _obj = BeolinkExperiencesRequest.parse_obj({"request_id": obj.get("requestID")}) - return _obj diff --git a/python_client/mozart_api/mozart_client.py b/python_client/mozart_api/mozart_client.py index 5aa3f4e..b853d1f 100644 --- a/python_client/mozart_api/mozart_client.py +++ b/python_client/mozart_api/mozart_client.py @@ -10,6 +10,7 @@ from collections import defaultdict from dataclasses import dataclass from datetime import time +from ssl import SSLContext from typing import Callable, Literal from aiohttp import ClientSession @@ -21,6 +22,7 @@ from inflection import underscore from mozart_api.api.mozart_api import MozartApi from mozart_api.api_client import ApiClient +from mozart_api.rest import RESTClientObject from mozart_api.configuration import Configuration from mozart_api.exceptions import ApiException from mozart_api.models import Art, PlaybackContentMetadata @@ -130,7 +132,7 @@ def get_highest_resolution_artwork(metadata: PlaybackContentMetadata) -> Art: class MozartClient(MozartApi): """User friendly Mozart REST API and WebSocket client.""" - def __init__(self, host: str) -> None: + def __init__(self, host: str, ssl_context: SSLContext | None = None) -> None: """Initialize Mozart client.""" self.host = host self.websocket_connected = False @@ -151,10 +153,20 @@ def __init__(self, host: str) -> None: self._notification_callbacks.default_factory = lambda: None # Configure MozartApi object. - self.configuration = Configuration(host="http://" + self.host) + self.configuration = Configuration(host=f"http://{self.host}") self.configuration.verify_ssl = False - super().__init__(ApiClient(self.configuration)) + if ssl_context is None: + super().__init__(ApiClient(self.configuration)) + elif ssl_context: + super().__init__( + ApiClient( + self.configuration, + rest_client=RESTClientObject( + configuration=self.configuration, ssl_context=ssl_context + ), + ) + ) async def close_api_client(self) -> None: """Close the API ClientSession.""" diff --git a/python_client/mozart_api/rest.py b/python_client/mozart_api/rest.py index 6f81c24..6ea2abc 100644 --- a/python_client/mozart_api/rest.py +++ b/python_client/mozart_api/rest.py @@ -46,21 +46,24 @@ def getheader(self, name, default=None): class RESTClientObject: - def __init__(self, configuration, pools_size=4, maxsize=None) -> None: + def __init__( + self, configuration, pools_size=4, maxsize=None, ssl_context=None + ) -> None: # maxsize is number of requests to host that are allowed in parallel if maxsize is None: maxsize = configuration.connection_pool_maxsize - ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert) - if configuration.cert_file: - ssl_context.load_cert_chain( - configuration.cert_file, keyfile=configuration.key_file - ) + if ssl_context is None: + ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert) + if configuration.cert_file: + ssl_context.load_cert_chain( + configuration.cert_file, keyfile=configuration.key_file + ) - if not configuration.verify_ssl: - ssl_context.check_hostname = False - ssl_context.verify_mode = ssl.CERT_NONE + if not configuration.verify_ssl: + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE connector = aiohttp.TCPConnector(limit=maxsize, ssl=ssl_context) diff --git a/python_client/pyproject.toml b/python_client/pyproject.toml index 89fea29..e6e5808 100644 --- a/python_client/pyproject.toml +++ b/python_client/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mozart_api" -version = "3.4.1.8.7" +version = "3.4.1.8.8" description = "Mozart platform API" authors = [ "BangOlufsen ",