mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 13:46:31 +00:00
Support host tokens (#507)
* Update coresys.py * Update bootstrap.py * Update security.py * fix lint * Update bootstrap.py
This commit is contained in:
parent
baa61c6aa0
commit
aea31ee6dd
@ -44,13 +44,18 @@ class SecurityMiddleware(CoreSysAttributes):
|
|||||||
if hassio_token == self.sys_homeassistant.uuid:
|
if hassio_token == self.sys_homeassistant.uuid:
|
||||||
_LOGGER.debug("%s access from Home-Assistant", request.path)
|
_LOGGER.debug("%s access from Home-Assistant", request.path)
|
||||||
request[REQUEST_FROM] = 'homeassistant'
|
request[REQUEST_FROM] = 'homeassistant'
|
||||||
return await handler(request)
|
|
||||||
|
# Host
|
||||||
|
if hassio_token == self.sys_machine_id:
|
||||||
|
_LOGGER.debug("%s access from Host", request.path)
|
||||||
|
request[REQUEST_FROM] = 'host'
|
||||||
|
|
||||||
# Add-on
|
# Add-on
|
||||||
addon = self.sys_addons.from_uuid(hassio_token)
|
addon = self.sys_addons.from_uuid(hassio_token)
|
||||||
if addon:
|
if addon:
|
||||||
_LOGGER.info("%s access from %s", request.path, addon.slug)
|
_LOGGER.info("%s access from %s", request.path, addon.slug)
|
||||||
request[REQUEST_FROM] = addon.slug
|
request[REQUEST_FROM] = addon.slug
|
||||||
return await handler(request)
|
|
||||||
|
|
||||||
raise HTTPUnauthorized()
|
if not request.get(REQUEST_FROM):
|
||||||
|
raise HTTPUnauthorized()
|
||||||
|
return await handler(request)
|
||||||
|
@ -24,6 +24,11 @@ from .dbus import DBusManager
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ENV_SHARE = 'SUPERVISOR_SHARE'
|
||||||
|
ENV_NAME = 'SUPERVISOR_NAME'
|
||||||
|
ENV_REPO = 'HOMEASSISTANT_REPOSITORY'
|
||||||
|
ENV_MACHINE = 'MACHINE_ID'
|
||||||
|
|
||||||
|
|
||||||
def initialize_coresys(loop):
|
def initialize_coresys(loop):
|
||||||
"""Initialize HassIO coresys/objects."""
|
"""Initialize HassIO coresys/objects."""
|
||||||
@ -46,6 +51,9 @@ def initialize_coresys(loop):
|
|||||||
# bootstrap config
|
# bootstrap config
|
||||||
initialize_system_data(coresys)
|
initialize_system_data(coresys)
|
||||||
|
|
||||||
|
# Set Machine/Host ID
|
||||||
|
coresys.machine_id = os.environ.get(ENV_MACHINE)
|
||||||
|
|
||||||
return coresys
|
return coresys
|
||||||
|
|
||||||
|
|
||||||
@ -139,8 +147,7 @@ def initialize_logging():
|
|||||||
def check_environment():
|
def check_environment():
|
||||||
"""Check if all environment are exists."""
|
"""Check if all environment are exists."""
|
||||||
# check environment variables
|
# check environment variables
|
||||||
for key in ('SUPERVISOR_SHARE', 'SUPERVISOR_NAME',
|
for key in (ENV_SHARE, ENV_NAME, ENV_REPO):
|
||||||
'HOMEASSISTANT_REPOSITORY'):
|
|
||||||
try:
|
try:
|
||||||
os.environ[key]
|
os.environ[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -17,6 +17,7 @@ class CoreSys:
|
|||||||
"""Initialize coresys."""
|
"""Initialize coresys."""
|
||||||
# Static attributes
|
# Static attributes
|
||||||
self.exit_code = 0
|
self.exit_code = 0
|
||||||
|
self.machine_id = None
|
||||||
|
|
||||||
# External objects
|
# External objects
|
||||||
self._loop = loop
|
self._loop = loop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user