aboutsummaryrefslogtreecommitdiff
path: root/rwa/support
diff options
context:
space:
mode:
Diffstat (limited to 'rwa/support')
-rwxr-xr-xrwa/support/sessionservice/service.py141
-rw-r--r--rwa/support/sessionservice/session.py12
2 files changed, 78 insertions, 75 deletions
diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py
index 588e531..7bb45b2 100755
--- a/rwa/support/sessionservice/service.py
+++ b/rwa/support/sessionservice/service.py
@@ -104,14 +104,17 @@ class RWASupportSessionService(dbus.service.Object):
Helper function: No D-Bus API.
"""
+
+ logging.debug("Raw web_app_hosts: %s", self.settings.web_app_hosts.items())
hosts = [
self._build_host_dict(key, value) for key, value in self.settings.web_app_hosts.items()
]
return json.dumps(hosts)
- def _build_host_dict(self, host_id: str, host: dict) -> dict:
+ def _build_host_dict(self, host_uuid: str, host: dict) -> dict:
"""Include the host ID in the host dictionary."""
- return host.update({"id": host_id})
+ host.update({'uuid': host_uuid})
+ return host
@dbus.service.method("org.ArcticaProject.RWASupportSessionService", out_signature="s")
def get_web_app_hosts(self) -> str:
@@ -123,12 +126,12 @@ class RWASupportSessionService(dbus.service.Object):
::
- [{"id": <host_id>, "https://example.org"}, {"id": <host_id>, "http://127.0.0.1:8000"}]
+ [{"id": <host_uuid>, "https://example.org"}, {"id": <host_uuid>, "http://127.0.0.1:8000"}]
"""
logging.info("D-Bus method call: %s()", "get_web_app_hosts")
response = self._get_web_app_hosts()
- logging.debug('The response to D-Bus caller: "%s"', response)
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
def _do_api_handshake(self, host: str) -> Dict[str, str]:
@@ -183,17 +186,17 @@ class RWASupportSessionService(dbus.service.Object):
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="s", out_signature="s"
)
- def add_web_app_host(self, host: str) -> str:
+ def add_web_app_host(self, host_url: str) -> str:
"""Add a RWA.Support.WebApp host.
- :param host: Exact hostname of the RWA.Support.WebApp host (D-Bus string)
- :return: The registered host as JSOn object (D-Bus string)
+ :param host_url: Exact hostname of the RWA.Support.WebApp host (D-Bus string)
+ :return: The registered host as JSON object (D-Bus string)
**Structure of returned JSON (success):**
::
- {"id": <host_id>, "http://127.0.0.1:8000"}
+ {"id": <host_uuid>, "http://127.0.0.1:8000"}
**Structure of returned JSON (error):**
@@ -209,87 +212,87 @@ class RWASupportSessionService(dbus.service.Object):
* ``invalid_url``
* ``duplicate``
"""
- host = str(host).rstrip("/")
+ host_url = str(host_url).rstrip("/")
- logging.info('D-Bus method call: %s("%s")', "add_web_app_host", host)
+ logging.info('D-Bus method call: %s("%s")', "add_web_app_host", host_url)
- if not self._is_url(host):
+ if not self._is_url(host_url):
logging.warning("Given URL is not valid!")
- logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host)
+ logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url)
response = json.dumps({"status": "error", "type": "invalid_url"})
- logging.debug('The response to D-Bus caller: "%s"', response)
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
- if host in self.settings.web_app_hosts:
+ if host_url in self.settings.web_app_hosts:
logging.warning("Given URL is already present!")
- logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host)
+ logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url)
response = json.dumps({"status": "error", "type": "duplicate"})
- logging.debug('The response to D-Bus caller: "%s"', response)
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
- res = self._do_api_handshake(host)
+ res = self._do_api_handshake(host_url)
if res["status"] == "error":
- logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host)
+ logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url)
response = json.dumps(res)
- logging.debug('The response to D-Bus caller: "%s"', response)
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
- host_id = str(uuid4())
- host_object = {"url": host}
+ host_uuid = str(uuid4())
+ host_object = {"url": host_url}
- self.settings.web_app_hosts[host_id] = host_object
+ self.settings.web_app_hosts[host_uuid] = host_object
self.settings.save_settings()
- logging.info('Added "%s" to "web_app_hosts" in user_settings', host)
+ logging.info('Added "%s" to "web_app_hosts" in user_settings', host_url)
- response = json.dumps(self._build_host_dict(host_id, host_object))
- logging.debug('The response to D-Bus caller: "%s"', response)
+ response = json.dumps(self._build_host_dict(host_uuid, host_object))
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s"
)
- def remove_web_app_host(self, host_id: str) -> str:
+ def remove_web_app_host(self, host_uuid: str) -> str:
"""Remove a RWA.Support.WebApp host.
- :param host_id: ID of web app host (D-Bus string)
+ :param host_uuid: ID of web app host (D-Bus string)
:return: All registered hosts as JSON array (D-Bus string)
**Structure of returned JSON:**
::
- [{"id": <host_id>, "https://example.org"}, {"id": <host_id>, "http://127.0.0.1:8000"}]
+ [{"id": <host_uuid>, "https://example.org"}, {"id": <host_uuid>, "http://127.0.0.1:8000"}]
"""
- logging.info("D-Bus method call: %s(%s)", "remove_web_app_host", host_id)
+ logging.info("D-Bus method call: %s(%s)", "remove_web_app_host", host_uuid)
- if host_id in self.settings.web_app_hosts:
- host_object = self.settings.web_app_hosts[host_id]
- del self.settings.web_app_hosts[host_id]
+ if host_uuid in self.settings.web_app_hosts:
+ host_object = self.settings.web_app_hosts[host_uuid]
+ del self.settings.web_app_hosts[host_uuid]
self.settings.save_settings()
- logging.info('Removed web_app_hosts[%s]="%s" in user settings', host_id, host_object)
+ logging.info('Removed web_app_hosts[%s]="%s" in user settings', host_uuid, host_object)
else:
logging.warning("Given host index is not valid!")
logging.debug(
"Did not remove web_app_hosts[%s]"
- "(not existent!) in " "user settings", host_id
+ "(not existent!) in " "user settings", host_uuid
)
return json.dumps({"status": "error", "type": "host_not_found"})
response = self._get_web_app_hosts()
- logging.debug('The response to D-Bus caller: "%s"', response)
+ logging.info('The response to D-Bus caller: "%s"', response)
return response
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s"
)
- def start(self, host_id: str) -> str:
+ def start(self, host_uuid: str) -> str:
"""Start a new remote session and register it in RWA.Support.WebApp.
- :param host_id: ID of web app host (D-Bus string)
+ :param host_uuid: ID of web app host (D-Bus string)
:return: Result as JSON (D-Bus string)
**Structure of returned JSON (success):**
@@ -298,7 +301,7 @@ class RWASupportSessionService(dbus.service.Object):
{
"status": "success",
- "host_id": "<host_id>",
+ "host_uuid": "<host_uuid>",
"session_id": <session_id>,
"url": "<url>",
"pin": <pin>
@@ -318,7 +321,7 @@ class RWASupportSessionService(dbus.service.Object):
* ``permission_denied``
* ``unsupported_server``
"""
- logging.info("D-Bus method call: %s(%s)", "start", host_id)
+ logging.info("D-Bus method call: %s(%s)", "start", host_uuid)
if ALLOW_ONLY_ONE_SESSION and len(self.sessions.values()) > 0:
logging.warning(
@@ -331,11 +334,11 @@ class RWASupportSessionService(dbus.service.Object):
return response
try:
- host_object = self.settings.web_app_hosts[host_id]
- host_object = self._build_host_dict(host_id, host_object)
- logging.debug('web_app_hosts[%s] is the following host: "%s"', host_id, host_object)
+ host_object = self.settings.web_app_hosts[host_uuid]
+ host_object = self._build_host_dict(host_uuid, host_object)
+ logging.debug('web_app_hosts[%s] is the following host: "%s"', host_uuid, host_object)
except (KeyError, IndexError):
- logging.error("web_app_hosts[%s] does not exist!", host_id)
+ logging.error("web_app_hosts[%s] does not exist!", host_uuid)
response = json.dumps({"status": "error", "type": "host_not_found"})
logging.info("The response to the D-Bus caller: '%s'", response)
return response
@@ -376,14 +379,14 @@ class RWASupportSessionService(dbus.service.Object):
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="si", out_signature="s"
)
- def status(self, host_id: str, session_id: int) -> str:
+ def status(self, host_uuid: str, session_id: int) -> str:
"""Return the status of a session.
.. note::
This uses the last status version got by the update service in the background.
- :param host_id: Host ID (D-Bus string)
+ :param host_uuid: Host ID (D-Bus string)
:param session_id: Session ID (D-Bus integer)
:return: Session status as JSON (D-Bus string)
@@ -392,7 +395,7 @@ class RWASupportSessionService(dbus.service.Object):
::
- {"host_id": "<host_id>", "session_id": <session_id>, "status": <status>}
+ {"host_uuid": "<host_uuid>", "session_id": <session_id>, "status": <status>}
**Possible status options:**
@@ -403,30 +406,30 @@ class RWASupportSessionService(dbus.service.Object):
``dead`` There was a problem, so that the session is dead.
============ ======================
"""
- logging.info("D-Bus method call: %s(%s, %d)", "status", host_id, session_id)
- response = self._get_status(host_id, session_id)
+ logging.info("D-Bus method call: %s(%s, %d)", "status", host_uuid, session_id)
+ response = self._get_status(host_uuid, session_id)
logging.info("The response to the D-Bus caller: '%s'", response)
return response
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="si", out_signature="s"
)
- def refresh_status(self, host_id: str, session_id: int) -> str:
+ def refresh_status(self, host_uuid: str, session_id: int) -> str:
"""Update status from WebApp before returning it here like :meth:`status`."""
- logging.info("D-Bus method call: %s(%s, %d)", "refresh_status", host_id, session_id)
+ logging.info("D-Bus method call: %s(%s, %d)", "refresh_status", host_uuid, session_id)
- self._update_session(host_id, session_id)
- response = self._get_status(host_id, session_id)
+ self._update_session(host_uuid, session_id)
+ response = self._get_status(host_uuid, session_id)
logging.info("The response to the D-Bus caller: '%s'", response)
return response
@dbus.service.method(
"org.ArcticaProject.RWASupportSessionService", in_signature="si", out_signature="s"
)
- def stop(self, host_id: str, session_id: int) -> str:
+ def stop(self, host_uuid: str, session_id: int) -> str:
"""Stop a remote session.
- :param host_id: Host ID (D-Bus string)
+ :param host_uuid: Host ID (D-Bus string)
:param session_id: Session ID (D-Bus integer)
:return: Session status as JSON (D-Bus string)
@@ -434,35 +437,35 @@ class RWASupportSessionService(dbus.service.Object):
::
- {"host_id": "<host_id>", "session_id": <session_id>, "status": "stopped"}
+ {"host_uuid": "<host_uuid>", "session_id": <session_id>, "status": "stopped"}
"""
- logging.info("D-Bus method call: %s(%s, %d)", "stop", host_id, session_id)
+ logging.info("D-Bus method call: %s(%s, %d)", "stop", host_uuid, session_id)
- combined_id = combine(host_id, session_id)
+ combined_id = combine(host_uuid, session_id)
try:
session = self.sessions[combined_id]
except KeyError:
logging.debug("D-Bus method stop(): sessions[%s] does not exist.", combined_id)
response = json.dumps(
- {"host_id": host_id, "session_id": session_id, "status": "stopped"}, sort_keys=True
+ {"host_uuid": host_uuid, "session_id": session_id, "status": "stopped"}, sort_keys=True
)
logging.info("The response to the D-Bus caller: '%s'", response)
return response
session.stop()
response = json.dumps(
- {"host_id": host_id, "session_id": session_id, "status": "stopped"}, sort_keys=True
+ {"host_uuid": host_uuid, "session_id": session_id, "status": "stopped"}, sort_keys=True
)
logging.info("The response to the D-Bus caller: '%s'", response)
return response
- def _get_status(self, host_id: str, session_id: int) -> str:
- combined_id = combine(host_id, session_id)
+ def _get_status(self, host_uuid: str, session_id: int) -> str:
+ combined_id = combine(host_uuid, session_id)
try:
session = self.sessions[combined_id]
except KeyError:
logging.debug("_get_status(): self.sessions[%s] does not exist.", combined_id)
return json.dumps(
- {"host_id": host_id, "session_id": session_id, "status": "dead"}, sort_keys=True
+ {"host_uuid": host_uuid, "session_id": session_id, "status": "dead"}, sort_keys=True
)
return json.dumps(session.status)
@@ -472,13 +475,13 @@ class RWASupportSessionService(dbus.service.Object):
self.update_thread = Thread(target=self._update_sessions)
self.update_thread.start()
- def _update_session(self, host_id: str, session_id: int):
+ def _update_session(self, host_uuid: str, session_id: int):
"""Update the status of a session."""
- combined_id = combine(host_id, session_id)
+ combined_id = combine(host_uuid, session_id)
try:
session = self.sessions[combined_id]
except KeyError:
- logging.info(f"Update status for session #{session_id} on host {host_id} …")
+ logging.info(f"Update status for session #{session_id} on host {host_uuid} …")
logging.warning("Session %s is dead.", combined_id)
return
@@ -487,12 +490,12 @@ class RWASupportSessionService(dbus.service.Object):
if running:
pass
elif session.status_text == "stopped" and session.pid in self.sessions:
- logging.info(f"Update status for session #{session_id} on host {host_id} …")
+ logging.info(f"Update status for session #{session_id} on host {host_uuid} …")
logging.warning("Session %s is dead.", combined_id)
del self.sessions[combined_id]
else:
- logging.info(f"Update status for session #{session_id} on host {host_id} …")
+ logging.info(f"Update status for session #{session_id} on host {host_uuid} …")
logging.warning("VNC was stopped, so session %s is dead.", session.combined_id)
session.stop()
@@ -503,7 +506,7 @@ class RWASupportSessionService(dbus.service.Object):
logging.info("Started update service for sessions.")
while len(self.sessions.values()) > 0:
for session in list(self.sessions.values()):
- self._update_session(session.host_id, session.session_id)
+ self._update_session(session.host_uuid, session.session_id)
time.sleep(2)
@@ -520,7 +523,7 @@ class RWASupportSessionService(dbus.service.Object):
if session.session_id == session_id:
r = session.trigger(data, method)
logging.info(
- f"Found matching session #{session.session_id} on host {session.host_id}: {r}"
+ f"Found matching session #{session.session_id} on host {session.host_uuid}: {r}"
)
return r
diff --git a/rwa/support/sessionservice/session.py b/rwa/support/sessionservice/session.py
index 53bde2d..d3aa57c 100644
--- a/rwa/support/sessionservice/session.py
+++ b/rwa/support/sessionservice/session.py
@@ -51,8 +51,8 @@ def get_desktop_dir():
return output.strip().replace("\n", "")
-def combine(host_id: str, session_id: int):
- return f"{host_id}-{session_id}"
+def combine(host_uuid: str, session_id: int):
+ return f"{host_uuid}-{session_id}"
class Session:
@@ -65,7 +65,7 @@ class Session:
def __init__(self, host_object: dict, trigger_port: int, mockup_session: bool = False):
self.host_object = host_object
self.host_url = self.host_object["url"]
- self.host_id = self.host_object["id"]
+ self.host_uuid = self.host_object["id"]
self.BASE_URL = self.host_url + API_PATH
self.REGISTER_URL = self.BASE_URL + "register/"
self.STOP_URL = self.BASE_URL + "stop/"
@@ -86,7 +86,7 @@ class Session:
@property
def combined_id(self):
- return combine(self.host_id, self.session_id)
+ return combine(self.host_uuid, self.session_id)
@property
def pid(self) -> int:
@@ -307,7 +307,7 @@ class Session:
@property
def client_meta(self) -> Dict[str, Union[str, int]]:
return {
- "host_id": self.host_id,
+ "host_uuid": self.host_uuid,
"session_id": self.session_id,
"url": self.web_url,
"pin": self.pin,
@@ -315,4 +315,4 @@ class Session:
@property
def status(self) -> Dict[str, Union[str, int]]:
- return {"host_id": self.host_id, "session_id": self.session_id, "status": self.status_text}
+ return {"host_uuid": self.host_uuid, "session_id": self.session_id, "status": self.status_text}