mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
import os
|
|
import logging
|
|
|
|
|
|
class Config:
|
|
''' ### Flask ### '''
|
|
SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
|
|
|
|
''' ### Flask-Mail ### '''
|
|
MAIL_SERVER = os.environ.get('MAIL_SERVER')
|
|
MAIL_PORT = int(os.environ.get('MAIL_PORT'))
|
|
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS').lower() == 'true'
|
|
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
|
|
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
|
|
|
|
''' ### Flask-SQLAlchemy ### '''
|
|
SQLALCHEMY_RECORD_QUERIES = True
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
''' ### nopaque ### '''
|
|
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
|
|
NOPAQUE_MAIL_SENDER = os.environ.get('NOPAQUE_MAIL_SENDER')
|
|
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
|
NOPAQUE_STORAGE = os.environ.get('NOPAQUE_STORAGE')
|
|
|
|
@staticmethod
|
|
def init_app(app):
|
|
pass
|
|
|
|
|
|
class DevelopmentConfig(Config):
|
|
''' ### Flask ### '''
|
|
DEBUG = True
|
|
|
|
''' ### Flask-SQLAlchemy ### '''
|
|
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@db/{}'.format(
|
|
os.environ.get('POSTGRES_USER'),
|
|
os.environ.get('POSTGRES_PASSWORD'),
|
|
os.environ.get('POSTGRES_DB_NAME'))
|
|
if not os.path.isfile('logs/nopaque.log'):
|
|
file_path = os.path.join(os.getcwd(), 'logs/nopaque.log')
|
|
log = open(file_path, 'w+')
|
|
log.close()
|
|
if os.environ.get('FLASK_CONFIG') == 'development':
|
|
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
|
|
"%(filename)s - %(lineno)d - %(message)s")
|
|
logging.basicConfig(filename='logs/nopaque.log', level='WARNING',
|
|
format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
|
|
filemode='w')
|
|
logger = logging.getLogger(__name__)
|
|
logger.warning('Logging has started with level WARNING.'
|
|
' From development config.')
|
|
|
|
|
|
class TestingConfig(Config):
|
|
''' ### Flask ### '''
|
|
TESTING = True
|
|
|
|
''' ### Flask-SQLAlchemy ### '''
|
|
SQLALCHEMY_DATABASE_URI = 'sqlite://'
|
|
|
|
''' ### Flask-WTF ### '''
|
|
WTF_CSRF_ENABLED = False
|
|
|
|
|
|
class ProductionConfig(Config):
|
|
''' ### Flask-SQLAlchemy ### '''
|
|
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@db/{}'.format(
|
|
os.environ.get('POSTGRES_USER'),
|
|
os.environ.get('POSTGRES_PASSWORD'),
|
|
os.environ.get('POSTGRES_DB_NAME')
|
|
)
|
|
if not os.path.isfile('logs/nopaque.log'):
|
|
file_path = os.path.join(os.getcwd(), 'logs/nopaque.log')
|
|
log = open(file_path, 'w+')
|
|
log.close()
|
|
if os.environ.get('FLASK_CONFIG') == 'production':
|
|
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
|
|
"%(filename)s - %(lineno)d - %(message)s")
|
|
logging.basicConfig(filename='logs/nopaque.log', level='ERROR',
|
|
format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
|
|
filemode='w')
|
|
logger = logging.getLogger(__name__)
|
|
logger.error('Logging has started with level ERROR.'
|
|
' From production config.')
|
|
|
|
|
|
config = {
|
|
'development': DevelopmentConfig,
|
|
'testing': TestingConfig,
|
|
'production': ProductionConfig,
|
|
'default': DevelopmentConfig
|
|
}
|