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-08 10:34:02 +00:00
|
|
|
root_dir = os.path.abspath(os.path.dirname(__file__))
|
2019-09-05 08:12:40 +00:00
|
|
|
|
2019-07-03 13:40:09 +00:00
|
|
|
|
2020-10-08 10:47:47 +00:00
|
|
|
DEFAULT_DATA_DIR = os.path.join('/mnt/nopaque')
|
2020-10-08 10:34:02 +00:00
|
|
|
DEFAULT_DB_PORT = '5432'
|
|
|
|
DEFAULT_DEBUG = 'False'
|
|
|
|
DEFAULT_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
|
|
DEFAULT_LOG_FILE = os.path.join(root_dir, 'nopaque.log')
|
|
|
|
DEFAULT_LOG_FORMAT = ('[%(asctime)s] %(levelname)s in %(pathname)s '
|
|
|
|
'(function: %(funcName)s, line: %(lineno)d): '
|
|
|
|
'%(message)s')
|
|
|
|
DEFAULT_LOG_LEVEL = 'ERROR'
|
|
|
|
DEFAULT_SMTP_USE_SSL = 'False'
|
|
|
|
DEFAULT_SMTP_USE_TLS = 'False'
|
|
|
|
DEFAULT_NUM_PROXIES = '0'
|
|
|
|
DEFAULT_PROTOCOL = 'http'
|
2020-10-09 12:43:23 +00:00
|
|
|
DEFAULT_REMEMBER_COOKIE_HTTPONLY = 'True'
|
|
|
|
DEFAULT_REMEMBER_COOKIE_SECURE = 'False'
|
2020-10-08 10:34:02 +00:00
|
|
|
DEFAULT_SECRET_KEY = 'hard to guess string'
|
2020-10-09 12:43:23 +00:00
|
|
|
DEFAULT_SESSION_COOKIE_SECURE = 'False'
|
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:
|
|
|
|
''' ### Database ### '''
|
|
|
|
DB_HOST = os.environ.get('NOPAQUE_DB_HOST')
|
|
|
|
DB_NAME = os.environ.get('NOPAQUE_DB_NAME')
|
|
|
|
DB_PASSWORD = os.environ.get('NOPAQUE_DB_PASSWORD')
|
|
|
|
DB_PORT = os.environ.get('NOPAQUE_DB_PORT', DEFAULT_DB_PORT)
|
|
|
|
DB_USERNAME = os.environ.get('NOPAQUE_DB_USERNAME')
|
|
|
|
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@{}:{}/{}'.format(
|
|
|
|
DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
|
|
|
|
SQLALCHEMY_RECORD_QUERIES = True
|
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
2020-06-17 07:26:37 +00:00
|
|
|
|
2020-10-08 10:34:02 +00:00
|
|
|
''' ### Email ### '''
|
|
|
|
MAIL_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER')
|
|
|
|
MAIL_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD')
|
|
|
|
MAIL_PORT = 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',
|
|
|
|
DEFAULT_SMTP_USE_SSL).lower() == 'true'
|
|
|
|
MAIL_USE_TLS = os.environ.get('NOPAQUE_SMTP_USE_TLS',
|
|
|
|
DEFAULT_SMTP_USE_TLS).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', DEFAULT_DATA_DIR)
|
|
|
|
DEBUG = os.environ.get('NOPAQUE_DEBUG', DEFAULT_DEBUG).lower() == 'true'
|
|
|
|
NUM_PROXIES = int(os.environ.get('NOPAQUE_NUM_PROXIES',
|
|
|
|
DEFAULT_NUM_PROXIES))
|
|
|
|
PROTOCOL = os.environ.get('NOPAQUE_PROTOCOL', DEFAULT_PROTOCOL)
|
2020-10-09 12:43:23 +00:00
|
|
|
REMEMBER_COOKIE_HTTPONLY = os.environ.get(
|
|
|
|
'NOPAQUE_REMEMBER_COOKIE_HTTPONLY',
|
|
|
|
DEFAULT_REMEMBER_COOKIE_HTTPONLY
|
|
|
|
).lower() == 'true'
|
|
|
|
REMEMBER_COOKIE_SECURE = os.environ.get(
|
|
|
|
'NOPAQUE_REMEMBER_COOKIE_SECURE',
|
|
|
|
DEFAULT_REMEMBER_COOKIE_SECURE
|
|
|
|
).lower() == 'true'
|
|
|
|
SECRET_KEY = os.environ.get('RECIPY_SECRET_KEY', DEFAULT_SECRET_KEY)
|
|
|
|
SESSION_COOKIE_SECURE = os.environ.get(
|
|
|
|
'NOPAQUE_SESSION_COOKIE_SECURE',
|
|
|
|
DEFAULT_SESSION_COOKIE_SECURE
|
|
|
|
).lower() == 'true'
|
2020-06-17 07:26:37 +00:00
|
|
|
|
2020-10-08 10:34:02 +00:00
|
|
|
''' ### Logging ### '''
|
|
|
|
LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT',
|
|
|
|
DEFAULT_LOG_DATE_FORMAT)
|
|
|
|
LOG_FILE = os.environ.get('NOPAQUE_LOG_FILE', DEFAULT_LOG_FILE)
|
|
|
|
LOG_FORMAT = os.environ.get('NOPAQUE_LOG_FORMAT', DEFAULT_LOG_FORMAT)
|
|
|
|
LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', DEFAULT_LOG_LEVEL)
|
|
|
|
|
|
|
|
''' ### Message queue ### '''
|
|
|
|
MQ_HOST = os.environ.get('NOPAQUE_MQ_HOST')
|
|
|
|
MQ_PORT = os.environ.get('NOPAQUE_MQ_PORT')
|
|
|
|
MQ_TYPE = os.environ.get('NOPAQUE_MQ_TYPE')
|
|
|
|
SOCKETIO_MESSAGE_QUEUE_URI = \
|
|
|
|
'{}://{}:{}/'.format(MQ_TYPE, MQ_HOST, MQ_PORT)
|
|
|
|
|
|
|
|
def init_app(self, app):
|
|
|
|
# Configure logging according to the corresponding (LOG_*) config
|
|
|
|
# entries
|
|
|
|
logging.basicConfig(datefmt=self.LOG_DATE_FORMAT,
|
|
|
|
filename=self.LOG_FILE,
|
|
|
|
format=self.LOG_FORMAT,
|
|
|
|
level=self.LOG_LEVEL)
|
|
|
|
# Apply the ProxyFix middleware if nopaque is running behind reverse
|
|
|
|
# proxies. (NUM_PROXIES indicates the number of reverse proxies running
|
|
|
|
# in front of nopaque)
|
|
|
|
if self.NUM_PROXIES > 0:
|
|
|
|
app.wsgi_app = ProxyFix(app.wsgi_app,
|
|
|
|
x_for=self.NUM_PROXIES,
|
|
|
|
x_host=self.NUM_PROXIES,
|
|
|
|
x_port=self.NUM_PROXIES,
|
|
|
|
x_proto=self.NUM_PROXIES)
|