mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 04:36:31 +00:00
Machine ID for user/sentry & cleanups (#1928)
* Machine ID for user/sentry & cleanups * Add tests / fix users
This commit is contained in:
parent
b6509dca1f
commit
94f112512f
@ -42,5 +42,5 @@ class APIInfo(CoreSysAttributes):
|
||||
ATTR_SUPPORTED: self.sys_core.supported,
|
||||
ATTR_CHANNEL: self.sys_updater.channel,
|
||||
ATTR_LOGGING: self.sys_config.logging,
|
||||
ATTR_TIMEZONE: self.sys_timezone,
|
||||
ATTR_TIMEZONE: self.sys_config.timezone,
|
||||
}
|
||||
|
@ -131,8 +131,7 @@ class SecurityMiddleware(CoreSysAttributes):
|
||||
request_from = self.sys_homeassistant
|
||||
|
||||
# Host
|
||||
# Remove machine_id handling later if all use new CLI
|
||||
if supervisor_token in (self.sys_machine_id, self.sys_plugins.cli.supervisor_token):
|
||||
if supervisor_token == self.sys_plugins.cli.supervisor_token:
|
||||
_LOGGER.debug("%s access from Host", request.path)
|
||||
request_from = self.sys_host
|
||||
|
||||
|
@ -90,11 +90,6 @@ class CoreSys:
|
||||
return False
|
||||
return self._updater.channel == UpdateChannels.DEV
|
||||
|
||||
@property
|
||||
def timezone(self) -> str:
|
||||
"""Return timezone."""
|
||||
return self._config.timezone
|
||||
|
||||
@property
|
||||
def loop(self) -> asyncio.BaseEventLoop:
|
||||
"""Return loop object."""
|
||||
@ -459,16 +454,6 @@ class CoreSysAttributes:
|
||||
"""Return True if we run dev mode."""
|
||||
return self.coresys.dev
|
||||
|
||||
@property
|
||||
def sys_timezone(self) -> str:
|
||||
"""Return timezone."""
|
||||
return self.coresys.timezone
|
||||
|
||||
@property
|
||||
def sys_machine_id(self) -> Optional[str]:
|
||||
"""Return timezone."""
|
||||
return self.coresys.machine_id
|
||||
|
||||
@property
|
||||
def sys_loop(self) -> asyncio.BaseEventLoop:
|
||||
"""Return loop object."""
|
||||
|
@ -116,7 +116,7 @@ class DockerAddon(DockerInterface):
|
||||
|
||||
return {
|
||||
**addon_env,
|
||||
ENV_TIME: self.sys_timezone,
|
||||
ENV_TIME: self.sys_config.timezone,
|
||||
ENV_TOKEN: self.addon.supervisor_token,
|
||||
ENV_TOKEN_OLD: self.addon.supervisor_token,
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
|
||||
hostname=self.name.replace("_", "-"),
|
||||
detach=True,
|
||||
privileged=True,
|
||||
environment={ENV_TIME: self.sys_timezone},
|
||||
environment={ENV_TIME: self.sys_config.timezone},
|
||||
volumes=self.volumes,
|
||||
)
|
||||
|
||||
|
@ -50,7 +50,7 @@ class DockerCli(DockerInterface, CoreSysAttributes):
|
||||
detach=True,
|
||||
extra_hosts={"supervisor": self.sys_docker.network.supervisor},
|
||||
environment={
|
||||
ENV_TIME: self.sys_timezone,
|
||||
ENV_TIME: self.sys_config.timezone,
|
||||
ENV_TOKEN: self.sys_plugins.cli.supervisor_token,
|
||||
},
|
||||
)
|
||||
|
@ -47,7 +47,7 @@ class DockerDNS(DockerInterface, CoreSysAttributes):
|
||||
name=self.name,
|
||||
hostname=self.name.replace("_", "-"),
|
||||
detach=True,
|
||||
environment={ENV_TIME: self.sys_timezone},
|
||||
environment={ENV_TIME: self.sys_config.timezone},
|
||||
volumes={
|
||||
str(self.sys_config.path_extern_dns): {"bind": "/config", "mode": "ro"}
|
||||
},
|
||||
|
@ -115,7 +115,7 @@ class DockerHomeAssistant(DockerInterface):
|
||||
environment={
|
||||
"HASSIO": self.sys_docker.network.supervisor,
|
||||
"SUPERVISOR": self.sys_docker.network.supervisor,
|
||||
ENV_TIME: self.sys_timezone,
|
||||
ENV_TIME: self.sys_config.timezone,
|
||||
ENV_TOKEN: self.sys_homeassistant.supervisor_token,
|
||||
ENV_TOKEN_OLD: self.sys_homeassistant.supervisor_token,
|
||||
},
|
||||
@ -150,7 +150,7 @@ class DockerHomeAssistant(DockerInterface):
|
||||
"mode": "ro",
|
||||
},
|
||||
},
|
||||
environment={ENV_TIME: self.sys_timezone},
|
||||
environment={ENV_TIME: self.sys_config.timezone},
|
||||
)
|
||||
|
||||
def is_initialize(self) -> Awaitable[bool]:
|
||||
|
@ -47,7 +47,7 @@ class DockerMulticast(DockerInterface, CoreSysAttributes):
|
||||
network_mode="host",
|
||||
detach=True,
|
||||
extra_hosts={"supervisor": self.sys_docker.network.supervisor},
|
||||
environment={ENV_TIME: self.sys_timezone},
|
||||
environment={ENV_TIME: self.sys_config.timezone},
|
||||
)
|
||||
|
||||
self._meta = docker_container.attrs
|
||||
|
@ -45,6 +45,7 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
|
||||
]
|
||||
|
||||
# Update information
|
||||
event.setdefault("user", {}).update({"id": coresys.machine_id})
|
||||
event.setdefault("contexts", {}).update(
|
||||
{
|
||||
"supervisor": {
|
||||
@ -100,4 +101,5 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
|
||||
|
||||
if key in [hdrs.HOST, hdrs.X_FORWARDED_HOST]:
|
||||
event["request"]["headers"][i] = [key, "example.com"]
|
||||
|
||||
return event
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Common test functions."""
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
@ -39,6 +40,9 @@ async def coresys(loop, docker):
|
||||
coresys_obj.ingress.save_data = MagicMock()
|
||||
coresys_obj.arch._default_arch = "amd64"
|
||||
|
||||
coresys_obj._machine = "qemux86-64"
|
||||
coresys_obj._machine_id = uuid4()
|
||||
|
||||
yield coresys_obj
|
||||
|
||||
|
||||
|
@ -59,7 +59,9 @@ def test_defaults(coresys):
|
||||
|
||||
assert ["installation_type", "supervised"] in filtered["tags"]
|
||||
assert filtered["contexts"]["host"]["arch"] == "amd64"
|
||||
assert filtered["contexts"]["host"]["machine"] == "qemux86-64"
|
||||
assert filtered["contexts"]["versions"]["supervisor"] == SUPERVISOR_VERSION
|
||||
assert filtered["user"]["id"] == coresys.machine_id
|
||||
|
||||
|
||||
def test_sanitize(coresys):
|
||||
|
Loading…
x
Reference in New Issue
Block a user