diff --git a/app/__init__.py b/app/__init__.py index 969e8ed..0cbec4d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,13 +4,13 @@ from flask_migrate import Migrate from flask_login import LoginManager from flask_mail import Mail from flask_wtf.csrf import CSRFProtect -from config import Config +from config import FlaskApplicationSettings app = Flask(__name__) -app.config.from_object(Config) +app.config.from_object(FlaskApplicationSettings) # Check security of secret -if Config.SECRET_KEY == "a-random-secret-key": +if FlaskApplicationSettings.SECRET_KEY == "a-random-secret-key": raise Exception("Please use a strong secret key!") db = SQLAlchemy(app) diff --git a/config.py b/config.py index 8b4efe8..96725a5 100644 --- a/config.py +++ b/config.py @@ -6,11 +6,28 @@ try: except ImportError: print(" \033[92mWARNING: Local config not found\033[0m") + # The LocalConfig class serves a dual purpose and overrides settings in + # both V5Config and some fields of FlaskApplicationSettings. The first has + # defaults (DefaultConfig), but not the second, so we provide them here. class LocalConfig(): - pass + FLASK_DEBUG = False + DB_NAME = "pcv5" + SECRET_KEY = "a-random-secret-key" +#--- +# Flask configuration +#--- + +class FlaskApplicationSettings(object): + """ + This object specifies the settings for the Flask application. All the keys + and values are predefined by Flask. + + See: https://flask.palletsprojects.com/en/2.1.x/config/ + """ + + DEBUG = os.environ.get("FLASK_DEBUG") or LocalConfig.FLASK_DEBUG -class Config(object): SECRET_KEY = os.environ.get('SECRET_KEY') or LocalConfig.SECRET_KEY SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'postgresql+psycopg2://' + os.environ.get('USER') + ':@/' \ @@ -27,9 +44,11 @@ class Config(object): # Do not attach cookies to cross-origin requests SESSION_COOKIE_SAMESITE = "Lax" +#--- +# v5 configuration +#--- class DefaultConfig(object): - """Every value here can be overrided in the local_config.py class""" # Domain DOMAIN = "v5.planet-casio.com" # Database name @@ -62,5 +81,9 @@ class DefaultConfig(object): class V5Config(LocalConfig, DefaultConfig): - # Values put here cannot be overidden with local_config + """ + This object holds the settings for the v5 code. Each parameter has the + value specified in LocalConfig (if any), and defaults to the value set in + DefaultConfig. + """ pass diff --git a/local_config.py.default b/local_config.py.default deleted file mode 100644 index f631079..0000000 --- a/local_config.py.default +++ /dev/null @@ -1,12 +0,0 @@ -# This is a sample file -# You can override every value available in the class DefaultConfig - -class LocalConfig(object): - DB_NAME = "pcv5" - USE_LDAP = True - LDAP_PASSWORD = "openldap" - LDAP_ENV = "o=prod" - SECRET_KEY = "a-random-secret-key" # CHANGE THIS VALUE *NOW* - AVATARS_FOLDER = '/home/pc/data/avatars/' - ENABLE_GUEST_POST = True - SEND_MAILS = True