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/api/ingress.py b/hassio/api/ingress.py index e870a999b..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 diff --git a/hassio/api/proxy.py b/hassio/api/proxy.py index c0b310163..59e5db03e 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__) +FORWARD_HEADERS = ("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 FORWARD_HEADERS + }, + content_type=request.content_type, + data=request.content, timeout=timeout, params=request.query, ) as resp: 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" 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: 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..9e3de47d5 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -1,5 +1,6 @@ -flake8==3.7.8 +flake8==3.7.9 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