From d9800c5223c41afb2f0b7078e2ff40356a0cbd2f Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 2 Oct 2022 12:08:47 +0200 Subject: [PATCH] refactor: override config from env Closes https://git.vvvvvvaria.org/varia/octomode/issues/8 --- README.md | 15 +++++++++++++++ config.py | 6 ------ octomode.py | 14 +++++++++++++- 3 files changed, 28 insertions(+), 7 deletions(-) delete mode 100644 config.py diff --git a/README.md b/README.md index f56f8a9..f03cd2e 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,21 @@ You can clone this repository to run octomode on your own computer or server. `make setup` (sets up a virtual environment and install the requirements, you only need to do this once) +Then you can configure your environment: + +- **OCTOMODE_PORTNUMBER**: optional, default: `5001` +- **OCTOMODE_PAD_URL**: optional, default: `https://pad.vvvvvvaria.org/` +- **OCTOMODE_PAD_API_URL**: optional, default: `https://pad.vvvvvvaria.org/api/1.2.15/` +- **OCTOMODE_PAD_API_KEY**: required, **no default** + +You must provide a value for `OCTOMODE_PAD_API_KEY`. + +You can do this by passing the values on the command-line before running octomode: + +``` +export OCTOMODE_PAD_API_KEY=... +``` + `make run` (runs the Flask application) Open the application at . diff --git a/config.py b/config.py deleted file mode 100644 index eca98cd..0000000 --- a/config.py +++ /dev/null @@ -1,6 +0,0 @@ -class Config(object): - APPLICATION_ROOT = '/' - PORTNUMBER = 5001 - PAD_URL = 'https://pad.vvvvvvaria.org/' # with a slash in the end! - PAD_API_URL = 'https://pad.vvvvvvaria.org/api/1.2.15/' - PAD_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' diff --git a/octomode.py b/octomode.py index 10a8485..679fa9e 100755 --- a/octomode.py +++ b/octomode.py @@ -14,8 +14,20 @@ import pypandoc # To read the Markdown metadat import markdown +class Config(object): + APPLICATION_ROOT = '/' + PORTNUMBER = int(os.environ.get('OCTOMODE_PORTNUMBER', 5001)) + PAD_URL = os.environ.get('OCTOMODE_PAD_URL', 'https://pad.vvvvvvaria.org/' ) + PAD_API_URL = os.environ.get('OCTOMODE_PAD_API_URL', 'https://pad.vvvvvvaria.org/api/1.2.15/') + PAD_API_KEY = os.environ.get('OCTOMODE_PAD_API_KEY', '') + APP = Flask(__name__) -APP.config.from_object("config.Config") +APP.config.from_object(Config) + +if APP.config.get('PAD_API_KEY', '') == '': + print("error: you must provide a value for OCTOMODE_PAD_API_KEY") + print("error: e.g. export OCTOMODE_PAD_API_KEY=...") + exit(1) # ---