From 75d24ba5347d73b7c9ec8f8dce0f1b702e23a7f0 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sat, 30 Jun 2018 22:03:21 +0200 Subject: [PATCH 1/3] Bump version to 111 --- hassio/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/const.py b/hassio/const.py index 5e1925c2a..e85167484 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -2,7 +2,7 @@ from pathlib import Path from ipaddress import ip_network -HASSIO_VERSION = '110' +HASSIO_VERSION = '111' URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons" URL_HASSIO_VERSION = \ From 44ae9c7b63ae374054113d2413ab3ca33192c2b0 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sat, 30 Jun 2018 22:06:18 +0200 Subject: [PATCH 2/3] Don't try to shutdown a not running API (#543) --- hassio/api/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hassio/api/__init__.py b/hassio/api/__init__.py index 9144cda84..70dbac711 100644 --- a/hassio/api/__init__.py +++ b/hassio/api/__init__.py @@ -243,5 +243,9 @@ class RestAPI(CoreSysAttributes): async def stop(self): """Stop rest api webserver.""" + if not self._site: + return + + # Shutdown running API await self._site.stop() await self._runner.cleanup() From 806161e3ac08211ac693cff807e31aacf9e42608 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sun, 1 Jul 2018 22:28:32 +0200 Subject: [PATCH 3/3] Use machine-id from filesystem (#546) * Use machine-id from filesystem * Update security.py * Update security.py * fix lint --- hassio/api/security.py | 16 +++++++--------- hassio/bootstrap.py | 6 ++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hassio/api/security.py b/hassio/api/security.py index 69888786b..2ecb67daa 100644 --- a/hassio/api/security.py +++ b/hassio/api/security.py @@ -35,11 +35,6 @@ class SecurityMiddleware(CoreSysAttributes): _LOGGER.debug("Passthrough %s", request.path) return await handler(request) - # Unknown API access - if not hassio_token: - _LOGGER.warning("Invalid token for access %s", request.path) - raise HTTPUnauthorized() - # Home-Assistant if hassio_token == self.sys_homeassistant.uuid: _LOGGER.debug("%s access from Home-Assistant", request.path) @@ -51,11 +46,14 @@ class SecurityMiddleware(CoreSysAttributes): request[REQUEST_FROM] = 'host' # Add-on - addon = self.sys_addons.from_uuid(hassio_token) + addon = self.sys_addons.from_uuid(hassio_token) \ + if hassio_token else None if addon: _LOGGER.info("%s access from %s", request.path, addon.slug) request[REQUEST_FROM] = addon.slug - if not request.get(REQUEST_FROM): - raise HTTPUnauthorized() - return await handler(request) + if request.get(REQUEST_FROM): + return await handler(request) + + _LOGGER.warning("Invalid token for access %s", request.path) + raise HTTPUnauthorized() diff --git a/hassio/bootstrap.py b/hassio/bootstrap.py index 4bc718aea..1d661f752 100644 --- a/hassio/bootstrap.py +++ b/hassio/bootstrap.py @@ -28,7 +28,8 @@ _LOGGER = logging.getLogger(__name__) ENV_SHARE = 'SUPERVISOR_SHARE' ENV_NAME = 'SUPERVISOR_NAME' ENV_REPO = 'HOMEASSISTANT_REPOSITORY' -ENV_MACHINE = 'MACHINE_ID' + +MACHINE_ID = Path('/etc/machine-id') def initialize_coresys(loop): @@ -54,7 +55,8 @@ def initialize_coresys(loop): initialize_system_data(coresys) # Set Machine/Host ID - coresys.machine_id = os.environ.get(ENV_MACHINE) + if MACHINE_ID.exists(): + coresys.machine_id = MACHINE_ID.read_text().strip() return coresys