1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 20:35:55 +00:00

Allow dynamic handling of proto part (#203)

* Allow dynamic handling of proto part

* Fix lint

* fix bug
This commit is contained in:
Pascal Vizeli
2017-10-01 00:03:06 +02:00
committed by GitHub
parent 79e2f3e8ab
commit 2998cd94ff
2 changed files with 23 additions and 9 deletions

View File

@@ -29,7 +29,9 @@ from ..tools import write_json_file, read_json_file
_LOGGER = logging.getLogger(__name__)
RE_WEBUI = re.compile(r"^(.*\[HOST\]:)\[PORT:(\d+)\](.*)$")
RE_WEBUI = re.compile(
r"^(?:(?P<s_prefix>https?)|\[PROTO:(?P<t_proto>\w+)\])"
r":\/\/\[HOST\]:\[PORT:(?P<t_port>\d+)\](?P<s_suffix>.*)$")
MERGE_OPT = Merger([(dict, ['merge'])], ['override'], ['override'])
@@ -207,19 +209,31 @@ class Addon(object):
"""Return URL to webui or None."""
if ATTR_WEBUI not in self._mesh:
return None
webui = RE_WEBUI.match(self._mesh[ATTR_WEBUI])
webui = self._mesh[ATTR_WEBUI]
dock_port = RE_WEBUI.sub(r"\2", webui)
# extract arguments
t_port = webui.group('t_port')
t_proto = webui.group('t_proto')
s_prefix = webui.group('s_prefix') or ""
s_suffix = webui.group('s_suffix') or ""
# search host port for this docker port
if self.ports is None:
real_port = dock_port
port = self.ports.get("{}/tcp".format(t_port), t_port)
else:
real_port = self.ports.get("{}/tcp".format(dock_port), dock_port)
port = t_port
# for interface config or port lists
if isinstance(real_port, (tuple, list)):
real_port = real_port[-1]
if isinstance(port, (tuple, list)):
port = port[-1]
return RE_WEBUI.sub(r"\g<1>{}\g<3>".format(real_port), webui)
# lookup the correct protocol from config
if t_proto:
proto = 'https' if self.options[t_proto] else 'http'
else:
proto = s_prefix
return "{}://[HOST]:{}{}".format(proto, port, s_suffix)
@property
def host_network(self):