nopaque/config.py

95 lines
3.2 KiB
Python
Raw Normal View History

2019-07-03 08:31:23 +00:00
import os
2019-09-11 12:50:29 +00:00
import logging
2019-07-03 08:31:23 +00:00
class Config:
2019-09-05 08:12:40 +00:00
''' ### Flask ### '''
SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
''' ### Flask-Mail ### '''
2019-08-26 07:57:26 +00:00
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'
2019-07-08 09:29:11 +00:00
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
2019-09-05 08:12:40 +00:00
''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_RECORD_QUERIES = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
2019-07-03 13:40:09 +00:00
''' ### nopaque ### '''
2019-12-02 10:34:28 +00:00
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
NOPAQUE_CONTACT = os.environ.get('NOPAQUE_CONTACT')
NOPAQUE_MAIL_SENDER = os.environ.get('NOPAQUE_MAIL_SENDER')
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
2020-04-09 05:57:52 +00:00
NOPAQUE_STORAGE = os.environ.get('NOPAQUE_STORAGE')
2019-09-05 08:12:40 +00:00
2019-07-03 13:40:09 +00:00
@staticmethod
def init_app(app):
pass
class DevelopmentConfig(Config):
2019-09-05 08:12:40 +00:00
''' ### Flask ### '''
2019-07-03 13:40:09 +00:00
DEBUG = True
2019-09-05 08:12:40 +00:00
''' ### Flask-SQLAlchemy ### '''
2019-09-06 11:42:47 +00:00
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@db/{}'.format(
2019-09-05 14:39:50 +00:00
os.environ.get('POSTGRES_USER'),
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME'))
2019-12-02 13:24:33 +00:00
if not os.path.isfile('logs/nopaque.log'):
file_path = os.path.join(os.getcwd(), 'logs/nopaque.log')
2019-09-12 09:35:23 +00:00
log = open(file_path, 'w+')
log.close()
2019-09-12 14:44:53 +00:00
if os.environ.get('FLASK_CONFIG') == 'development':
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
"%(filename)s - %(lineno)d - %(message)s")
2019-12-02 13:24:33 +00:00
logging.basicConfig(filename='logs/nopaque.log', level='WARNING',
2019-09-12 14:44:53 +00:00
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.')
2019-07-03 13:40:09 +00:00
class TestingConfig(Config):
2019-09-05 14:39:50 +00:00
''' ### Flask ### '''
TESTING = True
''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = 'sqlite://'
2019-09-05 14:39:50 +00:00
''' ### Flask-WTF ### '''
WTF_CSRF_ENABLED = False
2019-09-05 08:12:40 +00:00
class ProductionConfig(Config):
''' ### Flask-SQLAlchemy ### '''
2019-09-06 11:42:47 +00:00
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@db/{}'.format(
2019-09-05 14:39:50 +00:00
os.environ.get('POSTGRES_USER'),
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME')
)
2019-12-02 13:24:33 +00:00
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()
2019-09-12 14:44:53 +00:00
if os.environ.get('FLASK_CONFIG') == 'production':
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
"%(filename)s - %(lineno)d - %(message)s")
2019-12-02 13:24:33 +00:00
logging.basicConfig(filename='logs/nopaque.log', level='ERROR',
2019-09-12 14:44:53 +00:00
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.')
2019-07-03 13:40:09 +00:00
config = {
'development': DevelopmentConfig,
2019-07-08 08:52:36 +00:00
'testing': TestingConfig,
2019-09-05 08:12:40 +00:00
'production': ProductionConfig,
2019-07-03 13:40:09 +00:00
'default': DevelopmentConfig
}