Skip to content

Commit

Permalink
handle more edge case drama
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 16, 2024
1 parent ece29b1 commit 377a913
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion music_assistant/server/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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
Expand Down Expand Up @@ -239,6 +240,16 @@ async def get_provider_config_entries(
raise KeyError(msg)
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
Expand Down Expand Up @@ -304,7 +315,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}/{instance_id}/values/{key}"
self.set(conf_key, config.get_value(key))
Expand Down

0 comments on commit 377a913

Please sign in to comment.