Adds options_validate API (#1996)

This commit is contained in:
Joakim Sørensen 2020-08-30 17:58:13 +02:00 committed by GitHub
parent f32d17d924
commit 1c7b1f1462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

1
API.md
View File

@ -619,6 +619,7 @@ Get all available add-ons.
- GET `/addons/{addon}/changelog`
- GET `/addons/{addon}/documentation`
- POST `/addons/{addon}/options`
- POST `/addons/{addon}/options/validate`
```json
{

View File

@ -268,6 +268,9 @@ class RestAPI(CoreSysAttributes):
web.post("/addons/{addon}/restart", api_addons.restart),
web.post("/addons/{addon}/update", api_addons.update),
web.post("/addons/{addon}/options", api_addons.options),
web.post(
"/addons/{addon}/options/validate", api_addons.options_validate
),
web.post("/addons/{addon}/rebuild", api_addons.rebuild),
web.get("/addons/{addon}/logs", api_addons.logs),
web.get("/addons/{addon}/icon", api_addons.icon),

View File

@ -5,6 +5,7 @@ from typing import Any, Awaitable, Dict, List
from aiohttp import web
import voluptuous as vol
from voluptuous.humanize import humanize_error
from ..addons import AnyAddon
from ..addons.addon import Addon
@ -315,6 +316,15 @@ class APIAddons(CoreSysAttributes):
addon.save_persist()
@api_process
async def options_validate(self, request: web.Request) -> None:
"""Validate user options for add-on."""
addon = self._extract_addon_installed(request)
try:
addon.schema(addon.options)
except vol.Invalid as ex:
raise APIError(humanize_error(addon.options, ex)) from None
@api_process
async def security(self, request: web.Request) -> None:
"""Store security options for add-on."""