from werkzeug.middleware.proxy_fix import ProxyFix import logging import os ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) class Config: ''' # 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 # ''' SQLALCHEMY_RECORD_QUERIES = True SQLALCHEMY_TRACK_MODIFICATIONS = False ''' # Email # ''' MAIL_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER') MAIL_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD') MAIL_PORT = int(os.environ.get('NOPAQUE_SMTP_PORT')) MAIL_SERVER = os.environ.get('NOPAQUE_SMTP_SERVER') MAIL_USERNAME = os.environ.get('NOPAQUE_SMTP_USERNAME') 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' ''' # General # ''' ADMIN_EMAIL_ADRESS = os.environ.get('NOPAQUE_ADMIN_EMAIL_ADRESS') CONTACT_EMAIL_ADRESS = os.environ.get('NOPAQUE_CONTACT_EMAIL_ADRESS') DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque') SECRET_KEY = os.environ.get('NOPAQUE_SECRET_KEY', 'hard to guess string') ''' # Logging # ''' LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT', '%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}