From 94ffc706e74bca92c19450740f10a23c2349fbea Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 25 Jan 2021 13:09:20 +0100 Subject: [PATCH] [System] config: Read default config. * Config file in module path is the default config, this allows simpler user configs. * Default values also for test configuration --- flaschengeist.example.toml | 101 ------------------------------------- flaschengeist/config.py | 18 ++++--- readme.md | 16 +++--- 3 files changed, 20 insertions(+), 115 deletions(-) delete mode 100644 flaschengeist.example.toml diff --git a/flaschengeist.example.toml b/flaschengeist.example.toml deleted file mode 100644 index 3f4ff49..0000000 --- a/flaschengeist.example.toml +++ /dev/null @@ -1,101 +0,0 @@ -[FLASCHENGEIST] -# Select authentication provider (builtin: auth_plain, auth_ldap) -auth = "auth_plain" -# Enable if you run flaschengeist behind a proxy, e.g. nginx + gunicorn -#proxy = false -# Set root path, prefixes all routes -#root = /api -# Set secret key -secret_key = "V3ryS3cr3t" -# Domain used by frontend -#domain = "flaschengeist.local" - -[LOGGING] -file = "/tmp/flaschengeist-debug.log" -# DEBUG INFO WARNING ERROR -#level = "WARNING" - -[DATABASE] -user = "user" -host = "127.0.0.1" -password = "password" -database = "database" - -[auth_plain] -enabled = true - -#[auth_ldap] -# enabled = true -# host = -# port = -# bind_dn = -# base_dn = -# secret = -# use_ssl = -# admin_dn = -# admin_dn = -# default_gid = - -[MESSAGES] -welcome_subject = "Welcome to Flaschengeist {name}" -welcome_text = ''' -Hello {name}! -Welcome to Flaschengeist! - -Your username is {username}, please set your password: -{password_link} -(If the link expires, please just use the Forgot-Password-function). - -Have fun :) -''' - -password_subject = "Flaschengeist - Password reset" -password_text = ''' -Hello {name}! -There was a password reset request for username: {username} - -To change your password, click on this link: -{link} -''' - -password_changed_subject = "Flaschengeist - Password changed" -password_changed_text = ''' -Hello {name}! -Your password was changed for username: {username} - -If this was not you, please contact the support. -''' - -################## -# PLUGINS # -################## - -#[users] -# always enabled -# -## allowed values: false, "managed", "public" -## false: Disable registration -## "managed": only users with matching permission are allowed to register new users -## "public": Also unauthenticated users can register an account -# registration = False - -############################ -# Configuration of plugins # -############################ -#[mail] -# enabled = true -# SERVER = -# PORT = -# USER = -# PASSWORD = -# MAIL = -# SSL or STARTLS -# CRYPT = SSL - -[balance] -enabled = true -# Enable a default limit, will be set if no other limit is set -# limit = -10.00 - -[geruecht] -enabled = false diff --git a/flaschengeist/config.py b/flaschengeist/config.py index e8726c6..09ada68 100644 --- a/flaschengeist/config.py +++ b/flaschengeist/config.py @@ -21,12 +21,14 @@ def update_dict(d, u): return d -def read_configuration(): +def read_configuration(test_config): global config + paths = [_module_path] - paths = [_module_path, Path.home() / ".config"] - if "FLASCHENGEIST_CONF" in os.environ: - paths.append(Path(os.environ.get("FLASCHENGEIST_CONF"))) + if not test_config: + paths.append(Path.home() / ".config") + if "FLASCHENGEIST_CONF" in os.environ: + paths.append(Path(os.environ.get("FLASCHENGEIST_CONF"))) for loc in paths: try: @@ -35,14 +37,14 @@ def read_configuration(): update_dict(config, toml.load(source)) except IOError: pass + if test_config: + update_dict(config, test_config) def configure_app(app, test_config=None): global config - if test_config is None: - read_configuration() - else: - update_dict(config, test_config) + read_configuration(test_config) + # Always enable this builtin plugins! update_dict(config, {"auth": {"enabled": True}, "roles": {"enabled": True}, "users": {"enabled": True}}) diff --git a/readme.md b/readme.md index 51deeac..c950344 100644 --- a/readme.md +++ b/readme.md @@ -13,18 +13,22 @@ or if you want to also run the tests: pip3 install --user ".[ldap,test]" +You will also need a MySQL driver, recommended drivers are +- `mysqlclient` +- `PyMySQL` + #### Windows Same as above, but for mysql you have to follow this guide: https://www.radishlogic.com/coding/python-3/installing-mysqldb-for-python-3-in-windows/ ### Configuration -1. Rename `flaschengeist.example.toml` to `flaschengeist.toml` -2. Move it to either - 1. the module path (where flaschegeist is installed) - 2. `~/.config/` - 3. A custom path and set environment variable `FLASCHENGEIST_CONF` -3. Change at least the database parameters +Configuration is done within the a `flaschengeist.toml`file, you can copy the one located inside the module path +(where flaschegeist is installed) or create an empty one and place it inside either: +1. `~/.config/` +2. A custom path and set environment variable `FLASCHENGEIST_CONF` + +Change at least the database parameters! ### Database installation run_flaschengeist install