Machine ID for user/sentry & cleanups (#1928)

* Machine ID for user/sentry & cleanups

* Add tests / fix users
This commit is contained in:
Pascal Vizeli 2020-08-15 18:26:20 +02:00 committed by GitHub
parent b6509dca1f
commit 94f112512f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 25 deletions

View File

@ -42,5 +42,5 @@ class APIInfo(CoreSysAttributes):
ATTR_SUPPORTED: self.sys_core.supported, ATTR_SUPPORTED: self.sys_core.supported,
ATTR_CHANNEL: self.sys_updater.channel, ATTR_CHANNEL: self.sys_updater.channel,
ATTR_LOGGING: self.sys_config.logging, ATTR_LOGGING: self.sys_config.logging,
ATTR_TIMEZONE: self.sys_timezone, ATTR_TIMEZONE: self.sys_config.timezone,
} }

View File

@ -131,8 +131,7 @@ class SecurityMiddleware(CoreSysAttributes):
request_from = self.sys_homeassistant request_from = self.sys_homeassistant
# Host # Host
# Remove machine_id handling later if all use new CLI if supervisor_token == self.sys_plugins.cli.supervisor_token:
if supervisor_token in (self.sys_machine_id, self.sys_plugins.cli.supervisor_token):
_LOGGER.debug("%s access from Host", request.path) _LOGGER.debug("%s access from Host", request.path)
request_from = self.sys_host request_from = self.sys_host

View File

@ -90,11 +90,6 @@ class CoreSys:
return False return False
return self._updater.channel == UpdateChannels.DEV return self._updater.channel == UpdateChannels.DEV
@property
def timezone(self) -> str:
"""Return timezone."""
return self._config.timezone
@property @property
def loop(self) -> asyncio.BaseEventLoop: def loop(self) -> asyncio.BaseEventLoop:
"""Return loop object.""" """Return loop object."""
@ -459,16 +454,6 @@ class CoreSysAttributes:
"""Return True if we run dev mode.""" """Return True if we run dev mode."""
return self.coresys.dev 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 @property
def sys_loop(self) -> asyncio.BaseEventLoop: def sys_loop(self) -> asyncio.BaseEventLoop:
"""Return loop object.""" """Return loop object."""

View File

@ -116,7 +116,7 @@ class DockerAddon(DockerInterface):
return { return {
**addon_env, **addon_env,
ENV_TIME: self.sys_timezone, ENV_TIME: self.sys_config.timezone,
ENV_TOKEN: self.addon.supervisor_token, ENV_TOKEN: self.addon.supervisor_token,
ENV_TOKEN_OLD: self.addon.supervisor_token, ENV_TOKEN_OLD: self.addon.supervisor_token,
} }

View File

@ -69,7 +69,7 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
hostname=self.name.replace("_", "-"), hostname=self.name.replace("_", "-"),
detach=True, detach=True,
privileged=True, privileged=True,
environment={ENV_TIME: self.sys_timezone}, environment={ENV_TIME: self.sys_config.timezone},
volumes=self.volumes, volumes=self.volumes,
) )

View File

@ -50,7 +50,7 @@ class DockerCli(DockerInterface, CoreSysAttributes):
detach=True, detach=True,
extra_hosts={"supervisor": self.sys_docker.network.supervisor}, extra_hosts={"supervisor": self.sys_docker.network.supervisor},
environment={ environment={
ENV_TIME: self.sys_timezone, ENV_TIME: self.sys_config.timezone,
ENV_TOKEN: self.sys_plugins.cli.supervisor_token, ENV_TOKEN: self.sys_plugins.cli.supervisor_token,
}, },
) )

View File

@ -47,7 +47,7 @@ class DockerDNS(DockerInterface, CoreSysAttributes):
name=self.name, name=self.name,
hostname=self.name.replace("_", "-"), hostname=self.name.replace("_", "-"),
detach=True, detach=True,
environment={ENV_TIME: self.sys_timezone}, environment={ENV_TIME: self.sys_config.timezone},
volumes={ volumes={
str(self.sys_config.path_extern_dns): {"bind": "/config", "mode": "ro"} str(self.sys_config.path_extern_dns): {"bind": "/config", "mode": "ro"}
}, },

View File

@ -115,7 +115,7 @@ class DockerHomeAssistant(DockerInterface):
environment={ environment={
"HASSIO": self.sys_docker.network.supervisor, "HASSIO": self.sys_docker.network.supervisor,
"SUPERVISOR": 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: self.sys_homeassistant.supervisor_token,
ENV_TOKEN_OLD: self.sys_homeassistant.supervisor_token, ENV_TOKEN_OLD: self.sys_homeassistant.supervisor_token,
}, },
@ -150,7 +150,7 @@ class DockerHomeAssistant(DockerInterface):
"mode": "ro", "mode": "ro",
}, },
}, },
environment={ENV_TIME: self.sys_timezone}, environment={ENV_TIME: self.sys_config.timezone},
) )
def is_initialize(self) -> Awaitable[bool]: def is_initialize(self) -> Awaitable[bool]:

View File

@ -47,7 +47,7 @@ class DockerMulticast(DockerInterface, CoreSysAttributes):
network_mode="host", network_mode="host",
detach=True, detach=True,
extra_hosts={"supervisor": self.sys_docker.network.supervisor}, 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 self._meta = docker_container.attrs

View File

@ -45,6 +45,7 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
] ]
# Update information # Update information
event.setdefault("user", {}).update({"id": coresys.machine_id})
event.setdefault("contexts", {}).update( event.setdefault("contexts", {}).update(
{ {
"supervisor": { "supervisor": {
@ -100,4 +101,5 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
if key in [hdrs.HOST, hdrs.X_FORWARDED_HOST]: if key in [hdrs.HOST, hdrs.X_FORWARDED_HOST]:
event["request"]["headers"][i] = [key, "example.com"] event["request"]["headers"][i] = [key, "example.com"]
return event return event

View File

@ -1,5 +1,6 @@
"""Common test functions.""" """Common test functions."""
from unittest.mock import MagicMock, PropertyMock, patch from unittest.mock import MagicMock, PropertyMock, patch
from uuid import uuid4
import pytest import pytest
@ -39,6 +40,9 @@ async def coresys(loop, docker):
coresys_obj.ingress.save_data = MagicMock() coresys_obj.ingress.save_data = MagicMock()
coresys_obj.arch._default_arch = "amd64" coresys_obj.arch._default_arch = "amd64"
coresys_obj._machine = "qemux86-64"
coresys_obj._machine_id = uuid4()
yield coresys_obj yield coresys_obj

View File

@ -59,7 +59,9 @@ def test_defaults(coresys):
assert ["installation_type", "supervised"] in filtered["tags"] assert ["installation_type", "supervised"] in filtered["tags"]
assert filtered["contexts"]["host"]["arch"] == "amd64" assert filtered["contexts"]["host"]["arch"] == "amd64"
assert filtered["contexts"]["host"]["machine"] == "qemux86-64"
assert filtered["contexts"]["versions"]["supervisor"] == SUPERVISOR_VERSION assert filtered["contexts"]["versions"]["supervisor"] == SUPERVISOR_VERSION
assert filtered["user"]["id"] == coresys.machine_id
def test_sanitize(coresys): def test_sanitize(coresys):