diff options
author | Jonathan Weth <mail@jonathanweth.de> | 2021-06-29 14:31:01 +0000 |
---|---|---|
committer | Jonathan Weth <mail@jonathanweth.de> | 2021-06-29 14:31:01 +0000 |
commit | 4c5b30bd253dd0230afffb29c6daa6c338c2749c (patch) | |
tree | 9d51d6e01de7743a5d1c71e9542d47126d4e2aff /rwa/support/sessionservice/service.py | |
parent | d8146354959fb352f9709ae0d2a674c361dbec17 (diff) | |
parent | ad5ebc3197b7fbd6ffffda969d5a81d939057bc7 (diff) | |
download | RWA.Support.SessionService-4c5b30bd253dd0230afffb29c6daa6c338c2749c.tar.gz RWA.Support.SessionService-4c5b30bd253dd0230afffb29c6daa6c338c2749c.tar.bz2 RWA.Support.SessionService-4c5b30bd253dd0230afffb29c6daa6c338c2749c.zip |
Merge branch 'feature/multiple-hosts' into 'master'
Support multiple hosts
See merge request remotewebapp/rwa.support.sessionservice!7
Diffstat (limited to 'rwa/support/sessionservice/service.py')
-rwxr-xr-x | rwa/support/sessionservice/service.py | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index c69c049..52bf627 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -38,6 +38,7 @@ import dbus.mainloop.glib import dbus.service from gi.repository import GLib +from .config import user_settings from .lock import is_locked, lock, unlock from .session import Session from .trigger import TriggerServerThread @@ -76,10 +77,73 @@ class RWASupportSessionService(dbus.service.Object): logging.info("D-Bus service has been started.") + def _get_web_app_hosts(self) -> str: + """Get all registered RWA.Support.WebApp hosts. + + Helper function: No D-Bus API. + """ + hosts = user_settings.web_app_hosts + return json.dumps(hosts) + @dbus.service.method("org.ArcticaProject.RWASupportSessionService", out_signature="s") - def start(self) -> str: + def get_web_app_hosts(self) -> str: + """Get all registered RWA.Support.WebApp hosts. + + :return: All registered hosts as JSON array (D-Bus string) + + **Structure of returned JSON:** + + :: + + ["https://example.org", "http://127.0.0.1:8000"] + """ + return self._get_web_app_hosts() + + @dbus.service.method( + "org.ArcticaProject.RWASupportSessionService", in_signature="s", out_signature="s" + ) + def add_web_app_host(self, host: str) -> str: + """Add a RWA.Support.WebApp host. + + :param host: Exact hostname of the RWA.Support.WebApp host (D-Bus string) + :return: All registered hosts as JSON array (D-Bus string) + + **Structure of returned JSON:** + + :: + + ["https://example.org", "http://127.0.0.1:8000"] + """ + user_settings.web_app_hosts.append(host) + user_settings.save_settings() + return self._get_web_app_hosts() + + @dbus.service.method( + "org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s" + ) + def remove_web_app_host(self, idx: int) -> str: + """Remove a RWA.Support.WebApp host. + + :param idx: Index of web app host (D-Bus integer) + :return: All registered hosts as JSON array (D-Bus string) + + **Structure of returned JSON:** + + :: + + ["https://example.org", "http://127.0.0.1:8000"] + """ + del user_settings.web_app_hosts[idx] + user_settings.save_settings() + return self._get_web_app_hosts() + + @dbus.service.method( + "org.ArcticaProject.RWASupportSessionService", in_signature="i", out_signature="s" + ) + def start(self, host_idx: int) -> str: """Start a new remote session and register it in RWA.Support.WebApp. + :param host_idx: Index of web app host (D-Bus integer) :return: Result as JSON (D-Bus string) **Structure of returned JSON (success):** @@ -103,10 +167,16 @@ class RWASupportSessionService(dbus.service.Object): "session, so this session won't be started." ) return json.dumps({"status": "error", "type": "multiple"}) + print(host_idx, user_settings.web_app_hosts) + + try: + host = user_settings.web_app_hosts[host_idx] + except IndexError: + return json.dumps({"status": "error", "type": "host_not_found"}) # Start session try: - session = Session(self.trigger_service.port, self.mockup_mode) + session = Session(host, self.trigger_service.port, self.mockup_mode) # Add session to sessions list self.sessions[session.pid] = session @@ -251,7 +321,7 @@ class RWASupportSessionService(dbus.service.Object): return False def _stop_all(self): - """Stop all sessions""" + """Stop all sessions.""" logging.info("Stop all sessions.") for session in list(self.sessions.values()): session.stop() |