From 09579899f2a38d7da5c30da066ef3a299dfca8b3 Mon Sep 17 00:00:00 2001 From: Maxime Daniel Date: Wed, 8 Mar 2023 20:20:51 +0100 Subject: [PATCH] config: add run modes as config dictionnary Mode run mode from hardcoded in the main code to a config option --- bootstrap.py | 15 ++++----------- config.py.sample | 9 +++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index dc94e17..3c9ce72 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -23,13 +23,6 @@ app = Flask(__name__, static_url_path='/static') app.url_map.strict_slashes = False -runmodes = { - "prod": "production (v3)", - "test": "testing (v3)", - "dev": "development (v3)", - "qa": "qa-network (v3)", -} - # # Database # @@ -67,7 +60,7 @@ def ipxe_script(release, farmer, extra="", source=None): kernel = os.path.join(config['kernel-path'], source) - if release not in runmodes.keys(): + if release not in config['runmodes'].keys(): abort(401) if not os.path.exists(kernel): @@ -86,7 +79,7 @@ def ipxe_script(release, farmer, extra="", source=None): settings = { - "release": runmodes[release], + "release": config['runmodes'][release], "farmerid": farmer, "parameters": extra, "kernel": kernel_secure, @@ -102,7 +95,7 @@ def ipxe_quick_script(release, farmer, extra=""): source = 'zero-os-development-zos-v2-generic.efi' kernel = os.path.join(config['kernel-path'], source) - if release not in runmodes.keys(): + if release not in config['runmodes'].keys(): abort(401) if not os.path.exists(kernel): @@ -118,7 +111,7 @@ def ipxe_quick_script(release, farmer, extra=""): cmdline += " " + extra settings = { - "release": runmodes[release], + "release": config['runmodes'][release], "parameters": extra, "kernel": kernel, "cmdline": cmdline, diff --git a/config.py.sample b/config.py.sample index 79729d6..496a8f1 100644 --- a/config.py.sample +++ b/config.py.sample @@ -24,4 +24,13 @@ config = { # sqlite3 database used for provisioning 'bootstrap-db': 'db/bootstrap.sqlite3', + + # allowed run-modes and their pretty name + 'runmodes': { + "prod": "production (v3)", + "test": "testing (v3)", + "dev": "development (v3)", + "qa": "qa-network (v3)", + }, + }