2021-09-15 10:31:53 +00:00
|
|
|
from dotenv import load_dotenv
|
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
|
|
|
|
|
|
|
|
2021-09-15 10:31:53 +00:00
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
load_dotenv(os.path.join(basedir, '.env'))
|
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:
|
2021-08-04 15:07:59 +00:00
|
|
|
''' # Docker # '''
|
|
|
|
DOCKER_REGISTRY = 'gitlab.ub.uni-bielefeld.de:4567'
|
|
|
|
DOCKER_IMAGE_PREFIX = DOCKER_REGISTRY + '/sfb1288inf/'
|
|
|
|
|
2020-11-13 09:01:51 +00:00
|
|
|
''' # Flask # '''
|
2020-11-19 11:30:13 +00:00
|
|
|
PREFERRED_URL_SCHEME = os.environ.get('PREFERRED_URL_SCHEME', 'http')
|
2020-11-13 09:01:51 +00:00
|
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'hard to guess string')
|
2020-11-19 11:30:13 +00:00
|
|
|
SERVER_NAME = os.environ.get('SERVER_NAME')
|
2020-11-13 09:01:51 +00:00
|
|
|
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 # '''
|
2021-09-15 10:31:53 +00:00
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'SQLALCHEMY_DATABASE_URI',
|
|
|
|
'sqlite:///' + os.path.join(basedir, 'app.db')
|
|
|
|
)
|
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')
|
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',
|
2021-09-15 10:31:53 +00:00
|
|
|
os.path.join(basedir, 'nopaque.log')),
|
2020-11-13 09:01:51 +00:00
|
|
|
'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)
|