mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-11 20:10:16 +00:00
Check management (#2703)
* Check management * Add test * Don't allow disable core_security * options and decorator * streamline config handling * streamline v2 * fix logging * Add tests * Fix test * cleanup v1 * fix api * Add more test * Expose option also for cli * address comments from Paulus * Address second comment * Update supervisor/resolution/checks/base.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * fix lint * Fix black Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
@@ -4,6 +4,8 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.hdrs import AUTHORIZATION
|
||||
from aiohttp.web_exceptions import HTTPUnauthorized
|
||||
from aiohttp.web_request import Request
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
|
||||
@@ -14,9 +16,11 @@ from ..const import (
|
||||
JSON_DATA,
|
||||
JSON_MESSAGE,
|
||||
JSON_RESULT,
|
||||
REQUEST_FROM,
|
||||
RESULT_ERROR,
|
||||
RESULT_OK,
|
||||
)
|
||||
from ..coresys import CoreSys
|
||||
from ..exceptions import APIError, APIForbidden, DockerAPIError, HassioError
|
||||
from ..utils import check_exception_chain, get_message_from_exception_chain
|
||||
from ..utils.json import JSONEncoder
|
||||
@@ -73,6 +77,20 @@ def api_process(method):
|
||||
return wrap_api
|
||||
|
||||
|
||||
def require_home_assistant(method):
|
||||
"""Ensure that the request comes from Home Assistant."""
|
||||
|
||||
async def wrap_api(api, *args, **kwargs):
|
||||
"""Return API information."""
|
||||
coresys: CoreSys = api.coresys
|
||||
request: Request = args[0]
|
||||
if request[REQUEST_FROM] != coresys.homeassistant:
|
||||
raise HTTPUnauthorized()
|
||||
return await method(api, *args, **kwargs)
|
||||
|
||||
return wrap_api
|
||||
|
||||
|
||||
def api_process_raw(content):
|
||||
"""Wrap content_type into function."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user