-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconfig.py
56 lines (45 loc) · 1.8 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
import glob
import os
from flask import Flask
from werkzeug.contrib.fixers import ProxyFix
from flask_sslify import SSLify
from foauth.providers import OAuthMeta
app = Flask(__name__)
app.secret_key = os.environ['SECRET_KEY']
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL')
app.config['DEBUG'] = 'DEBUG' in os.environ
app.wsgi_app = ProxyFix(app.wsgi_app)
if 'SSLIFY' in os.environ:
SSLify(app)
def get_service_modules():
for filename in glob.glob(os.path.join('services', '*.py')):
module_name = os.path.splitext(os.path.split(filename)[1])[0]
if not module_name.startswith('__'):
yield module_name
def get_oauth_providers(module_name):
module = getattr(__import__('services.%s' % module_name), module_name)
for name, obj in module.__dict__.items():
if isinstance(obj, OAuthMeta):
yield obj
services = []
for module_name in get_service_modules():
for service in get_oauth_providers(module_name):
alias = service.alias.upper()
if alias[0].isdigit():
key = os.environ.get('%s_KEY' % alias) or os.environ.get('_%s_KEY' % alias) or ''
secret = os.environ.get('%s_SECRET' % alias, '') or os.environ.get('_%s_SECRET' % alias, '') or ''
key = key.decode('utf8')
secret = secret.decode('utf8')
else:
key = os.environ.get('%s_KEY' % alias, '').decode('utf8')
secret = os.environ.get('%s_SECRET' % alias, '').decode('utf8')
if key and secret:
# Only initialize if all the pieces are in place
services.append(service(key, secret))
alias_map = {}
for service in services:
alias_map[service.alias] = service
domain_map = {}
for service in services:
for domain in service.api_domains:
domain_map[domain] = service