mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
Fix secrets containing unsupported types (#1345)
* Fix secrets containing unsupported types * Black * Cleanup
This commit is contained in:
parent
7b8ad0782d
commit
05d7eff09a
@ -2,18 +2,15 @@
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from typing import Dict, Union
|
||||
|
||||
from ruamel.yaml import YAML, YAMLError
|
||||
import voluptuous as vol
|
||||
|
||||
from .coresys import CoreSys, CoreSysAttributes
|
||||
from .utils import AsyncThrottle
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
SECRETS_SCHEMA = vol.Schema({str: vol.Any(str, int, None, float)})
|
||||
|
||||
|
||||
class SecretsManager(CoreSysAttributes):
|
||||
"""Manage Home Assistant secrets."""
|
||||
@ -21,14 +18,14 @@ class SecretsManager(CoreSysAttributes):
|
||||
def __init__(self, coresys: CoreSys):
|
||||
"""Initialize secret manager."""
|
||||
self.coresys: CoreSys = coresys
|
||||
self.secrets: Dict[str, str] = {}
|
||||
self.secrets: Dict[str, Union[bool, float, int, str]] = {}
|
||||
|
||||
@property
|
||||
def path_secrets(self) -> Path:
|
||||
"""Return path to secret file."""
|
||||
return Path(self.sys_config.path_homeassistant, "secrets.yaml")
|
||||
|
||||
def get(self, secret: str) -> str:
|
||||
def get(self, secret: str) -> Union[bool, float, int, str]:
|
||||
"""Get secret from store."""
|
||||
_LOGGER.info("Request secret %s", secret)
|
||||
return self.secrets.get(secret)
|
||||
@ -55,10 +52,12 @@ class SecretsManager(CoreSysAttributes):
|
||||
yaml = YAML()
|
||||
data = await self.sys_run_in_executor(yaml.load, self.path_secrets) or {}
|
||||
|
||||
self.secrets = SECRETS_SCHEMA(data)
|
||||
# Filter to only get supported values
|
||||
self.secrets = {
|
||||
k: v for k, v in data.items() if isinstance(v, (bool, float, int, str))
|
||||
}
|
||||
|
||||
except YAMLError as err:
|
||||
_LOGGER.error("Can't process Home Assistant secrets: %s", err)
|
||||
except vol.Invalid:
|
||||
_LOGGER.warning("Home Assistant secrets have a invalid format")
|
||||
else:
|
||||
_LOGGER.debug("Reload Home Assistant secrets: %s", len(self.secrets))
|
||||
|
Loading…
x
Reference in New Issue
Block a user