From 428a4dd8497b5db9751abee8684d19f05252b414 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 25 Oct 2019 16:55:44 +0200 Subject: [PATCH 1/7] Bump version 193 --- hassio/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/const.py b/hassio/const.py index 6a2887376..b005d6ffd 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -2,7 +2,7 @@ from pathlib import Path from ipaddress import ip_network -HASSIO_VERSION = "192" +HASSIO_VERSION = "193" URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons" From e438858da0b6d73b729e4a5c9aa5b78af7cc236f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 28 Oct 2019 14:34:26 +0100 Subject: [PATCH 2/7] Better proxy handling (#1350) --- hassio/api/ingress.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hassio/api/ingress.py b/hassio/api/ingress.py index e870a999b..839f0bc53 100644 --- a/hassio/api/ingress.py +++ b/hassio/api/ingress.py @@ -226,6 +226,10 @@ def _response_header(response: aiohttp.ClientResponse) -> Dict[str, str]: hdrs.CONTENT_LENGTH, hdrs.CONTENT_TYPE, hdrs.CONTENT_ENCODING, + hdrs.SEC_WEBSOCKET_EXTENSIONS, + hdrs.SEC_WEBSOCKET_PROTOCOL, + hdrs.SEC_WEBSOCKET_VERSION, + hdrs.SEC_WEBSOCKET_KEY, ): continue headers[name] = value From 93f4c5e207ef6b93374a6e404d244c91a14c8ca6 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 28 Oct 2019 17:57:03 +0100 Subject: [PATCH 3/7] Real optimize websocket proxy (#1351) --- hassio/api/ingress.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hassio/api/ingress.py b/hassio/api/ingress.py index 839f0bc53..a0fe3a480 100644 --- a/hassio/api/ingress.py +++ b/hassio/api/ingress.py @@ -204,7 +204,15 @@ def _init_header( # filter flags for name, value in request.headers.items(): - if name in (hdrs.CONTENT_LENGTH, hdrs.CONTENT_ENCODING, istr(HEADER_TOKEN)): + if name in ( + hdrs.CONTENT_LENGTH, + hdrs.CONTENT_ENCODING, + hdrs.SEC_WEBSOCKET_EXTENSIONS, + hdrs.SEC_WEBSOCKET_PROTOCOL, + hdrs.SEC_WEBSOCKET_VERSION, + hdrs.SEC_WEBSOCKET_KEY, + istr(HEADER_TOKEN), + ): continue headers[name] = value @@ -226,10 +234,6 @@ def _response_header(response: aiohttp.ClientResponse) -> Dict[str, str]: hdrs.CONTENT_LENGTH, hdrs.CONTENT_TYPE, hdrs.CONTENT_ENCODING, - hdrs.SEC_WEBSOCKET_EXTENSIONS, - hdrs.SEC_WEBSOCKET_PROTOCOL, - hdrs.SEC_WEBSOCKET_VERSION, - hdrs.SEC_WEBSOCKET_KEY, ): continue headers[name] = value From 380ca13be1ee0094c532dcd11c1172c68db7c8e0 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 30 Oct 2019 23:18:04 +0100 Subject: [PATCH 4/7] Pin Black (#1355) * Pin black version * fix devcontainer --- .devcontainer/Dockerfile | 2 +- azure-pipelines.yml | 12 ------------ hassio/utils/tar.py | 2 +- requirements_tests.txt | 1 + tox.ini | 7 ++++++- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 18b012145..d48100d8d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -36,7 +36,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Install Python dependencies from requirements.txt if it exists COPY requirements.txt requirements_tests.txt ./ RUN pip3 install -r requirements.txt -r requirements_tests.txt \ - && pip3 install black tox \ + && pip3 install tox \ && rm -f requirements.txt requirements_tests.txt # Set the default shell to bash instead of sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5a1eb8e35..6502004ab 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -42,18 +42,6 @@ stages: displayName: 'Install Tox' - script: tox displayName: 'Run Tox' - - job: 'Black' - pool: - vmImage: 'ubuntu-latest' - steps: - - task: UsePythonVersion@0 - displayName: 'Use Python $(python.version)' - inputs: - versionSpec: '3.7' - - script: pip install black - displayName: 'Install black' - - script: black --target-version py37 --check hassio tests - displayName: 'Run Black' - job: 'JQ' pool: vmImage: 'ubuntu-latest' diff --git a/hassio/utils/tar.py b/hassio/utils/tar.py index 27f12fa94..0ffd97cf9 100644 --- a/hassio/utils/tar.py +++ b/hassio/utils/tar.py @@ -134,7 +134,7 @@ def secure_path(tar: tarfile.TarFile) -> Generator[tarfile.TarInfo, None, None]: def exclude_filter( - exclude_list: List[str] + exclude_list: List[str], ) -> Callable[[tarfile.TarInfo], Optional[tarfile.TarInfo]]: """Create callable filter function to check TarInfo for add.""" diff --git a/requirements_tests.txt b/requirements_tests.txt index 4cf87e285..0e79b2c23 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -3,3 +3,4 @@ pylint==2.4.3 pytest==5.2.2 pytest-timeout==1.3.3 pytest-aiohttp==0.3.0 +black==19.10b0 diff --git a/tox.ini b/tox.ini index 99aa3aa26..320d34d6c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint, tests +envlist = lint, tests, black [testenv] deps = @@ -17,3 +17,8 @@ commands = basepython = python3 commands = pytest --timeout=10 tests + +[testenv:black] +basepython = python3 +commands = + black --target-version py37 --check hassio tests setup.py From ee7631739298eb6b5c6dc6d8806ae66a75251337 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2019 23:19:25 +0100 Subject: [PATCH 5/7] Bump flake8 from 3.7.8 to 3.7.9 (#1352) Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.7.8 to 3.7.9. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.7.8...3.7.9) Signed-off-by: dependabot-preview[bot] --- requirements_tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_tests.txt b/requirements_tests.txt index 0e79b2c23..9e3de47d5 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -1,4 +1,4 @@ -flake8==3.7.8 +flake8==3.7.9 pylint==2.4.3 pytest==5.2.2 pytest-timeout==1.3.3 From a92cab48e0d5cbcc581248e73991b387442a180c Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 6 Nov 2019 23:57:51 +0100 Subject: [PATCH 6/7] Support upload streaming (#1362) * Support upload streaming * Fix header * Fix typing --- hassio/api/proxy.py | 22 ++++++++++------------ hassio/homeassistant.py | 5 +++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/hassio/api/proxy.py b/hassio/api/proxy.py index c0b310163..3cea4c06c 100644 --- a/hassio/api/proxy.py +++ b/hassio/api/proxy.py @@ -8,7 +8,6 @@ from aiohttp import web from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized from aiohttp.client_exceptions import ClientConnectorError from aiohttp.hdrs import CONTENT_TYPE, AUTHORIZATION -import async_timeout from ..const import HEADER_HA_ACCESS from ..coresys import CoreSysAttributes @@ -17,6 +16,9 @@ from ..exceptions import HomeAssistantAuthError, HomeAssistantAPIError, APIError _LOGGER: logging.Logger = logging.getLogger(__name__) +LEGACY_HEADER = ("X-Speech-Content",) + + class APIProxy(CoreSysAttributes): """API Proxy for Home Assistant.""" @@ -43,20 +45,16 @@ class APIProxy(CoreSysAttributes): async def _api_client(self, request: web.Request, path: str, timeout: int = 300): """Return a client request with proxy origin for Home Assistant.""" try: - # read data - with async_timeout.timeout(30): - data = await request.read() - - if data: - content_type = request.content_type - else: - content_type = None - async with self.sys_homeassistant.make_request( request.method.lower(), f"api/{path}", - content_type=content_type, - data=data, + headers={ + name: value + for name, value in request.headers.items() + if name in LEGACY_HEADER + }, + content_type=request.content_type, + data=request.content, timeout=timeout, params=request.query, ) as resp: diff --git a/hassio/homeassistant.py b/hassio/homeassistant.py index 672c71856..a765a4725 100644 --- a/hassio/homeassistant.py +++ b/hassio/homeassistant.py @@ -487,13 +487,14 @@ class HomeAssistant(JsonConfig, CoreSysAttributes): path: str, json: Optional[Dict[str, Any]] = None, content_type: Optional[str] = None, - data: Optional[bytes] = None, + data: Any = None, timeout: int = 30, params: Optional[Dict[str, str]] = None, + headers: Optional[Dict[str, str]] = None, ) -> AsyncContextManager[aiohttp.ClientResponse]: """Async context manager to make a request with right auth.""" url = f"{self.api_url}/{path}" - headers = {} + headers = headers or {} # Passthrough content type if content_type is not None: From ce3d3d58ec16196322d212f04a8010a345ed8d38 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 7 Nov 2019 15:12:42 +0000 Subject: [PATCH 7/7] Fix name --- hassio/api/proxy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hassio/api/proxy.py b/hassio/api/proxy.py index 3cea4c06c..59e5db03e 100644 --- a/hassio/api/proxy.py +++ b/hassio/api/proxy.py @@ -16,7 +16,7 @@ from ..exceptions import HomeAssistantAuthError, HomeAssistantAPIError, APIError _LOGGER: logging.Logger = logging.getLogger(__name__) -LEGACY_HEADER = ("X-Speech-Content",) +FORWARD_HEADERS = ("X-Speech-Content",) class APIProxy(CoreSysAttributes): @@ -51,7 +51,7 @@ class APIProxy(CoreSysAttributes): headers={ name: value for name, value in request.headers.items() - if name in LEGACY_HEADER + if name in FORWARD_HEADERS }, content_type=request.content_type, data=request.content,