mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 10:16:29 +00:00
Forward Params (#1150)
This commit is contained in:
parent
0a3a752b4c
commit
a37c90af96
@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class APIProxy(CoreSysAttributes):
|
class APIProxy(CoreSysAttributes):
|
||||||
"""API Proxy for Home Assistant."""
|
"""API Proxy for Home Assistant."""
|
||||||
|
|
||||||
def _check_access(self, request):
|
def _check_access(self, request: web.Request):
|
||||||
"""Check the Hass.io token."""
|
"""Check the Hass.io token."""
|
||||||
if AUTHORIZATION in request.headers:
|
if AUTHORIZATION in request.headers:
|
||||||
bearer = request.headers[AUTHORIZATION]
|
bearer = request.headers[AUTHORIZATION]
|
||||||
@ -40,7 +40,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
raise HTTPUnauthorized()
|
raise HTTPUnauthorized()
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def _api_client(self, request, path, timeout=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
|
# read data
|
||||||
@ -58,6 +58,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
data=data,
|
data=data,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
params=request.query,
|
||||||
) as resp:
|
) as resp:
|
||||||
yield resp
|
yield resp
|
||||||
return
|
return
|
||||||
@ -73,7 +74,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
|
|
||||||
raise HTTPBadGateway()
|
raise HTTPBadGateway()
|
||||||
|
|
||||||
async def stream(self, request):
|
async def stream(self, request: web.Request):
|
||||||
"""Proxy HomeAssistant EventStream Requests."""
|
"""Proxy HomeAssistant EventStream Requests."""
|
||||||
self._check_access(request)
|
self._check_access(request)
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
_LOGGER.info("Home Assistant EventStream close")
|
_LOGGER.info("Home Assistant EventStream close")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def api(self, request):
|
async def api(self, request: web.Request):
|
||||||
"""Proxy Home Assistant API Requests."""
|
"""Proxy Home Assistant API Requests."""
|
||||||
self._check_access(request)
|
self._check_access(request)
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
|
|
||||||
raise APIError()
|
raise APIError()
|
||||||
|
|
||||||
async def websocket(self, request):
|
async def websocket(self, request: web.Request):
|
||||||
"""Initialize a WebSocket API connection."""
|
"""Initialize a WebSocket API connection."""
|
||||||
_LOGGER.info("Home Assistant WebSocket API request initialize")
|
_LOGGER.info("Home Assistant WebSocket API request initialize")
|
||||||
|
|
||||||
|
@ -460,7 +460,8 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
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: Optional[bytes] = None,
|
||||||
timeout=30,
|
timeout: int = 30,
|
||||||
|
params: 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}"
|
||||||
@ -482,7 +483,12 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with getattr(self.sys_websession_ssl, method)(
|
async with getattr(self.sys_websession_ssl, method)(
|
||||||
url, data=data, timeout=timeout, json=json, headers=headers
|
url,
|
||||||
|
data=data,
|
||||||
|
timeout=timeout,
|
||||||
|
json=json,
|
||||||
|
headers=headers,
|
||||||
|
params=params,
|
||||||
) as resp:
|
) as resp:
|
||||||
# Access token expired
|
# Access token expired
|
||||||
if resp.status == 401 and self.refresh_token:
|
if resp.status == 401 and self.refresh_token:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user