mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Config cleanup
This commit is contained in:
parent
b4082a2547
commit
0a8b32e57e
29
.env.tpl
29
.env.tpl
@ -33,10 +33,11 @@ HOST_DOCKER_GID=
|
||||
# HINT: Use this bash command `python -c "import uuid; print(uuid.uuid4().hex)"`
|
||||
# SECRET_KEY=
|
||||
|
||||
# DEFAULT: localhost:5000
|
||||
# Example: nopaque.example.com/nopaque.example.com:5000
|
||||
# HINT: If your instance is publicly available on a different Port then 80/443,
|
||||
# you will have to add this to the server name
|
||||
SERVER_NAME=
|
||||
# SERVER_NAME=
|
||||
|
||||
# CHOOSE ONE: False, True
|
||||
# DEFAULT: False
|
||||
@ -44,6 +45,15 @@ SERVER_NAME=
|
||||
# SESSION_COOKIE_SECURE=
|
||||
|
||||
|
||||
################################################################################
|
||||
# Flask-Assets #
|
||||
# https://webassets.readthedocs.io/en/latest/ #
|
||||
################################################################################
|
||||
# CHOOSE ONE: False, True
|
||||
# DEFAULT: False
|
||||
# ASSETS_DEBUG=
|
||||
|
||||
|
||||
################################################################################
|
||||
# Flask-Login #
|
||||
# https://flask-login.readthedocs.io/en/latest/ #
|
||||
@ -85,7 +95,7 @@ MAIL_USERNAME=
|
||||
# Flask-SQLAlchemy #
|
||||
# https://flask-sqlalchemy.palletsprojects.com/en/2.x/config/ #
|
||||
################################################################################
|
||||
# DEFAULT: 'sqlite:///<nopaque-basedir>/app.db'
|
||||
# DEFAULT: 'sqlite:///<nopaque-basedir>/data.sqlite'
|
||||
# NOTE: Use `.` as <nopaque-basedir>,
|
||||
# Don't use a SQLite database when using Docker
|
||||
# SQLALCHEMY_DATABASE_URI=
|
||||
@ -104,10 +114,6 @@ NOPAQUE_ADMIN=
|
||||
# Swarm nodes
|
||||
# NOPAQUE_DATA_DIR=
|
||||
|
||||
# NOTE: Get these from the nopaque development team
|
||||
NOPAQUE_DOCKER_REGISTRY_USERNAME=
|
||||
NOPAQUE_DOCKER_REGISTRY_PASSWORD=
|
||||
|
||||
# CHOOSE ONE: False, True
|
||||
# DEFAULT: True
|
||||
# NOPAQUE_IS_PRIMARY_INSTANCE=
|
||||
@ -115,6 +121,10 @@ NOPAQUE_DOCKER_REGISTRY_PASSWORD=
|
||||
# transport://[userid:password]@hostname[:port]/[virtual_host]
|
||||
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI=
|
||||
|
||||
# NOTE: Get these from the nopaque development team
|
||||
NOPAQUE_DOCKER_REGISTRY_USERNAME=
|
||||
NOPAQUE_DOCKER_REGISTRY_PASSWORD=
|
||||
|
||||
# DEFAULT: %Y-%m-%d %H:%M:%S
|
||||
# NOPAQUE_LOG_DATE_FORMAT=
|
||||
|
||||
@ -141,10 +151,15 @@ NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI=
|
||||
# DEFAULT: False
|
||||
# NOPAQUE_LOG_STDERR_ENABLED=
|
||||
|
||||
# DEFAULT: NOPAQUE_LOG_LEVEL
|
||||
# CHOOSE ONE: CRITICAL, ERROR, WARNING, INFO, DEBUG
|
||||
# DEFAULT: NOPAQUE_LOG_LEVEL
|
||||
# NOPAQUE_LOG_STDERR_LEVEL=
|
||||
|
||||
# CHOOSE ONE: False, True
|
||||
# DEFAULT: False
|
||||
# HINT: Set this to True only if you are using a proxy in front of nopaque
|
||||
# NOPAQUE_PROXY_FIX_ENABLED=
|
||||
|
||||
# DEFAULT: 0
|
||||
# Number of values to trust for X-Forwarded-For
|
||||
# NOPAQUE_PROXY_FIX_X_FOR=
|
||||
|
83
config.py
83
config.py
@ -14,53 +14,53 @@ class Config:
|
||||
''' # Flask # '''
|
||||
PREFERRED_URL_SCHEME = os.environ.get('PREFERRED_URL_SCHEME', 'http')
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY', 'hard to guess string')
|
||||
SERVER_NAME = os.environ.get('SERVER_NAME')
|
||||
SERVER_NAME = os.environ.get('SERVER_NAME', 'localhost:5000')
|
||||
SESSION_COOKIE_SECURE = \
|
||||
os.environ.get('SESSION_COOKIE_SECURE', 'false').lower() == 'true'
|
||||
TEMPLATES_AUTO_RELOAD = \
|
||||
os.environ.get('TEMPLATES_AUTO_RELOAD', 'false').lower() == 'true'
|
||||
|
||||
''' # Flask-Assets '''
|
||||
ASSETS_DEBUG = os.environ.get('ASSETS_DEBUG', 'false').lower() == 'true'
|
||||
|
||||
''' # Flask-Hashids '''
|
||||
HASHIDS_MIN_LENGTH = 32
|
||||
HASHIDS_MIN_LENGTH = 16
|
||||
|
||||
''' # 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_PORT = int(os.environ.get('MAIL_PORT'))
|
||||
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 # '''
|
||||
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
||||
'SQLALCHEMY_DATABASE_URI',
|
||||
'sqlite:///' + os.path.join(basedir, 'app.db')
|
||||
)
|
||||
SQLALCHEMY_DATABASE_URI = \
|
||||
os.environ.get('SQLALCHEMY_DATABASE_URI') \
|
||||
or f'sqlite:///{os.path.join(basedir, "data.sqlite")}'
|
||||
SQLALCHEMY_RECORD_QUERIES = True
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
''' # nopaque # '''
|
||||
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
|
||||
NOPAQUE_IS_PRIMARY_INSTANCE = \
|
||||
os.environ.get('NOPAQUE_IS_PRIMARY_INSTANCE', 'true').lower() == 'true'
|
||||
NOPAQUE_DATA_DIR = \
|
||||
os.path.abspath(os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque'))
|
||||
NOPAQUE_IS_PRIMARY_INSTANCE = \
|
||||
os.environ.get('NOPAQUE_IS_PRIMARY_INSTANCE', 'true').lower() == 'true'
|
||||
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
||||
NOPAQUE_SERVICE_DESK = 'gitlab-ub-incoming+sfb1288inf-nopaque-1324-issue-@jura.uni-bielefeld.de' # noqa
|
||||
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \
|
||||
os.environ.get('NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI')
|
||||
|
||||
NOPAQUE_DOCKER_REGISTRY = 'gitlab.ub.uni-bielefeld.de:4567'
|
||||
NOPAQUE_DOCKER_IMAGE_PREFIX = f'{NOPAQUE_DOCKER_REGISTRY}/sfb1288inf/'
|
||||
NOPAQUE_DOCKER_REGISTRY_USERNAME = \
|
||||
os.environ.get('NOPAQUE_DOCKER_REGISTRY_USERNAME')
|
||||
NOPAQUE_DOCKER_REGISTRY_PASSWORD = \
|
||||
os.environ.get('NOPAQUE_DOCKER_REGISTRY_PASSWORD')
|
||||
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
||||
NOPAQUE_SERVICE_DESK = 'gitlab-ub-incoming+sfb1288inf-nopaque-1324-issue-@jura.uni-bielefeld.de' # noqa
|
||||
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \
|
||||
os.environ.get('NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI')
|
||||
|
||||
NOPAQUE_LOG_DATE_FORMAT = \
|
||||
os.environ.get('NOPAQUE_LOG_DATE_FORMAT', '%Y-%m-%d %H:%M:%S')
|
||||
@ -81,6 +81,8 @@ class Config:
|
||||
NOPAQUE_LOG_STDERR_LEVEL = \
|
||||
os.environ.get('NOPAQUE_LOG_STDERR_LEVEL', NOPAQUE_LOG_LEVEL)
|
||||
|
||||
NOPAQUE_PROXY_FIX_ENABLED = \
|
||||
os.environ.get('NOPAQUE_PROXY_FIX_ENABLED', 'false').lower() == 'true'
|
||||
NOPAQUE_PROXY_FIX_X_FOR = \
|
||||
int(os.environ.get('NOPAQUE_PROXY_FIX_X_FOR', '0'))
|
||||
NOPAQUE_PROXY_FIX_X_HOST = \
|
||||
@ -93,47 +95,48 @@ class Config:
|
||||
int(os.environ.get('NOPAQUE_PROXY_FIX_X_PROTO', '0'))
|
||||
|
||||
NOPAQUE_TRANSKRIBUS_ENABLED = \
|
||||
os.environ.get('NOPAQUE_TRANSKRIBUS_ENABLED', 'true').lower() == 'true'
|
||||
os.environ.get('NOPAQUE_TRANSKRIBUS_ENABLED', 'false').lower() == 'true'
|
||||
NOPAQUE_READCOOP_USERNAME = os.environ.get('NOPAQUE_READCOOP_USERNAME')
|
||||
NOPAQUE_READCOOP_PASSWORD = os.environ.get('NOPAQUE_READCOOP_PASSWORD')
|
||||
|
||||
@classmethod
|
||||
def init_app(cls, app: Flask):
|
||||
@staticmethod
|
||||
def init_app(app: Flask):
|
||||
# Set up logging according to the corresponding (NOPAQUE_LOG_*)
|
||||
# configurations
|
||||
app.logger.setLevel(app.config.get('NOPAQUE_LOG_LEVEL'))
|
||||
app.logger.setLevel(app.config['NOPAQUE_LOG_LEVEL'])
|
||||
# Remove existing handlers
|
||||
for handler in app.logger.handlers:
|
||||
app.logger.removeHandler(handler)
|
||||
# Setup handlers
|
||||
formatter = logging.Formatter(
|
||||
fmt=app.config.get('NOPAQUE_LOG_FORMAT'),
|
||||
datefmt=app.config.get('NOPAQUE_LOG_DATE_FORMAT')
|
||||
fmt=app.config['NOPAQUE_LOG_FORMAT'],
|
||||
datefmt=app.config['NOPAQUE_LOG_DATE_FORMAT']
|
||||
)
|
||||
if app.config.get('NOPAQUE_LOG_STDERR_ENABLED'):
|
||||
if app.config['NOPAQUE_LOG_STDERR_ENABLED']:
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
stream_handler.setLevel(app.config.get('NOPAQUE_LOG_STDERR_LEVEL'))
|
||||
stream_handler.setLevel(app.config['NOPAQUE_LOG_STDERR_LEVEL'])
|
||||
app.logger.addHandler(stream_handler)
|
||||
if app.config.get('NOPAQUE_LOG_FILE_ENABLED'):
|
||||
if not os.path.exists(app.config.get('NOPAQUE_LOG_FILE_DIR')):
|
||||
os.mkdir(app.config.get('NOPAQUE_LOG_FILE_DIR'))
|
||||
if app.config['NOPAQUE_LOG_FILE_ENABLED']:
|
||||
if not os.path.exists(app.config['NOPAQUE_LOG_FILE_DIR']):
|
||||
os.mkdir(app.config['NOPAQUE_LOG_FILE_DIR'])
|
||||
rotating_file_handler = RotatingFileHandler(
|
||||
os.path.join(app.config.get('NOPAQUE_LOG_FILE_DIR'), 'nopaque.log'), # noqa
|
||||
maxBytes=10240,
|
||||
os.path.join(app.config['NOPAQUE_LOG_FILE_DIR'], 'nopaque.log'), # noqa
|
||||
maxBytes=10_240,
|
||||
backupCount=10
|
||||
)
|
||||
rotating_file_handler.setFormatter(formatter)
|
||||
rotating_file_handler.setLevel(app.config.get('NOPAQUE_LOG_FILE_LEVEL')) # noqa
|
||||
rotating_file_handler.setLevel(app.config['NOPAQUE_LOG_FILE_LEVEL']) # noqa
|
||||
app.logger.addHandler(rotating_file_handler)
|
||||
|
||||
# Set up and apply the ProxyFix middleware according to the
|
||||
# corresponding (NOPAQUE_PROXY_FIX_*) configurations
|
||||
app.wsgi_app = ProxyFix(
|
||||
app.wsgi_app,
|
||||
x_for=app.config.get('NOPAQUE_PROXY_FIX_X_FOR'),
|
||||
x_host=app.config.get('NOPAQUE_PROXY_FIX_X_HOST'),
|
||||
x_port=app.config.get('NOPAQUE_PROXY_FIX_X_PORT'),
|
||||
x_prefix=app.config.get('NOPAQUE_PROXY_FIX_X_PREFIX'),
|
||||
x_proto=app.config.get('NOPAQUE_PROXY_FIX_X_PROTO')
|
||||
)
|
||||
if app.config['NOPAQUE_PROXY_FIX_ENABLED']:
|
||||
# Set up and apply the ProxyFix middleware according to the
|
||||
# corresponding (NOPAQUE_PROXY_FIX_*) configurations
|
||||
app.wsgi_app = ProxyFix(
|
||||
app.wsgi_app,
|
||||
x_for=app.config['NOPAQUE_PROXY_FIX_X_FOR'],
|
||||
x_host=app.config['NOPAQUE_PROXY_FIX_X_HOST'],
|
||||
x_port=app.config['NOPAQUE_PROXY_FIX_X_PORT'],
|
||||
x_prefix=app.config['NOPAQUE_PROXY_FIX_X_PREFIX'],
|
||||
x_proto=app.config['NOPAQUE_PROXY_FIX_X_PROTO']
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user