diff options
author | Jonathan Weth <git@jonathanweth.de> | 2021-06-28 11:59:29 +0200 |
---|---|---|
committer | Jonathan Weth <git@jonathanweth.de> | 2021-06-28 11:59:29 +0200 |
commit | e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8 (patch) | |
tree | db4a4897185ac618fa7b046c20e032ecb0fc4a63 | |
parent | 9ec08cbc84b01ce82f58892556637d8934ede0a5 (diff) | |
parent | d81082efdea8b603914f04b6690d11c28fc8fcf7 (diff) | |
download | RWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.tar.gz RWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.tar.bz2 RWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.zip |
Merge branch 'master' into feature/multiple-hosts
-rw-r--r-- | poetry.lock | 94 | ||||
-rw-r--r-- | pyproject.toml | 1 | ||||
-rwxr-xr-x | rwa/support/sessionservice/service.py | 49 | ||||
-rw-r--r-- | rwa/support/sessionservice/session.py | 2 | ||||
-rwxr-xr-x | test_client.py | 52 | ||||
-rw-r--r-- | tox.ini | 10 |
6 files changed, 123 insertions, 85 deletions
diff --git a/poetry.lock b/poetry.lock index c501ed0..0c0a1a8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -8,7 +8,7 @@ python-versions = "*" [[package]] name = "aleksis-builddeps" -version = "2021.6b0" +version = "2021.6rc2" description = "AlekSIS (School Information System) — Build/Dev dependencies for apps" category = "dev" optional = false @@ -60,7 +60,7 @@ python-versions = "*" [[package]] name = "asgiref" -version = "3.3.4" +version = "3.4.0" description = "ASGI specs, helper code, and adapters" category = "dev" optional = false @@ -166,17 +166,21 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "click" -version = "7.1.2" +version = "8.0.1" description = "Composable command line interface toolkit" category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.6" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "colorama" version = "0.4.4" description = "Cross-platform colored terminal text." -category = "dev" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" @@ -445,17 +449,17 @@ restructuredtext-lint = "*" [[package]] name = "flask" -version = "1.1.4" +version = "1.1.2" description = "A simple framework for building complex web applications." category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [package.dependencies] -click = ">=5.1,<8.0" -itsdangerous = ">=0.24,<2.0" -Jinja2 = ">=2.10.1,<3.0" -Werkzeug = ">=0.15,<2.0" +click = ">=5.1" +itsdangerous = ">=0.24" +Jinja2 = ">=2.10.1" +Werkzeug = ">=0.15" [package.extras] dev = ["pytest", "coverage", "tox", "sphinx", "pallets-sphinx-themes", "sphinxcontrib-log-cabinet", "sphinx-issues"] @@ -514,9 +518,9 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [[package]] name = "importlib-metadata" -version = "4.5.0" +version = "4.6.0" description = "Read metadata from Python packages" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -526,7 +530,8 @@ zipp = ">=0.5" [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] -testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] +perf = ["ipython"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] [[package]] name = "iniconfig" @@ -552,25 +557,25 @@ plugins = ["setuptools"] [[package]] name = "itsdangerous" -version = "1.1.0" -description = "Various helpers to pass data to untrusted environments and back." +version = "2.0.1" +description = "Safely pass data to untrusted environments and back." category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.6" [[package]] name = "jinja2" -version = "2.11.3" +version = "3.0.1" description = "A very fast and expressive template engine." category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.6" [package.dependencies] -MarkupSafe = ">=0.23" +MarkupSafe = ">=2.0" [package.extras] -i18n = ["Babel (>=0.8)"] +i18n = ["Babel (>=2.7)"] [[package]] name = "markupsafe" @@ -1196,13 +1201,13 @@ python-versions = "*" name = "typing-extensions" version = "3.10.0.0" description = "Backported and Experimental Type Hints for Python 3.5+" -category = "dev" +category = "main" optional = false python-versions = "*" [[package]] name = "urllib3" -version = "1.26.5" +version = "1.26.6" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "main" optional = false @@ -1237,21 +1242,20 @@ numpy = "*" [[package]] name = "werkzeug" -version = "1.0.1" +version = "2.0.1" description = "The comprehensive WSGI web application library." category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.6" [package.extras] -dev = ["pytest", "pytest-timeout", "coverage", "tox", "sphinx", "pallets-sphinx-themes", "sphinx-issues"] watchdog = ["watchdog"] [[package]] name = "zipp" version = "3.4.1" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -1262,7 +1266,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "4477f63dce4f7591677d1eaa2bc01265e56d3aa06811958fdaaab7b1f93c920e" +content-hash = "e94d233aff281e3b0cdf43eab46ee628f6772a88780ca76396f008ae41fb4548" [metadata.files] alabaster = [ @@ -1270,8 +1274,8 @@ alabaster = [ {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, ] aleksis-builddeps = [ - {file = "AlekSIS-Builddeps-2021.6b0.tar.gz", hash = "sha256:a70b4d917e0f03d037384960f108b13d9b0413cc082b171f2f239163fd93462a"}, - {file = "AlekSIS_Builddeps-2021.6b0-py3-none-any.whl", hash = "sha256:b579c9e2938179c83d3e2656cdc5c28ea9113be65498b8e8ea7f380b6783154b"}, + {file = "AlekSIS-Builddeps-2021.6rc2.tar.gz", hash = "sha256:abefdf307dbc2ec3e4e1688f59621bb0da80911b248cc0ed6fb04de5d0fbf641"}, + {file = "AlekSIS_Builddeps-2021.6rc2-py3-none-any.whl", hash = "sha256:4290c265a90bd96c093da413905641888d33dc55d0e34512d057cd53d5c40977"}, ] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, @@ -1282,8 +1286,8 @@ argparse = [ {file = "argparse-1.4.0.tar.gz", hash = "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4"}, ] asgiref = [ - {file = "asgiref-3.3.4-py3-none-any.whl", hash = "sha256:92906c611ce6c967347bbfea733f13d6313901d54dcca88195eaeb52b2a8e8ee"}, - {file = "asgiref-3.3.4.tar.gz", hash = "sha256:d1216dfbdfb63826470995d31caed36225dcaf34f182e0fa257a4dd9e86f1b78"}, + {file = "asgiref-3.4.0-py3-none-any.whl", hash = "sha256:d36fa91dd90e3aa3c81a6bd426ccc8fb20bd3d22b0cf14a12800289e9c3e2563"}, + {file = "asgiref-3.4.0.tar.gz", hash = "sha256:05914d0fa65a21711e732adc6572edad6c8da5f1435c3f0c060689ced5e85195"}, ] asn1crypto = [ {file = "asn1crypto-1.4.0-py2.py3-none-any.whl", hash = "sha256:4bcdf33c861c7d40bdcd74d8e4dd7661aac320fcdf40b9a3f95b4ee12fde2fa8"}, @@ -1318,8 +1322,8 @@ chardet = [ {file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"}, ] click = [ - {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, - {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, + {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, + {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, ] colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, @@ -1458,8 +1462,8 @@ flake8-rst-docstrings = [ {file = "flake8_rst_docstrings-0.2.3-py3-none-any.whl", hash = "sha256:565bbb391d7e4d0042924102221e9857ad72929cdd305b26501736ec22c1451a"}, ] flask = [ - {file = "Flask-1.1.4-py2.py3-none-any.whl", hash = "sha256:c34f04500f2cbbea882b1acb02002ad6fe6b7ffa64a6164577995657f50aed22"}, - {file = "Flask-1.1.4.tar.gz", hash = "sha256:0fbeb6180d383a9186d0d6ed954e0042ad9f18e0e8de088b2b419d526927d196"}, + {file = "Flask-1.1.2-py2.py3-none-any.whl", hash = "sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"}, + {file = "Flask-1.1.2.tar.gz", hash = "sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060"}, ] freezegun = [ {file = "freezegun-1.1.0-py2.py3-none-any.whl", hash = "sha256:2ae695f7eb96c62529f03a038461afe3c692db3465e215355e1bb4b0ab408712"}, @@ -1482,8 +1486,8 @@ imagesize = [ {file = "imagesize-1.2.0.tar.gz", hash = "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1"}, ] importlib-metadata = [ - {file = "importlib_metadata-4.5.0-py3-none-any.whl", hash = "sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00"}, - {file = "importlib_metadata-4.5.0.tar.gz", hash = "sha256:b142cc1dd1342f31ff04bb7d022492b09920cb64fed867cd3ea6f80fe3ebd139"}, + {file = "importlib_metadata-4.6.0-py3-none-any.whl", hash = "sha256:c6513572926a96458f8c8f725bf0e00108fba0c9583ade9bd15b869c9d726e33"}, + {file = "importlib_metadata-4.6.0.tar.gz", hash = "sha256:4a5611fea3768d3d967c447ab4e93f567d95db92225b43b7b238dbfb855d70bb"}, ] iniconfig = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, @@ -1494,12 +1498,12 @@ isort = [ {file = "isort-5.9.1.tar.gz", hash = "sha256:83510593e07e433b77bd5bff0f6f607dbafa06d1a89022616f02d8b699cfcd56"}, ] itsdangerous = [ - {file = "itsdangerous-1.1.0-py2.py3-none-any.whl", hash = "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"}, - {file = "itsdangerous-1.1.0.tar.gz", hash = "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19"}, + {file = "itsdangerous-2.0.1-py3-none-any.whl", hash = "sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c"}, + {file = "itsdangerous-2.0.1.tar.gz", hash = "sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"}, ] jinja2 = [ - {file = "Jinja2-2.11.3-py2.py3-none-any.whl", hash = "sha256:03e47ad063331dd6a3f04a43eddca8a966a26ba0c5b7207a9a9e4e08f1b29419"}, - {file = "Jinja2-2.11.3.tar.gz", hash = "sha256:a6d58433de0ae800347cab1fa3043cebbabe8baa9d29e668f1c768cb87a333c6"}, + {file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"}, + {file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"}, ] markupsafe = [ {file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"}, @@ -1934,8 +1938,8 @@ typing-extensions = [ {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, ] urllib3 = [ - {file = "urllib3-1.26.5-py2.py3-none-any.whl", hash = "sha256:753a0374df26658f99d826cfe40394a686d05985786d946fbe4165b5148f5a7c"}, - {file = "urllib3-1.26.5.tar.gz", hash = "sha256:a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098"}, + {file = "urllib3-1.26.6-py2.py3-none-any.whl", hash = "sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4"}, + {file = "urllib3-1.26.6.tar.gz", hash = "sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f"}, ] usersettings = [ {file = "usersettings-1.1.5-py3-none-any.whl", hash = "sha256:503be61d30d0cfd98f16bb6c9be86c29e78dc476c794ffae6333ab26f38994bf"}, @@ -1945,8 +1949,8 @@ websockify = [ {file = "websockify-0.9.0.tar.gz", hash = "sha256:c35b5b79ebc517d3b784dacfb993be413a93cda5222c6f382443ce29c1a6cada"}, ] werkzeug = [ - {file = "Werkzeug-1.0.1-py2.py3-none-any.whl", hash = "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43"}, - {file = "Werkzeug-1.0.1.tar.gz", hash = "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c"}, + {file = "Werkzeug-2.0.1-py3-none-any.whl", hash = "sha256:6c1ec500dcdba0baa27600f6a22f6333d8b662d22027ff9f6202e3367413caa8"}, + {file = "Werkzeug-2.0.1.tar.gz", hash = "sha256:1de1db30d010ff1af14a009224ec49ab2329ad2cde454c8a708130642d579c42"}, ] zipp = [ {file = "zipp-3.4.1-py3-none-any.whl", hash = "sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098"}, diff --git a/pyproject.toml b/pyproject.toml index 1ffeb05..de0b661 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ flask = "^1.1.2" argparse = "^1.0.10" dynaconf = "^3.0.0" usersettings = "^1.1.5" +click = "^8.0.1" [tool.poetry.dev-dependencies] aleksis-builddeps = "*" diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 4798df6..2bc727d 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -25,7 +25,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -import argparse import json import logging import signal @@ -33,6 +32,7 @@ import time from threading import Thread from typing import Union +import click import dbus import dbus.mainloop.glib import dbus.service @@ -354,7 +354,23 @@ def str2bool(v: Union[str, bool, int]) -> bool: raise argparse.ArgumentTypeError("Boolean value expected.") -def main(): +@click.command() +@click.option( + "-m", + "--mockup", + is_flag=True, + default=False, + help="Activates mock up mode. Acts like the real Session Service " + "but don't do changes or call RWA.Support.WebApp.", +) +@click.option( + "-o", + "--once", + is_flag=True, + default=False, + help="Runs as one-time-service. Stops after one session.", +) +def main(mockup, once): # Check for lock file if is_locked(): logging.error("The service is already running.") @@ -363,38 +379,13 @@ def main(): # Create lock file lock() - parser = argparse.ArgumentParser(description="D-Bus Session Service for RWA.Support") - parser.add_argument( - "-m", - "--mockup-mode", - type=str2bool, - nargs="?", - const=True, - default=False, - help="Activates mock up mode. Acts like the real session service " - "but don't do changes or call RWA.", - ) - parser.add_argument( - "-o", - "--one-time", - type=str2bool, - nargs="?", - const=True, - default=False, - help="Runs as one-time-service. Stops after one session.", - ) - - args = parser.parse_args() - mockup_mode = args.mockup_mode - one_time = args.one_time - - if mockup_mode: + if mockup: logging.warning("All API responses are faked and should NOT BE USED IN PRODUCTION!") dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) loop = GLib.MainLoop() - service_object = RWASupportSessionService(loop, mockup_mode, one_time) + service_object = RWASupportSessionService(loop, mockup, once) def signal_handler(sig, frame): logging.info("Service was terminated.") diff --git a/rwa/support/sessionservice/session.py b/rwa/support/sessionservice/session.py index 81584ea..11c418e 100644 --- a/rwa/support/sessionservice/session.py +++ b/rwa/support/sessionservice/session.py @@ -143,6 +143,7 @@ class Session: }, ) except requests.exceptions.ConnectionError: + self.stop(triggered=True) raise ConnectionError() logging.info( @@ -151,6 +152,7 @@ class Session: ) if r.status_code != 200: + self.stop(triggered=True) raise ConnectionError() self.meta = r.json() diff --git a/test_client.py b/test_client.py index 0e78784..5176ad2 100755 --- a/test_client.py +++ b/test_client.py @@ -3,7 +3,7 @@ # This file is part of Remote Support Desktop # https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.sessionservice # Copyright 2020, 2021 Jonathan Weth <dev@jonathanweth.de> -# Copyright 2020 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> +# Copyright 2020, 2021 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> # Copyright 2020 Mike Gabriel <mike.gabriel@das-netzwerkteam.de> # SPDX-License-Identifier: GPL-2.0-or-later # @@ -25,13 +25,53 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. + +import click import dbus bus = dbus.SessionBus() +req = bus.get_object("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService") + + +@click.group() +def cli(): + pass + + +@cli.command() +@click.argument("host") +def start(host: int): + """Start a session on the RWA.Support.WebApp host with index HOST.""" + click.echo(f"Sending D-Bus request 'start': {host}") + response = req.start(host) + click.echo(f"Your response is: {response}") + + +@cli.command() +@click.argument("pid") +def stop(pid: int): + """Stop the session with the pid PID.""" + click.echo(f"Sending D-Bus request 'stop' with PID {pid}") + response = req.stop(pid) + click.echo(f"Your response is: {response}") + + +@cli.command() +@click.argument("pid") +def status(pid: int): + """Get the status of the session with the pid PID.""" + click.echo(f"Sending D-Bus request 'status' with PID {pid}") + response = req.status(pid) + click.echo(f"Your response is: {response}") + -api = bus.get_object("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService") +@cli.command() +@click.argument("pid") +def refresh_status(pid: int): + """Refresh and get the status of the session with the pid PID.""" + click.echo(f"Sending D-Bus request 'refresh_status' with PID {pid}") + response = req.refresh_status(pid) + click.echo(f"Your response is: {response}") -hosts = api.get_web_app_hosts() -print(hosts) -curr = api.start(0) -print("Your VNC session is", curr) +if __name__ == "__main__": + cli() @@ -15,9 +15,9 @@ commands = [testenv:lint] commands = - poetry run black --check --diff rwa/ - poetry run isort -c --diff --stdout rwa/ - poetry run flake8 {posargs} rwa/ + poetry run black --check --diff rwa/ test_client.py + poetry run isort -c --diff --stdout rwa/ test_client.py + poetry run flake8 {posargs} rwa/ test_client.py [testenv:security] commands = @@ -34,8 +34,8 @@ commands = poetry run make -C docs/ html {posargs} [testenv:reformat] commands = - poetry run isort rwa/ - poetry run black rwa/ + poetry run isort rwa/ test_client.py + poetry run black rwa/ test_client.py [flake8] max_line_length = 100 |