From 7d4ef7c8d59406705696d03cc3b3c192bdef5afa Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 21 Feb 2023 12:12:53 +0100 Subject: test_client.py, (...)/service.py: Add host_alias field to 'add_web_app_host'. --- rwa/support/sessionservice/service.py | 19 ++++++++++--------- test_client.py | 11 ++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 0d7ade1..40e65cb 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -185,9 +185,9 @@ class RWASupportSessionService(dbus.service.Object): return {"status": "success", "type": "valid_host"} @dbus.service.method( - "org.ArcticaProject.RWASupportSessionService", in_signature="s", out_signature="s" + "org.ArcticaProject.RWASupportSessionService", in_signature="ss", out_signature="s" ) - def add_web_app_host(self, host_url: str) -> str: + def add_web_app_host(self, host_url: str, host_alias: str) -> str: """Add a RWA.Support.WebApp host. :param host_url: Exact hostname of the RWA.Support.WebApp host (D-Bus string) @@ -197,7 +197,7 @@ class RWASupportSessionService(dbus.service.Object): :: - {"status": "success", "host": {"url": "https://example.org", "uuid": }} + {"status": "success", "host": {"url": "https://example.org", "alias": "", "uuid": }} **Structure of returned JSON (error):** @@ -214,12 +214,13 @@ class RWASupportSessionService(dbus.service.Object): * ``duplicate`` """ host_url = str(host_url).rstrip("/") + host_alias = str(host_alias) - logging.info('D-Bus method call: %s("%s")', "add_web_app_host", host_url) + logging.info('D-Bus method call: %s("%s", "%s")', "add_web_app_host", host_url, host_alias) 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_url) + logging.debug('Did not add "%s":"%s" to "web_app_hosts" in user_settings', host_alias, host_url) response = json.dumps({"status": "error", "type": "invalid_url"}) logging.info('The response to D-Bus caller: "%s"', response) @@ -229,7 +230,7 @@ class RWASupportSessionService(dbus.service.Object): for uuid, host in self.settings.web_app_hosts.items(): if host_url == host['url']: logging.warning("Given URL is already present!") - logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url) + logging.debug('Did not add "%s":"%s" to "web_app_hosts" in user_settings', host_alias, host_url) response = json.dumps({"status": "error", "type": "duplicate"}) logging.info('The response to D-Bus caller: "%s"', response) @@ -242,19 +243,19 @@ class RWASupportSessionService(dbus.service.Object): 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_url) + logging.debug('Did not add "%s":"%s" to "web_app_hosts" in user_settings', host_alias, host_url) response = json.dumps(res) logging.info('The response to D-Bus caller: "%s"', response) return response host_uuid = str(uuid4()) - host_object = {"url": host_url} + host_object = {"url": host_url, "alias": host_alias} 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_url) + logging.info('Added "%s":"%s" to "web_app_hosts" in user_settings', host_alias, host_url) response = {"status": "success", "host": self._build_host_dict(host_uuid, host_object)} response = json.dumps(response) diff --git a/test_client.py b/test_client.py index b646c4f..a7cb648 100755 --- a/test_client.py +++ b/test_client.py @@ -51,11 +51,12 @@ def get_web_app_hosts(): @cli.command() -@click.argument("host", type=str) -def add_web_app_host(host: str): - """Add a RWA.Support.WebApp host. Requires """ - click.echo(f"Sending D-Bus request 'add_web_app_host': {host}") - response = req.add_web_app_host(host) +@click.argument("host_url", type=str) +@click.argument("host_alias", type=str) +def add_web_app_host(host_url: str, host_alias: str): + """Add a RWA.Support.WebApp host. Requires """ + click.echo(f"Sending D-Bus request 'add_web_app_host': '{host_url}', '{host_alias}'") + response = req.add_web_app_host(host_url, host_alias) click.echo(f"Your response is: {response}") -- cgit v1.2.3