2020-05-27 10:52:41 +00:00
|
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
2019-09-11 12:50:29 +00:00
|
|
|
import logging
|
2020-10-08 10:34:02 +00:00
|
|
|
import os
|
2019-07-03 08:31:23 +00:00
|
|
|
|
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
|
2019-09-05 08:12:40 +00:00
|
|
|
|
2020-05-27 09:03:50 +00:00
|
|
|
|
2020-10-08 10:34:02 +00:00
|
|
|
class Config:
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask # '''
|
|
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'hard to guess string')
|
|
|
|
SESSION_COOKIE_SECURE = \
|
|
|
|
os.environ.get('SESSION_COOKIE_SECURE', 'false').lower() == 'true'
|
2020-10-21 11:07:10 +00:00
|
|
|
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask-Login # '''
|
|
|
|
REMEMBER_COOKIE_HTTPONLY = True
|
|
|
|
REMEMBER_COOKIE_SECURE = \
|
|
|
|
os.environ.get('REMEMBER_COOKIE_SECURE', 'false').lower() == 'true'
|
|
|
|
|
|
|
|
''' # Flask-Mail # '''
|
|
|
|
MAIL_DEFAULT_SENDER = os.environ.get('MAIL_DEFAULT_SENDER')
|
|
|
|
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
|
|
|
MAIL_PORT = int(os.environ.get('MAIL_PORT'))
|
|
|
|
MAIL_SERVER = os.environ.get('MAIL_SERVER')
|
|
|
|
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
|
|
|
|
MAIL_USE_SSL = os.environ.get('MAIL_USE_SSL', 'false').lower() == 'true'
|
|
|
|
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS', 'false').lower() == 'true'
|
|
|
|
|
|
|
|
''' # Flask-SQLAlchemy # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
SQLALCHEMY_RECORD_QUERIES = True
|
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
2020-06-17 07:26:37 +00:00
|
|
|
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # nopaque # '''
|
|
|
|
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
|
|
|
|
NOPAQUE_CONTACT = os.environ.get('NOPAQUE_CONTACT')
|
|
|
|
NOPAQUE_DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
|
|
|
|
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
|
|
|
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \
|
|
|
|
os.environ.get('NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI')
|
|
|
|
NOPAQUE_USERNAME_REGEX = '^[A-Za-zÄÖÜäöüß0-9_.]*$'
|
2020-10-21 11:07:10 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def init_app(cls, app):
|
2020-11-13 09:01:51 +00:00
|
|
|
# Set up logging according to the corresponding (NOPAQUE_LOG_*)
|
|
|
|
# environment variables
|
|
|
|
basic_config_kwargs = {
|
|
|
|
'datefmt': os.environ.get('NOPAQUE_LOG_DATE_FORMAT',
|
|
|
|
'%Y-%m-%d %H:%M:%S'),
|
|
|
|
'filename': os.environ.get('NOPAQUE_LOG_FILE',
|
|
|
|
os.path.join(ROOT_DIR, 'nopaque.log')),
|
|
|
|
'format': os.environ.get(
|
|
|
|
'NOPAQUE_LOG_FORMAT',
|
|
|
|
'[%(asctime)s] %(levelname)s in '
|
|
|
|
'%(pathname)s (function: %(funcName)s, line: %(lineno)d): '
|
|
|
|
'%(message)s'
|
|
|
|
),
|
|
|
|
'level': os.environ.get('NOPAQUE_LOG_LEVEL', 'WARNING')
|
|
|
|
}
|
|
|
|
logging.basicConfig(**basic_config_kwargs)
|
2020-10-21 11:07:10 +00:00
|
|
|
# Set up and apply the ProxyFix middleware according to the
|
2020-11-13 09:01:51 +00:00
|
|
|
# corresponding (NOPAQUE_PROXY_FIX_*) environment variables
|
|
|
|
proxy_fix_kwargs = {
|
|
|
|
'x_for': int(os.environ.get('NOPAQUE_PROXY_FIX_X_FOR', '0')),
|
|
|
|
'x_host': int(os.environ.get('NOPAQUE_PROXY_FIX_X_HOST', '0')),
|
|
|
|
'x_port': int(os.environ.get('NOPAQUE_PROXY_FIX_X_PORT', '0')),
|
|
|
|
'x_prefix': int(os.environ.get('NOPAQUE_PROXY_FIX_X_PREFIX', '0')),
|
|
|
|
'x_proto': int(os.environ.get('NOPAQUE_PROXY_FIX_X_PROTO', '0'))
|
|
|
|
}
|
|
|
|
app.wsgi_app = ProxyFix(app.wsgi_app, **proxy_fix_kwargs)
|
2020-10-21 11:07:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DevelopmentConfig(Config):
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask # '''
|
|
|
|
DEBUG = True
|
|
|
|
|
|
|
|
''' # Flask-SQLAlchemy # '''
|
2020-10-21 11:07:10 +00:00
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
2020-11-13 09:01:51 +00:00
|
|
|
'SQLALCHEMY_DATABASE_URI',
|
2020-10-21 11:07:10 +00:00
|
|
|
'postgresql://nopaque:nopaque@db/nopaque_dev'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ProductionConfig(Config):
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask-SQLAlchemy # '''
|
2020-10-21 11:07:10 +00:00
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
2020-11-13 09:01:51 +00:00
|
|
|
'SQLALCHEMY_DATABASE_URI', 'postgresql://nopaque:nopaque@db/nopaque')
|
2020-10-21 11:07:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestingConfig(Config):
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask # '''
|
|
|
|
TESTING = True
|
|
|
|
WTF_CSRF_ENABLED = False
|
|
|
|
|
|
|
|
''' # Flask-SQLAlchemy # '''
|
2020-10-21 11:07:10 +00:00
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
2020-11-13 09:01:51 +00:00
|
|
|
'SQLALCHEMY_DATABASE_URI',
|
2020-10-21 11:07:10 +00:00
|
|
|
'postgresql://nopaque:nopaque@db/nopaque_test'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
config = {'development': DevelopmentConfig,
|
|
|
|
'production': ProductionConfig,
|
|
|
|
'testing': TestingConfig}
|