mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
commit
39cc8aaa13
@ -9,7 +9,6 @@ RUN apk add --no-cache \
|
||||
git \
|
||||
socat \
|
||||
glib \
|
||||
libstdc++ \
|
||||
eudev \
|
||||
eudev-libs
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
from pathlib import Path
|
||||
from ipaddress import ip_network
|
||||
|
||||
HASSIO_VERSION = "191"
|
||||
HASSIO_VERSION = "192"
|
||||
|
||||
|
||||
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
|
||||
|
@ -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)
|
||||
@ -53,12 +50,15 @@ class SecretsManager(CoreSysAttributes):
|
||||
# Read secrets
|
||||
try:
|
||||
yaml = YAML()
|
||||
yaml.allow_duplicate_keys = True
|
||||
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))
|
||||
|
@ -1,5 +1,5 @@
|
||||
flake8==3.7.8
|
||||
pylint==2.4.3
|
||||
pytest==5.2.1
|
||||
pytest==5.2.2
|
||||
pytest-timeout==1.3.3
|
||||
pytest-aiohttp==0.3.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user