This commit is contained in:
Pascal Vizeli 2019-09-11 16:37:49 +02:00 committed by GitHub
parent 02d4045ec3
commit db9d0f2639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 7 deletions

View File

@ -351,7 +351,7 @@ class Addon(AddonModel):
options = self.options
try:
schema(options)
options = schema(options)
write_json_file(self.path_options, options)
except vol.Invalid as ex:
_LOGGER.error(

View File

@ -356,6 +356,8 @@ def _single_validate(coresys, typ, value, key):
if str(value).startswith("!secret "):
secret: str = value.partition(" ")[2]
value = coresys.secrets.get(secret)
if value is None:
raise vol.Invalid(f"Unknown secret {secret}")
# parse extend data from type
match = RE_SCHEMA_ELEMENT.match(typ)

View File

@ -269,7 +269,9 @@ class APIAddons(CoreSysAttributes):
addon_schema = SCHEMA_OPTIONS.extend(
{vol.Optional(ATTR_OPTIONS): vol.Any(None, addon.schema)}
)
body: Dict[str, Any] = await api_validate(addon_schema, request)
body: Dict[str, Any] = await api_validate(
addon_schema, request, origin=[ATTR_OPTIONS]
)
if ATTR_OPTIONS in body:
addon.options = body[ATTR_OPTIONS]

View File

@ -161,7 +161,9 @@ class APISupervisor(CoreSysAttributes):
@api_process
def reload(self, request: web.Request) -> Awaitable[None]:
"""Reload add-ons, configuration, etc."""
return asyncio.shield(self.sys_updater.reload())
return asyncio.shield(
asyncio.wait([self.sys_updater.reload(), self.sys_secrets.reload()])
)
@api_process
def repair(self, request: web.Request) -> Awaitable[None]:

View File

@ -1,6 +1,7 @@
"""Init file for Hass.io util for RESTful API."""
import json
import logging
from typing import Optional, List
from aiohttp import web
import voluptuous as vol
@ -89,12 +90,22 @@ def api_return_ok(data=None):
return web.json_response({JSON_RESULT: RESULT_OK, JSON_DATA: data or {}})
async def api_validate(schema, request):
async def api_validate(
schema: vol.Schema, request: web.Request, origin: Optional[List[str]] = None
):
"""Validate request data with schema."""
data = await request.json(loads=json_loads)
try:
data = schema(data)
data_validated = schema(data)
except vol.Invalid as ex:
raise APIError(humanize_error(data, ex)) from None
return data
if not origin:
return data_validated
for origin_value in origin:
if origin_value not in data_validated:
continue
data_validated[origin_value] = data[origin_value]
return data_validated

View File

@ -19,7 +19,7 @@ RUN_RELOAD_SNAPSHOTS = 72000
RUN_RELOAD_HOST = 72000
RUN_RELOAD_UPDATER = 7200
RUN_RELOAD_INGRESS = 930
RUN_RELOAD_SECRETS = 900
RUN_RELOAD_SECRETS = 630
RUN_WATCHDOG_HOMEASSISTANT_DOCKER = 15
RUN_WATCHDOG_HOMEASSISTANT_API = 300