diff --git a/music_assistant/common/models/config_entries.py b/music_assistant/common/models/config_entries.py index bc31c76c9..a9428a91b 100644 --- a/music_assistant/common/models/config_entries.py +++ b/music_assistant/common/models/config_entries.py @@ -170,10 +170,10 @@ def parse_value( self.key, type(self.value), ) - self.value = self.default_value - return self.value - msg = f"{self.key} has unexpected type: {type(value)}" - raise ValueError(msg) + value = self.default_value + if not (value is None and allow_none): + msg = f"{self.key} has unexpected type: {type(value)}" + raise ValueError(msg) self.value = value return self.value diff --git a/music_assistant/server/controllers/config.py b/music_assistant/server/controllers/config.py index eb55be863..798a19ec5 100644 --- a/music_assistant/server/controllers/config.py +++ b/music_assistant/server/controllers/config.py @@ -35,7 +35,6 @@ CONF_SERVER_ID, CONFIGURABLE_CORE_CONTROLLERS, ENCRYPT_SUFFIX, - SECURE_STRING_SUBSTITUTE, ) from music_assistant.server.helpers.api import api_command from music_assistant.server.helpers.util import load_provider_module @@ -241,15 +240,6 @@ async def get_provider_config_entries( if values is None: values = self.get(f"{CONF_PROVIDERS}/{instance_id}/values", {}) if instance_id else {} - # handle (edge) case where encrypted values are passed along - for key, value in values.items(): - if not isinstance(value, str): - continue - if value == SECURE_STRING_SUBSTITUTE: - values[key] = value = self.get(f"{CONF_PROVIDERS}/{instance_id}/values/{key}", None) # noqa: PLW2901 - if value.startswith(ENCRYPT_SUFFIX): - values[key] = self.decrypt_string(value) - return ( await prov_mod.get_config_entries( self.mass, instance_id=instance_id, action=action, values=values @@ -315,7 +305,7 @@ async def set_provider_config_value( ) -> None: """Set single ProviderConfig value.""" config = await self.get_provider_config(instance_id) - config.update({**config.to_raw(), key: value}) + config.update({key: value}) config.validate() conf_key = f"{CONF_PROVIDERS}/{config.instance_id}" self.set(conf_key, config.to_raw()) @@ -692,9 +682,8 @@ def decrypt_string(self, encrypted_str: str) -> str: return encrypted_str if not encrypted_str.startswith(ENCRYPT_SUFFIX): return encrypted_str - encrypted_str = encrypted_str.replace(ENCRYPT_SUFFIX, "") try: - return self._fernet.decrypt(encrypted_str.encode()).decode() + return self._fernet.decrypt(encrypted_str.replace(ENCRYPT_SUFFIX, "").encode()).decode() except InvalidToken as err: msg = "Password decryption failed" raise InvalidDataError(msg) from err @@ -758,7 +747,8 @@ async def _update_provider_config( # save the config first to prevent issues when the # provider wants to manipulate the config during load conf_key = f"{CONF_PROVIDERS}/{config.instance_id}" - self.set(conf_key, config.to_raw()) + raw_conf = config.to_raw() + self.set(conf_key, raw_conf) if config.enabled: await self._load_provider_config(config) else: diff --git a/music_assistant/server/providers/spotify/__init__.py b/music_assistant/server/providers/spotify/__init__.py index 852791a6d..794df518a 100644 --- a/music_assistant/server/providers/spotify/__init__.py +++ b/music_assistant/server/providers/spotify/__init__.py @@ -174,6 +174,8 @@ async def get_config_entries( auth_required = values.get(CONF_REFRESH_TOKEN) is None if auth_required: + values[CONF_CLIENT_ID] = None + values[CONF_ACCESS_TOKEN] = None label_text = ( "You need to authenticate to Spotify. Click the authenticate button below " "to start the authentication process which will open in a new (popup window), "