Skip to content

Commit

Permalink
fixing port definition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ShutdownRepo committed Sep 27, 2023
1 parent fe8df5a commit 3b9df15
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions exegol/model/ContainerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,20 +504,24 @@ def configureDesktop(self, desktop_config: str):
"""
self.__desktop_proto = UserConfig().desktop_default_proto
self.__desktop_host = "127.0.0.1" if UserConfig().desktop_default_localhost else "0.0.0.0"
_host_set_by_user = False

for i, data in enumerate(desktop_config.split(":")):
if not data:
continue
if i == 0:
if i == 0: # protocol
logger.debug(f"Desktop proto set: {data}")
data = data.lower()
if data in UserConfig.desktop_available_proto:
self.__desktop_proto = data
else:
logger.critical(f"The desktop mode '{data}' is not supported. Please choose a supported mode: [green]{', '.join(UserConfig.desktop_available_proto)}[/green].")
elif i == 1 and data:
elif i == 1 and data: # host
logger.debug(f"Desktop host set: {data}")
self.__desktop_host = data
self.__desktop_port = self.__findAvailableRandomPort(self.__desktop_host)
elif i == 2:
_host_set_by_user = True
elif i == 2: # port
logger.debug(f"Desktop port set: {data}")
try:
self.__desktop_port = int(data)
except ValueError:
Expand All @@ -526,7 +530,9 @@ def configureDesktop(self, desktop_config: str):
logger.critical(f"Your configuration is invalid, please use the following format:[green]mode:host:port[/green]")

if self.__desktop_port is None:
self.__desktop_port = self.__findAvailableRandomPort()
_desktop_host = self.__desktop_host if _host_set_by_user else None
logger.debug(f"Desktop port automatically set for host {_desktop_host}")
self.__desktop_port = self.__findAvailableRandomPort(_desktop_host)

def __disableDesktop(self):
"""Procedure to disable exegol desktop feature"""
Expand Down

0 comments on commit 3b9df15

Please sign in to comment.