From 7ca7079af96b294aaaac763b4d0b77a2cbc3d1fe Mon Sep 17 00:00:00 2001 From: Jonathan Weth Date: Wed, 29 Jul 2020 18:07:21 +0200 Subject: Add option to configure API URL --- config.py | 5 ++++ docs/admin/02_config.rst | 12 +++++++++- log.py | 3 +++ poetry.lock | 59 ++++++++++++++++++++++++++++++++---------------- pyproject.toml | 1 + service.py | 2 -- session.py | 10 ++++---- 7 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 config.py create mode 100644 log.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..06f2e6e --- /dev/null +++ b/config.py @@ -0,0 +1,5 @@ +from dynaconf import Dynaconf + +settings = Dynaconf( + envvar_prefix="RWA", settings_files=["/etc/rwa-session-service/settings.toml"] +) diff --git a/docs/admin/02_config.rst b/docs/admin/02_config.rst index 8666afa..83712f1 100644 --- a/docs/admin/02_config.rst +++ b/docs/admin/02_config.rst @@ -1,4 +1,14 @@ Configuration ============= -TBA. \ No newline at end of file +The configuration for the RWA Session Service have to be saved in ``/etc/rwa-session-service/settings.toml``. +In the following you see an example configuration: + +:: + + api_url = "http://127.0.0.1" + + +.. note:: + + Yes, there is just one parameter at the moment. \ No newline at end of file diff --git a/log.py b/log.py new file mode 100644 index 0000000..53a19ba --- /dev/null +++ b/log.py @@ -0,0 +1,3 @@ +import logging + +logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s", level=logging.INFO) diff --git a/poetry.lock b/poetry.lock index c252804..1cdd6bd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,5 @@ [[package]] -category = "main" +category = "dev" description = "A configurable sidebar-enabled Sphinx theme" name = "alabaster" optional = false @@ -15,7 +15,7 @@ python-versions = "*" version = "1.4.0" [[package]] -category = "main" +category = "dev" description = "Internationalization utilities" name = "babel" optional = false @@ -50,7 +50,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "7.1.2" [[package]] -category = "main" +category = "dev" description = "Cross-platform colored terminal text." marker = "sys_platform == \"win32\"" name = "colorama" @@ -67,13 +67,30 @@ python-versions = "*" version = "1.2.16" [[package]] -category = "main" +category = "dev" description = "Docutils -- Python Documentation Utilities" name = "docutils" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "0.16" +[[package]] +category = "main" +description = "The dynamic configurator for your Python Project" +name = "dynaconf" +optional = false +python-versions = "*" +version = "3.0.0" + +[package.extras] +all = ["redis", "ruamel.yaml", "configobj", "hvac"] +configobj = ["configobj"] +ini = ["configobj"] +redis = ["redis"] +toml = ["toml"] +vault = ["hvac"] +yaml = ["ruamel.yaml"] + [[package]] category = "main" description = "A simple framework for building complex web applications." @@ -102,7 +119,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.10" [[package]] -category = "main" +category = "dev" description = "Getting image size from png/jpeg/jpeg2000/gif file" name = "imagesize" optional = false @@ -148,7 +165,7 @@ python-versions = ">=3.6" version = "1.19.1" [[package]] -category = "main" +category = "dev" description = "Core utilities for Python packages" name = "packaging" optional = false @@ -187,7 +204,7 @@ python-versions = ">=3.5, <4" version = "1.19.1" [[package]] -category = "main" +category = "dev" description = "Pygments is a syntax highlighting package written in Python." name = "pygments" optional = false @@ -206,7 +223,7 @@ version = "3.36.1" pycairo = ">=1.11.1" [[package]] -category = "main" +category = "dev" description = "Python parsing module" name = "pyparsing" optional = false @@ -214,7 +231,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" version = "2.4.7" [[package]] -category = "main" +category = "dev" description = "World timezone definitions, modern and historical" name = "pytz" optional = false @@ -240,7 +257,7 @@ security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"] [[package]] -category = "main" +category = "dev" description = "Python 2 and 3 compatibility utilities" name = "six" optional = false @@ -248,7 +265,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" version = "1.15.0" [[package]] -category = "main" +category = "dev" description = "This package provides 26 stemmers for 25 languages generated from Snowball algorithms." name = "snowballstemmer" optional = false @@ -256,7 +273,7 @@ python-versions = "*" version = "2.0.0" [[package]] -category = "main" +category = "dev" description = "Python documentation generator" name = "sphinx" optional = false @@ -303,7 +320,7 @@ test = ["pytest (>=3.1.0)", "typing-extensions (>=3.5)", "sphobjinv (>=2.0)", "d type_comments = ["typed-ast (>=1.4.0)"] [[package]] -category = "main" +category = "dev" description = "sphinxcontrib-applehelp is a sphinx extension which outputs Apple help books" name = "sphinxcontrib-applehelp" optional = false @@ -315,7 +332,7 @@ lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] -category = "main" +category = "dev" description = "sphinxcontrib-devhelp is a sphinx extension which outputs Devhelp document." name = "sphinxcontrib-devhelp" optional = false @@ -327,7 +344,7 @@ lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] -category = "main" +category = "dev" description = "sphinxcontrib-htmlhelp is a sphinx extension which renders HTML help files" name = "sphinxcontrib-htmlhelp" optional = false @@ -339,7 +356,7 @@ lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest", "html5lib"] [[package]] -category = "main" +category = "dev" description = "A sphinx extension which renders display math in HTML via JavaScript" name = "sphinxcontrib-jsmath" optional = false @@ -350,7 +367,7 @@ version = "1.0.1" test = ["pytest", "flake8", "mypy"] [[package]] -category = "main" +category = "dev" description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp document." name = "sphinxcontrib-qthelp" optional = false @@ -362,7 +379,7 @@ lint = ["flake8", "mypy", "docutils-stubs"] test = ["pytest"] [[package]] -category = "main" +category = "dev" description = "sphinxcontrib-serializinghtml is a sphinx extension which outputs \"serialized\" HTML files (json and pickle)." name = "sphinxcontrib-serializinghtml" optional = false @@ -410,7 +427,7 @@ dev = ["pytest", "pytest-timeout", "coverage", "tox", "sphinx", "pallets-sphinx- watchdog = ["watchdog"] [metadata] -content-hash = "26e888443a11f1d9b956327a5ac6acc542bc1d0ded57fcc9d8cabe3de94836af" +content-hash = "e8abb4cff6b13abcf21de3c0796ad2a55df9ea22daf9a2cac8229084a39e65e6" python-versions = "^3.6" [metadata.files] @@ -449,6 +466,10 @@ docutils = [ {file = "docutils-0.16-py2.py3-none-any.whl", hash = "sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af"}, {file = "docutils-0.16.tar.gz", hash = "sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc"}, ] +dynaconf = [ + {file = "dynaconf-3.0.0-py2.py3-none-any.whl", hash = "sha256:000b64b9f58d33591fe2716b28b5177bffd5db6f11b9c52fbab580d7f655c343"}, + {file = "dynaconf-3.0.0.tar.gz", hash = "sha256:b5fb3d1b07a78e6166228bb07b4dea2d101de55e1679d119403a2593e337e273"}, +] flask = [ {file = "Flask-1.1.2-py2.py3-none-any.whl", hash = "sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"}, {file = "Flask-1.1.2.tar.gz", hash = "sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060"}, diff --git a/pyproject.toml b/pyproject.toml index 641b182..1345e96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ websockify = "^0.9.0" psutil = "^5.7.2" flask = "^1.1.2" argparse = "^1.0.10" +dynaconf = "^3.0.0" [tool.poetry.dev-dependencies] sphinx = "^3.0" diff --git a/service.py b/service.py index 031cf0d..7a36235 100755 --- a/service.py +++ b/service.py @@ -17,8 +17,6 @@ from gi.repository import GLib from session import Session from trigger import TriggerServerThread -logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s", level=logging.INFO) - ALLOW_ONLY_ONE_SESSION = True diff --git a/session.py b/session.py index c30fb19..37cc312 100644 --- a/session.py +++ b/session.py @@ -1,28 +1,28 @@ -import logging import os import random import secrets import signal import string import subprocess -import threading from typing import Dict, Union import port_for import psutil import requests -from flask import Flask, abort, request -from werkzeug.serving import make_server +from config import settings +from log import logging from vnc import run_vnc, save_password -API_SERVER = "http://127.0.0.1:8000" +API_SERVER = settings.get("api_url", "http://127.0.0.1") BASE_URL = API_SERVER + "/app/rwa/api/" REGISTER_URL = BASE_URL + "register/" STOP_URL = BASE_URL + "stop/" STATUS_URL = BASE_URL + "status/" MARK_JOB_AS_DONE_URL = BASE_URL + "jobs/mark_as_done/" +logging.info(f"Load API config: {API_SERVER}") + def random_digits(length: int): return "".join(random.choice(string.digits) for _ in range(length)) -- cgit v1.2.3