-
Notifications
You must be signed in to change notification settings - Fork 0
/
appengine_config.py
108 lines (87 loc) · 3.8 KB
/
appengine_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
from google.appengine.api import app_identity
import json
import mimetypes
import os
import sys
import yaml
from google.appengine.ext import vendor
vendor.add('lib')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
mimetypes.add_type('image/svg+xml', '.svg')
if 'JETWAY_CONFIG' in os.environ:
_config_path = os.getenv('JETWAY_CONFIG')
elif os.path.exists('config/jetway.yaml'):
_config_path = 'config/jetway.yaml'
else:
_config_path = 'config/jetway.yaml.example'
jetway_config = yaml.load(open(_config_path))
if os.path.exists('config/domain_access_users.txt'):
DOMAIN_ACCESS_USERS = open('config/domain_access_users.txt').read().split()
else:
DOMAIN_ACCESS_USERS = None
if os.environ.get('TESTING'):
service_account_key = json.load(open('testing/service_account_key.json'))
client_secrets_path = os.path.abspath('testing/client_secrets.json')
client_secrets = json.load(open(client_secrets_path))
elif jetway_config.get('app'):
_basename = jetway_config['app'].get('client_secrets_file', 'client_secrets.json')
client_secrets_path = os.path.abspath('config/{}'.format(_basename))
client_secrets = json.load(open(client_secrets_path))
_basename = jetway_config['app'].get('service_account_key_file', 'service_account_key.json')
service_account_key_path = os.path.abspath('config/{}'.format(_basename))
service_account_key = json.load(open(service_account_key_path))
else:
client_secrets_path = os.path.abspath('testing/client_secrets.json')
client_secrets = {'web': {'client_id': '12345', 'client_secret': '12345'}}
service_account_key = {'client_email': None}
ALLOWED_USER_DOMAINS = jetway_config.get('options', {}).get('allowed_user_domains', None)
DEFAULT_USER_DOMAINS = jetway_config.get('options', {}).get('default_user_domains', None)
REQUIRE_HTTPS_FOR_PREVIEWS = jetway_config.get('require_https', {}).get('preview_domain', False)
REQUIRE_HTTPS_FOR_APP = jetway_config.get('require_https', {}).get('app_domain', False)
GCS_SERVICE_ACCOUNT_EMAIL = service_account_key['client_email']
_appid = os.getenv('APPLICATION_ID').replace('s~', '')
_sender_name = 'WebReview'
_sender_address = 'noreply@{}.appspotmail.com'.format(_appid)
EMAIL_SENDER = '{} <{}>'.format(_sender_name, _sender_address)
IS_DEV_SERVER = os.getenv('SERVER_SOFTWARE', '').startswith('Dev')
def get_gcs_bucket():
if IS_DEV_SERVER:
return 'grow-prod.appspot.com'
return app_identity.get_default_gcs_bucket_name()
if os.environ.get('TESTING'):
PREVIEW_HOSTNAME = 'jetway-test.appspot.com'
elif IS_DEV_SERVER:
PREVIEW_HOSTNAME = jetway_config['urls']['hostname']['dev']
else:
PREVIEW_HOSTNAME = jetway_config['urls']['hostname']['prod']
BUILDBOT_API_KEY = jetway_config['app'].get('webreview_buildbot_api_key')
BUILDBOT_SERVICE_ACCOUNT = jetway_config['app'].get('webreview_buildbot_service_account')
BASE_URL = '{}://{}'.format(os.getenv('wsgi.url_scheme'), os.getenv('SERVER_NAME'))
if IS_DEV_SERVER:
BASE_URL += ':{}'.format(os.getenv('SERVER_PORT'))
VERSION = os.getenv('CURRENT_VERSION_ID', 'dev')
STATIC_ROOT = '/_app/{}/static'.format(VERSION)
STATIC_URL = BASE_URL + STATIC_ROOT
_token_age = 60 * 60 * 24 * 7 * 4 # 4 weeks.
WEBAPP2_AUTH_CONFIG = {
'webapp2_extras.auth': {
'user_model': 'jetway.users.users.User',
'token_max_age': _token_age,
'token_new_age': _token_age,
'token_cache_age': _token_age,
},
'webapp2_extras.sessions': {
'secret_key': str(client_secrets['web']['client_secret']),
'user_model': 'jetway.users.users.User',
},
}
if not IS_DEV_SERVER:
WEBAPP2_AUTH_CONFIG['webapp2_extras.sessions']['cookie_args'] = {
'secure': True
}
class OAuth(object):
CLIENT_ID = client_secrets['web']['client_id']
SCOPES = (
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
)