From 8aa75b069b00240b10e5e5b20a011b57310581a4 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 9 Nov 2021 09:26:33 +0100 Subject: [PATCH] Use different endpoint for add-on options (#88) --- lib/addons.sh | 24 ++++++++++++++++++++++++ lib/config.sh | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/addons.sh b/lib/addons.sh index bb8b499..562b56f 100644 --- a/lib/addons.sh +++ b/lib/addons.sh @@ -544,6 +544,30 @@ function bashio::addon.option() { bashio::cache.flush_all } +# ------------------------------------------------------------------------------ +# Returns a JSON object with add-on specific config for the addon itself. +# +# This can be only used by self. +# ------------------------------------------------------------------------------ +function bashio::addon.config() { + local cache_key="addons.self.options.config" + local response + + bashio::log.trace "${FUNCNAME[0]}" "$@" + + if bashio::cache.exists "${cache_key}"; then + bashio::cache.get "${cache_key}" + return "${__BASHIO_EXIT_OK}" + fi + + response=$(bashio::api.supervisor GET "/addons/self/options/config" false) + + bashio::cache.set "${cache_key}" "${response}" + printf "%s" "${response}" + + return "${__BASHIO_EXIT_OK}" +} + # ------------------------------------------------------------------------------ # Returns a list of ports which are exposed on the host network for this add-on. # diff --git a/lib/config.sh b/lib/config.sh index df32374..6242e5e 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -45,7 +45,7 @@ function bashio::config() { end QUERY - options=$(bashio::addon.options) + options=$(bashio::addon.config) result=$(bashio::jq "${options}" "${query}") if [[ "${result}" == "null" ]] && bashio::var.has_value "${default_value}";