Commit 49cc5565 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Configuration with env vars

parent 2e136f4d
......@@ -7,39 +7,67 @@ import logging
import os
from hashlib import md5
from flask import Flask, request, Response
import configurations
import psycopg2
import gnupg
from version import __version__
import importlib
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s')
logger = logging.getLogger(__name__)
if os.getenv('RUNMODE') == 'production':
logger.setLevel(logging.INFO)
else:
logger.setLevel(logging.DEBUG)
# Loglevel can be overrinden by LOGLEVEL env var :
if os.getenv('DEBUG') == 'true':
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
application = Flask(__name__)
if 'RUNMODE' in os.environ:
try:
importlib.import_module('.'+os.environ.get('RUNMODE'), 'configurations')
application.config.from_object('configurations.'+os.environ.get('RUNMODE')+'.config')
except Exception as e:
raise e
# no configuration for this RUNMODE value
# For convenience, prepare configuration for RESIF RUNMODE
if os.getenv('RUNMODE') == 'production':
application.config['RESIFINV_PGUSER'] = "eidawsauth"
application.config['RESIFINV_PGHOST'] = "resif-pgprod.u-ga.fr"
application.config['RESIFINV_PGPORT'] = 5432
application.config['RESIFINV_PGDATABASE'] = "resifInv-Prod"
application.config['RESIFAUTH_PGUSER'] = "eidawsauth"
application.config['RESIFAUTH_PGHOST'] = "resif-pgprod.u-ga.fr"
application.config['RESIFAUTH_PGPORT'] = 5432
application.config['RESIFAUTH_PGDATABASE'] = "resifAuth"
elif os.getenv('RUNMODE') == 'preprod':
application.config['RESIFINV_PGUSER'] = "eidawsauth"
application.config['RESIFINV_PGHOST'] = "resif-pgpreprod.u-ga.fr"
application.config['RESIFINV_PGPORT'] = 5432
application.config['RESIFINV_PGDATABASE'] = "resifInv-Preprod"
application.config['RESIFAUTH_PGUSER'] = "eidawsauth"
application.config['RESIFAUTH_PGHOST'] = "resif-pgpreprod.u-ga.fr"
application.config['RESIFAUTH_PGPORT'] = 5432
application.config['RESIFAUTH_PGDATABASE'] = "resifAuth"
else:
application.config['RESIFINV_PGUSER'] = os.getenv('RESIFINV_PGUSER')
application.config['RESIFINV_PGHOST'] = os.getenv('RESIFINV_PGHOST')
application.config['RESIFINV_PGPORT'] = os.getenv('RESIFINV_PGPORT')
application.config['RESIFINV_PGDATABASE'] = os.getenv('RESIFINV_PGDATABASE')
application.config['RESIFAUTH_PGUSER'] = os.getenv('RESIFAUTH_PGUSER')
application.config['RESIFAUTH_PGHOST'] = os.getenv('RESIFAUTH_PGHOST')
application.config['RESIFAUTH_PGPORT'] = os.getenv('RESIFAUTH_PGPORT')
application.config['RESIFAUTH_PGDATABASE'] = os.getenv('RESIFAUTH_PGDATABASE')
# if PGPASS is provided, then use it for both database connection
if 'PGPASS' in os.environ:
application.config['RESIFINV_PGPASS'] = os.getenv('PGPASS')
application.config['RESIAUTH_PGPASS'] = os.getenv('PGPASS')
else:
application.config.from_object('configurations.default.config')
from logging.config import dictConfig
dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
}},
'handlers': {'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': application.config['LOGLEVEL'],
'handlers': ['wsgi']
}
})
application.config['RESIFINV_PGPASS'] = os.getenv('RESIFINV_PGPASS')
application.config['RESIAUTH_PGPASS'] = os.getenv('RESIAUTH_PGPASS')
application.config['GNUPG_HOMEDIR'] = os.getenv('GNUPG_HOMEDIR', '/gpghome')
application.config['SUPPORT_EMAIL'] = os.getenv('SUPPORT_EMAIL', 'resif-dc@univ-grenoble-alpes.fr')
application.config['EPOS_FDSN_MAP'] = {'/epos/alparray': {'networkcode':'Z3', 'startyear':2015, 'endyear': 2022}}
# Are we there now ?
def wsshash(login, password):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment