-
Bjarke Madsen authoredBjarke Madsen authored
config.py 1.68 KiB
import json
import jsonschema
CONFIG_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'type': 'object',
'properties': {
'SQLALCHEMY_DATABASE_URI': {'type': 'string', 'format': 'database-uri'},
'SURVEY_DATABASE_URI': {'type': 'string', 'format': 'database-uri'},
'oidc': {
'type': 'object',
'properties': {
'client_id': {'type': 'string'},
'client_secret': {'type': 'string'},
'server_metadata_url': {'type': 'string', 'format': 'uri', 'pattern': '^https?://'},
},
'required': ['client_id', 'client_secret', 'server_metadata_url'],
'additionalProperties': False
},
'mail': {
'type': 'object',
'properties': {
'MAIL_SERVER': {'type': 'string'},
'MAIL_PORT': {'type': 'integer'},
'MAIL_SENDER_EMAIL': {'type': 'string', 'format': 'email'},
'MAIL_EXCLUDED_ADMINS': {
'type': 'array',
'items': {'type': 'string', 'format': 'email'}
}
},
'required': ['MAIL_SERVER', 'MAIL_PORT', 'MAIL_SENDER_EMAIL'],
'additionalProperties': False
},
'SECRET_KEY': {'type': 'string'},
},
'required': ['SQLALCHEMY_DATABASE_URI', 'SURVEY_DATABASE_URI', 'SECRET_KEY'],
'additionalProperties': False
}
def load(f):
"""
loads, validates and returns configuration parameters
:param f: file-like object that produces the config file
:return:
"""
config = json.loads(f.read())
jsonschema.validate(config, CONFIG_SCHEMA)
return config