From 2f69aa4335f53cc569575eff0ce6c7699358d024 Mon Sep 17 00:00:00 2001 From: dortal94 Date: Sat, 25 Apr 2020 19:05:36 +0100 Subject: [PATCH 1/4] Added config file Added config file so the app will auto configured once the flask app starts. --- edison/__init__.py | 2 ++ edison/config.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 edison/config.py diff --git a/edison/__init__.py b/edison/__init__.py index dac6ddb..befb02a 100644 --- a/edison/__init__.py +++ b/edison/__init__.py @@ -1,8 +1,10 @@ import os from flask import Flask +from edison.config import get_config_object # Put app here so the entire app could import it. app = Flask(__name__) +app.config.from_object(get_config_object(app.config["ENV"])) basedir = os.path.abspath(os.path.dirname(__file__)) diff --git a/edison/config.py b/edison/config.py new file mode 100644 index 0000000..82314f8 --- /dev/null +++ b/edison/config.py @@ -0,0 +1,28 @@ +import secrets +import importlib, inspect +import sys, inspect + +config_dict = {} + +# If config_dict is empty this function builds it dynamically +# and returns the appropriate config object path. +def get_config_object(env_keyword: str): + if(len(config_dict) == 0): + # Iterating through all config.py members + for name, obj in inspect.getmembers(sys.modules[__name__]): + # We're interested only with the derived classes of the Config class + if inspect.isclass(obj) and name != "Config": + config_dict[obj.ENV_KEYWORD] = ".".join([obj.__module__, name]) + + return config_dict[env_keyword] + +class Config: + ENV_KEYWORD = "" + DEBUG = False + +class ProductionConfig(Config): + ENV_KEYWORD = "production" + +class DevelopmentConfig(Config): + ENV_KEYWORD = "development" + DEBUG = True From 54a6d858ce0f877a7f4b070cbf69b58fbf9a7c4a Mon Sep 17 00:00:00 2001 From: dortal94 Date: Sat, 25 Apr 2020 19:07:01 +0100 Subject: [PATCH 2/4] Set FLASK_ENV environment var --- setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.sh b/setup.sh index 02dcd7a..1e6346c 100644 --- a/setup.sh +++ b/setup.sh @@ -17,6 +17,8 @@ sudo apt-get install -y postgresql postgresql-contrib echo "install requirements" pip3 install -r /vagrant/requirements.txt +export FLASK_ENV=development + echo "running app.py" export FLASK_APP=/vagrant/edison/app.py flask run -h 0.0.0.0 -p $FLASK_PORT >> /vagrant/edison/app.log 2>&1 & From dc33484b3533020d18428dc4e9234c507308ba38 Mon Sep 17 00:00:00 2001 From: dortal94 Date: Sun, 26 Apr 2020 11:19:16 +0100 Subject: [PATCH 3/4] Removed unnecessary comment --- edison/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/edison/app.py b/edison/app.py index 6ef3f3e..11d4c69 100644 --- a/edison/app.py +++ b/edison/app.py @@ -3,8 +3,6 @@ from flask import render_template -# API description in swagger - https://app.swaggerhub.com/apis/DoRTaL94/UserManagment/1.0.0 - app = edison.app @app.route("/") From 64ec2e4df516070345e6cff78a69d362886c4e5c Mon Sep 17 00:00:00 2001 From: dortal94 Date: Sat, 2 May 2020 11:44:18 +0100 Subject: [PATCH 4/4] Changed comment in Vagrantfile Changed the linked issue to a more relevant one --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 61a4b3c..ca7721a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,7 +13,7 @@ Vagrant.configure("2") do |config| end # Fixes a dhcp configuration conflict of the private network. -# Issue: https://github.com/hashicorp/vagrant/issues/3083 +# Issue: https://github.com/hashicorp/vagrant/issues/8878 class VagrantPlugins::ProviderVirtualBox::Action::Network def dhcp_server_matches_config?(dhcp_server, config) true