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-10-21 11:07:10 +00:00
|
|
|
''' # Cookies # '''
|
|
|
|
REMEMBER_COOKIE_HTTPONLY = True
|
|
|
|
REMEMBER_COOKIE_SECURE = os.environ.get(
|
|
|
|
'NOPAQUE_REMEMBER_COOKIE_SECURE', 'false').lower() == 'true'
|
|
|
|
SESSION_COOKIE_SECURE = os.environ.get(
|
|
|
|
'NOPAQUE_SESSION_COOKIE_SECURE', 'false').lower() == 'true'
|
|
|
|
|
|
|
|
''' # Database # '''
|
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-10-21 11:07:10 +00:00
|
|
|
''' # Email # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
MAIL_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER')
|
|
|
|
MAIL_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD')
|
2020-10-21 11:07:10 +00:00
|
|
|
MAIL_PORT = int(os.environ.get('NOPAQUE_SMTP_PORT'))
|
2020-10-08 10:34:02 +00:00
|
|
|
MAIL_SERVER = os.environ.get('NOPAQUE_SMTP_SERVER')
|
|
|
|
MAIL_USERNAME = os.environ.get('NOPAQUE_SMTP_USERNAME')
|
2020-10-21 11:07:10 +00:00
|
|
|
MAIL_USE_SSL = os.environ.get(
|
|
|
|
'NOPAQUE_SMTP_USE_SSL', 'false').lower() == 'true'
|
|
|
|
MAIL_USE_TLS = os.environ.get(
|
|
|
|
'NOPAQUE_SMTP_USE_TLS', 'false').lower() == 'true'
|
2020-10-08 10:34:02 +00:00
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
''' # General # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
ADMIN_EMAIL_ADRESS = os.environ.get('NOPAQUE_ADMIN_EMAIL_ADRESS')
|
2020-10-23 11:52:01 +00:00
|
|
|
ALLOWED_USERNAME_REGEX = '^[A-Za-zÄÖÜäöüß0-9_.]*$'
|
2020-10-08 10:34:02 +00:00
|
|
|
CONTACT_EMAIL_ADRESS = os.environ.get('NOPAQUE_CONTACT_EMAIL_ADRESS')
|
2020-10-21 11:07:10 +00:00
|
|
|
DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
|
|
|
|
SECRET_KEY = os.environ.get('NOPAQUE_SECRET_KEY', 'hard to guess string')
|
2020-06-17 07:26:37 +00:00
|
|
|
|
2020-10-21 11:07:10 +00:00
|
|
|
''' # Logging # '''
|
2020-10-08 10:34:02 +00:00
|
|
|
LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT',
|
2020-10-21 11:07:10 +00:00
|
|
|
'%Y-%m-%d %H:%M:%S')
|
|
|
|
LOG_FILE = os.environ.get('NOPAQUE_LOG_FILE',
|
|
|
|
os.path.join(ROOT_DIR, 'nopaque.log'))
|
|
|
|
LOG_FORMAT = os.environ.get(
|
|
|
|
'NOPAQUE_LOG_FORMAT',
|
|
|
|
'[%(asctime)s] %(levelname)s in '
|
|
|
|
'%(pathname)s (function: %(funcName)s, line: %(lineno)d): %(message)s'
|
|
|
|
)
|
|
|
|
LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', 'WARNING')
|
|
|
|
|
|
|
|
''' # Message queue # '''
|
|
|
|
SOCKETIO_MESSAGE_QUEUE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI')
|
|
|
|
|
|
|
|
''' # Proxy fix # '''
|
|
|
|
PROXY_FIX_X_FOR = int(os.environ.get('NOPAQUE_PROXY_FIX_X_FOR', '0'))
|
|
|
|
PROXY_FIX_X_HOST = int(os.environ.get('NOPAQUE_PROXY_FIX_X_HOST', '0'))
|
|
|
|
PROXY_FIX_X_PORT = int(os.environ.get('NOPAQUE_PROXY_FIX_X_PORT', '0'))
|
|
|
|
PROXY_FIX_X_PREFIX = int(os.environ.get('NOPAQUE_PROXY_FIX_X_PREFIX', '0'))
|
|
|
|
PROXY_FIX_X_PROTO = int(os.environ.get('NOPAQUE_PROXY_FIX_X_PROTO', '0'))
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def init_app(cls, app):
|
|
|
|
# Set up logging according to the corresponding (LOG_*) variables
|
|
|
|
logging.basicConfig(datefmt=cls.LOG_DATE_FORMAT,
|
|
|
|
filename=cls.LOG_FILE,
|
|
|
|
format=cls.LOG_FORMAT,
|
|
|
|
level=cls.LOG_LEVEL)
|
|
|
|
# Set up and apply the ProxyFix middleware according to the
|
|
|
|
# corresponding (PROXY_FIX_*) variables
|
|
|
|
app.wsgi_app = ProxyFix(app.wsgi_app,
|
|
|
|
x_for=cls.PROXY_FIX_X_FOR,
|
|
|
|
x_host=cls.PROXY_FIX_X_HOST,
|
|
|
|
x_port=cls.PROXY_FIX_X_PORT,
|
|
|
|
x_prefix=cls.PROXY_FIX_X_PREFIX,
|
|
|
|
x_proto=cls.PROXY_FIX_X_PROTO)
|
|
|
|
|
|
|
|
|
|
|
|
class DevelopmentConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_DEV_DATABASE_URL',
|
|
|
|
'postgresql://nopaque:nopaque@db/nopaque_dev'
|
|
|
|
)
|
|
|
|
|
|
|
|
''' # General # '''
|
|
|
|
DEBUG = True
|
|
|
|
|
|
|
|
|
|
|
|
class ProductionConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_DATABASE_URL', 'postgresql://nopaque:nopaque@db/nopaque')
|
|
|
|
|
|
|
|
|
|
|
|
class TestingConfig(Config):
|
|
|
|
''' # Database # '''
|
|
|
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
|
|
|
'NOPAQUE_TEST_DATABASE_URL',
|
|
|
|
'postgresql://nopaque:nopaque@db/nopaque_test'
|
|
|
|
)
|
|
|
|
|
|
|
|
''' # General # '''
|
|
|
|
TESTING = True
|
|
|
|
WTF_CSRF_ENABLED = False
|
|
|
|
|
|
|
|
|
|
|
|
config = {'development': DevelopmentConfig,
|
|
|
|
'production': ProductionConfig,
|
|
|
|
'testing': TestingConfig}
|