From 6d70699295965901e08a6e06c74e96706ce9b9dd Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Thu, 3 Sep 2020 10:44:17 +0000 Subject: [PATCH 1/4] Add startup to addon info API --- supervisor/api/addons.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index b0ae1c2ef26..957c4a0e74c 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -78,6 +78,7 @@ ATTR_SLUG, ATTR_SOURCE, ATTR_STAGE, + ATTR_STARTUP, ATTR_STATE, ATTR_STDIN, ATTR_UDEV, @@ -250,6 +251,7 @@ async def info(self, request: web.Request) -> Dict[str, Any]: 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, From 744912082399ef2cb22a1cbe60c558d093d63a5d Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Thu, 3 Sep 2020 11:05:57 +0000 Subject: [PATCH 2/4] Don't fail when validating, just return the problem as 200 --- supervisor/api/addons.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index 957c4a0e74c..cb7ec47713a 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -322,10 +322,12 @@ async def options(self, request: web.Request) -> None: async def options_validate(self, request: web.Request) -> None: """Validate user options for add-on.""" addon = self._extract_addon_installed(request) + data = {"message": ""} try: addon.schema(addon.options) except vol.Invalid as ex: - raise APIError(humanize_error(addon.options, ex)) from None + data["message"] = humanize_error(addon.options, ex) + return data @api_process async def security(self, request: web.Request) -> None: From ded99239ae5717342f6bfec9e399d31525bc551c Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Thu, 3 Sep 2020 11:13:37 +0000 Subject: [PATCH 3/4] Add sugestions --- supervisor/api/addons.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index cb7ec47713a..7ccda2e196a 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -322,11 +322,13 @@ async def options(self, request: web.Request) -> None: async def options_validate(self, request: web.Request) -> None: """Validate user options for add-on.""" addon = self._extract_addon_installed(request) - data = {"message": ""} + data = {"message": "", "valid": True} try: addon.schema(addon.options) except vol.Invalid as ex: data["message"] = humanize_error(addon.options, ex) + data["valid"] = False + return data @api_process From bd718ec90f66e833525c3d29aac84c2f2b9d27c5 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Thu, 3 Sep 2020 14:26:43 +0000 Subject: [PATCH 4/4] Review comments --- API.md | 3 ++- supervisor/api/addons.py | 8 +++++--- supervisor/const.py | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index 58a846bf0de..935943dab85 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 7ccda2e196a..0ddfcbcfffe 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -62,6 +62,7 @@ ATTR_MEMORY_LIMIT, ATTR_MEMORY_PERCENT, ATTR_MEMORY_USAGE, + ATTR_MESSAGE, ATTR_NAME, ATTR_NETWORK, ATTR_NETWORK_DESCRIPTION, @@ -84,6 +85,7 @@ ATTR_UDEV, ATTR_URL, ATTR_USB, + ATTR_VALID, ATTR_VERSION, ATTR_VERSION_LATEST, ATTR_VIDEO, @@ -322,12 +324,12 @@ async def options(self, request: web.Request) -> None: async def options_validate(self, request: web.Request) -> None: """Validate user options for add-on.""" addon = self._extract_addon_installed(request) - data = {"message": "", "valid": True} + data = {ATTR_MESSAGE: "", ATTR_VALID: True} try: addon.schema(addon.options) except vol.Invalid as ex: - data["message"] = humanize_error(addon.options, ex) - data["valid"] = False + data[ATTR_MESSAGE] = humanize_error(addon.options, ex) + data[ATTR_VALID] = False return data diff --git a/supervisor/const.py b/supervisor/const.py index 90682825cc4..bc705ed1aff 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -195,6 +195,7 @@ 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_USER = "user" ATTR_USERNAME = "username" ATTR_UUID = "uuid" +ATTR_VALID = "valid" ATTR_VALUE = "value" ATTR_VERSION = "version" ATTR_VERSION_LATEST = "version_latest"