mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-25 18:16:32 +00:00
commit
ce3f670597
@ -36,7 +36,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
# Install Python dependencies from requirements.txt if it exists
|
# Install Python dependencies from requirements.txt if it exists
|
||||||
COPY requirements.txt requirements_tests.txt ./
|
COPY requirements.txt requirements_tests.txt ./
|
||||||
RUN pip3 install -r requirements.txt -r 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
|
&& rm -f requirements.txt requirements_tests.txt
|
||||||
|
|
||||||
# Set the default shell to bash instead of sh
|
# Set the default shell to bash instead of sh
|
||||||
|
@ -42,18 +42,6 @@ stages:
|
|||||||
displayName: 'Install Tox'
|
displayName: 'Install Tox'
|
||||||
- script: tox
|
- script: tox
|
||||||
displayName: 'Run 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'
|
- job: 'JQ'
|
||||||
pool:
|
pool:
|
||||||
vmImage: 'ubuntu-latest'
|
vmImage: 'ubuntu-latest'
|
||||||
|
@ -204,7 +204,15 @@ def _init_header(
|
|||||||
|
|
||||||
# filter flags
|
# filter flags
|
||||||
for name, value in request.headers.items():
|
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
|
continue
|
||||||
headers[name] = value
|
headers[name] = value
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ from aiohttp import web
|
|||||||
from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
|
from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from aiohttp.hdrs import CONTENT_TYPE, AUTHORIZATION
|
from aiohttp.hdrs import CONTENT_TYPE, AUTHORIZATION
|
||||||
import async_timeout
|
|
||||||
|
|
||||||
from ..const import HEADER_HA_ACCESS
|
from ..const import HEADER_HA_ACCESS
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
@ -17,6 +16,9 @@ from ..exceptions import HomeAssistantAuthError, HomeAssistantAPIError, APIError
|
|||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
FORWARD_HEADERS = ("X-Speech-Content",)
|
||||||
|
|
||||||
|
|
||||||
class APIProxy(CoreSysAttributes):
|
class APIProxy(CoreSysAttributes):
|
||||||
"""API Proxy for Home Assistant."""
|
"""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):
|
async def _api_client(self, request: web.Request, path: str, timeout: int = 300):
|
||||||
"""Return a client request with proxy origin for Home Assistant."""
|
"""Return a client request with proxy origin for Home Assistant."""
|
||||||
try:
|
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(
|
async with self.sys_homeassistant.make_request(
|
||||||
request.method.lower(),
|
request.method.lower(),
|
||||||
f"api/{path}",
|
f"api/{path}",
|
||||||
content_type=content_type,
|
headers={
|
||||||
data=data,
|
name: value
|
||||||
|
for name, value in request.headers.items()
|
||||||
|
if name in FORWARD_HEADERS
|
||||||
|
},
|
||||||
|
content_type=request.content_type,
|
||||||
|
data=request.content,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
params=request.query,
|
params=request.query,
|
||||||
) as resp:
|
) as resp:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ipaddress import ip_network
|
from ipaddress import ip_network
|
||||||
|
|
||||||
HASSIO_VERSION = "192"
|
HASSIO_VERSION = "193"
|
||||||
|
|
||||||
|
|
||||||
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
|
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
|
||||||
|
@ -487,13 +487,14 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
path: str,
|
path: str,
|
||||||
json: Optional[Dict[str, Any]] = None,
|
json: Optional[Dict[str, Any]] = None,
|
||||||
content_type: Optional[str] = None,
|
content_type: Optional[str] = None,
|
||||||
data: Optional[bytes] = None,
|
data: Any = None,
|
||||||
timeout: int = 30,
|
timeout: int = 30,
|
||||||
params: Optional[Dict[str, str]] = None,
|
params: Optional[Dict[str, str]] = None,
|
||||||
|
headers: Optional[Dict[str, str]] = None,
|
||||||
) -> AsyncContextManager[aiohttp.ClientResponse]:
|
) -> AsyncContextManager[aiohttp.ClientResponse]:
|
||||||
"""Async context manager to make a request with right auth."""
|
"""Async context manager to make a request with right auth."""
|
||||||
url = f"{self.api_url}/{path}"
|
url = f"{self.api_url}/{path}"
|
||||||
headers = {}
|
headers = headers or {}
|
||||||
|
|
||||||
# Passthrough content type
|
# Passthrough content type
|
||||||
if content_type is not None:
|
if content_type is not None:
|
||||||
|
@ -134,7 +134,7 @@ def secure_path(tar: tarfile.TarFile) -> Generator[tarfile.TarInfo, None, None]:
|
|||||||
|
|
||||||
|
|
||||||
def exclude_filter(
|
def exclude_filter(
|
||||||
exclude_list: List[str]
|
exclude_list: List[str],
|
||||||
) -> Callable[[tarfile.TarInfo], Optional[tarfile.TarInfo]]:
|
) -> Callable[[tarfile.TarInfo], Optional[tarfile.TarInfo]]:
|
||||||
"""Create callable filter function to check TarInfo for add."""
|
"""Create callable filter function to check TarInfo for add."""
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
flake8==3.7.8
|
flake8==3.7.9
|
||||||
pylint==2.4.3
|
pylint==2.4.3
|
||||||
pytest==5.2.2
|
pytest==5.2.2
|
||||||
pytest-timeout==1.3.3
|
pytest-timeout==1.3.3
|
||||||
pytest-aiohttp==0.3.0
|
pytest-aiohttp==0.3.0
|
||||||
|
black==19.10b0
|
||||||
|
7
tox.ini
7
tox.ini
@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = lint, tests
|
envlist = lint, tests, black
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps =
|
||||||
@ -17,3 +17,8 @@ commands =
|
|||||||
basepython = python3
|
basepython = python3
|
||||||
commands =
|
commands =
|
||||||
pytest --timeout=10 tests
|
pytest --timeout=10 tests
|
||||||
|
|
||||||
|
[testenv:black]
|
||||||
|
basepython = python3
|
||||||
|
commands =
|
||||||
|
black --target-version py37 --check hassio tests setup.py
|
||||||
|
Loading…
x
Reference in New Issue
Block a user