From e64cf41aec2b6e0e4d1dcfc532b12d32484123ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 3 Sep 2020 16:38:41 +0200 Subject: [PATCH] Addon api changes (#2006) * Add startup to addon info API * Don't fail when validating, just return the problem as 200 * Add sugestions * Review comments --- API.md | 3 ++- supervisor/api/addons.py | 10 +++++++++- supervisor/const.py | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 58a846bf0..935943dab 100644 --- a/API.md +++ b/API.md @@ -491,7 +491,7 @@ Update information for a single interface | Option | Description | | --------- | ---------------------------------------------------------------------- | | `address` | The new IP address for the interface in the X.X.X.X/XX format | -| `dns` | List of DNS servers to use | +| `dns` | List of DNS servers to use | | `gateway` | The gateway the interface should use | | `method` | Set if the interface should use DHCP or not, can be `dhcp` or `static` | @@ -565,6 +565,7 @@ Get all available add-ons. "version": "null|VERSION_INSTALLED", "version_latest": "version_latest", "state": "none|started|stopped", + "startup": "initialize|system|services|application|once", "boot": "auto|manual", "build": "bool", "options": "{}", diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index b0ae1c2ef..0ddfcbcff 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -62,6 +62,7 @@ from ..const import ( ATTR_MEMORY_LIMIT, ATTR_MEMORY_PERCENT, ATTR_MEMORY_USAGE, + ATTR_MESSAGE, ATTR_NAME, ATTR_NETWORK, ATTR_NETWORK_DESCRIPTION, @@ -78,11 +79,13 @@ from ..const import ( ATTR_SLUG, ATTR_SOURCE, ATTR_STAGE, + ATTR_STARTUP, ATTR_STATE, ATTR_STDIN, ATTR_UDEV, ATTR_URL, ATTR_USB, + ATTR_VALID, ATTR_VERSION, ATTR_VERSION_LATEST, ATTR_VIDEO, @@ -250,6 +253,7 @@ class APIAddons(CoreSysAttributes): ATTR_AUDIO: addon.with_audio, ATTR_AUDIO_INPUT: None, ATTR_AUDIO_OUTPUT: None, + ATTR_STARTUP: addon.startup, ATTR_SERVICES: _pretty_services(addon), ATTR_DISCOVERY: addon.discovery, ATTR_IP_ADDRESS: None, @@ -320,10 +324,14 @@ class APIAddons(CoreSysAttributes): async def options_validate(self, request: web.Request) -> None: """Validate user options for add-on.""" addon = self._extract_addon_installed(request) + data = {ATTR_MESSAGE: "", ATTR_VALID: True} try: addon.schema(addon.options) except vol.Invalid as ex: - raise APIError(humanize_error(addon.options, ex)) from None + data[ATTR_MESSAGE] = humanize_error(addon.options, ex) + data[ATTR_VALID] = False + + return data @api_process async def security(self, request: web.Request) -> None: diff --git a/supervisor/const.py b/supervisor/const.py index 90682825c..bc705ed1a 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -195,6 +195,7 @@ ATTR_MAP = "map" ATTR_MEMORY_LIMIT = "memory_limit" ATTR_MEMORY_PERCENT = "memory_percent" ATTR_MEMORY_USAGE = "memory_usage" +ATTR_MESSAGE = "message" ATTR_METHOD = "method" ATTR_METHODS = ["dhcp", "static"] ATTR_MODE = "mode" @@ -262,6 +263,7 @@ ATTR_USB = "usb" ATTR_USER = "user" ATTR_USERNAME = "username" ATTR_UUID = "uuid" +ATTR_VALID = "valid" ATTR_VALUE = "value" ATTR_VERSION = "version" ATTR_VERSION_LATEST = "version_latest"