This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
108 lines (81 loc) · 3.14 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import dateutil.parser
import distutils.util
import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
_logger = logging.getLogger(__name__)
class Config(object):
def __init__(self, database_url):
"""
Initialize the config.
Load the config values from the environment and do dynamic conversion.
"""
# Database connection
self.SECRET_KEY = str
# Flask-WTForms recaptcha.
self.RECAPTCHA_PUBLIC_KEY = str
self.RECAPTCHA_PRIVATE_KEY = str
# Google apps synchronization.
self.GOOGLE_SERVICE_EMAIL = str
self.GOOGLE_CALENDAR_ID = str
# Election dates.
self.ELECTIONS_NOMINATE_START = dateutil.parser.parse
self.ELECTIONS_VOTE_START = dateutil.parser.parse
self.ELECTIONS_VOTE_END = dateutil.parser.parse
# Git lab token for bug report.
self.GITLAB_TOKEN = str
# Mollie payment provider config.
self.MOLLIE_URL = str
self.MOLLIE_KEY = str
# Copernica e-mailing synchronization configuration.
self.COPERNICA_ENABLED = distutils.util.strtobool
self.COPERNICA_API_KEY = str
self.COPERNICA_DATABASE_ID = str
self.COPERNICA_ACTIEPUNTEN = str
self.COPERNICA_ACTIVITEITEN = str
self.COPERNICA_NEWSLETTER_TOKEN = str
# DOMJudge competition integration
self.DOMJUDGE_ADMIN_USERNAME = str
self.DOMJUDGE_ADMIN_PASSWORD = str
self.DOMJUDGE_URL = str
self.DOMJUDGE_USER_PASSWORD = str
# Sentry error capturing
self.SENTRY_DSN = str
self.SENTRY_DSN_FRONTEND = str
self.ENVIRONMENT = str
# URL for Athenaeum order page
self.ATHENAEUM_URL = str
# Privacy policy
self.PRIVACY_POLICY_URL_EN = str
self.PRIVACY_POLICY_URL_NL = str
# Path for SAML config and certificates
self.SAML_PATH = str
self.load_config(database_url=database_url)
# These must be defined after `load_config`, since they are not
# defined in the database.
self.RECAPTCHA_OPTIONS = {'theme': 'white'}
self.SENTRY_USER_ATTRS = ['name', 'email']
self.SENTRY_CONFIG = {
'environment': self.ENVIRONMENT
}
# Miscellaneous.
self.DEBUG_TB_INTERCEPT_REDIRECTS = False
self.SQLALCHEMY_TRACK_MODIFICATIONS = False
self.JSON_SORT_KEYS = False
# Authlib
self.OAUTH2_REFRESH_TOKEN_GENERATOR = True
def load_config(self, database_url):
engine = create_engine(database_url)
session = scoped_session(sessionmaker(bind=engine))
settings = {s[0]: s[1] for s in
session.execute("SELECT key, value FROM setting")}
for key in dir(self):
if not key.isupper():
continue
func = getattr(self, key)
if callable(func):
value = func(settings[key])
setattr(self, key, value)
_logger.info(f"{key} = {value}")
else:
_logger.info(f"{key} type not defined as callable.")