-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_config.py
211 lines (166 loc) · 5.59 KB
/
app_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
"""
Project-wide application configuration.
DO NOT STORE SECRETS, PASSWORDS, ETC. IN THIS FILE.
They will be exposed to users. Use environment variables instead.
See get_secrets() below for a fast way to access them.
"""
import os
from authomatic.providers import oauth2
from authomatic import Authomatic
"""
NAMES
"""
# Project name used for display
PROJECT_NAME = 'Housing Guide'
PROJECT_SLUG = '2016-housing-guide'
# Project name to be used in file paths
PROJECT_FILENAME = '2016_housing_guide'
# The name of the repository containing the source
REPOSITORY_NAME = '2016-housing-guide'
GITHUB_USERNAME = 'northbynorthwestern'
REPOSITORY_URL = '[email protected]:%s/%s.git' % (GITHUB_USERNAME, REPOSITORY_NAME)
REPOSITORY_ALT_URL = None # '[email protected]:northbynorthwestern/%s.git' % REPOSITORY_NAME'
# Project name used for assets rig
# Should stay the same, even if PROJECT_SLUG changes
ASSETS_SLUG = '2015-housing-guide'
"""
DEPLOYMENT
"""
PRODUCTION_S3_BUCKETS = ['apps.northbynorthwestern.com']
STAGING_S3_BUCKETS = []
ASSETS_S3_BUCKET = []
PRODUCTION_SERVERS = ['cron.nprapps.org']
STAGING_SERVERS = ['50.112.92.131']
# Should code be deployed to the web/cron servers?
DEPLOY_TO_SERVERS = False
SERVER_USER = 'ubuntu'
SERVER_PYTHON = 'python2.7'
SERVER_PROJECT_PATH = '/home/%s/apps/%s' % (SERVER_USER, PROJECT_FILENAME)
SERVER_REPOSITORY_PATH = '%s/repository' % SERVER_PROJECT_PATH
SERVER_VIRTUALENV_PATH = '%s/virtualenv' % SERVER_PROJECT_PATH
# Should the crontab file be installed on the servers?
# If True, DEPLOY_TO_SERVERS must also be True
DEPLOY_CRONTAB = False
# Should the service configurations be installed on the servers?
# If True, DEPLOY_TO_SERVERS must also be True
DEPLOY_SERVICES = False
UWSGI_SOCKET_PATH = '/tmp/%s.uwsgi.sock' % PROJECT_FILENAME
UWSGI_LOG_PATH = '/var/log/%s.uwsgi.log' % PROJECT_FILENAME
APP_LOG_PATH = '/var/log/%s.app.log' % PROJECT_FILENAME
# Services are the server-side services we want to enable and configure.
# A three-tuple following this format:
# (service name, service deployment path, service config file extension)
SERVER_SERVICES = [
('app', SERVER_REPOSITORY_PATH, 'ini'),
('uwsgi', '/etc/init', 'conf'),
('nginx', '/etc/nginx/locations-enabled', 'conf'),
]
# These variables will be set at runtime. See configure_targets() below
S3_BUCKETS = []
S3_BASE_URL = ''
SERVERS = []
SERVER_BASE_URL = ''
DEBUG = True
DEFAULT_MAX_AGE = 20
"""
COPY EDITING
"""
COPY_GOOGLE_DOC_KEY = '1KhQ1WC-hW9R-ePXo28dV_vFrQ16qqn1u2_LGp_P5IMU'
COPY_PATH = 'data/copy.xlsx'
"""
OAUTH
"""
GOOGLE_OAUTH_CREDENTIALS_PATH = '~/.google_oauth_credentials'
authomatic_config = {
'google': {
'id': 1,
'class_': oauth2.Google,
'consumer_key': os.environ.get('GOOGLE_OAUTH_CLIENT_ID'),
'consumer_secret': os.environ.get('GOOGLE_OAUTH_CONSUMER_SECRET'),
'scope': ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email'],
'offline': True,
},
}
authomatic = Authomatic(authomatic_config, os.environ.get('AUTHOMATIC_SALT'))
"""
SHARING
"""
PROJECT_DESCRIPTION = "The North by Northwestern Freshman Housing Guide, featuring photos, videos, statistics and the opinions of current residents of Northwestern University's housing options."
SHARE_URL = 'http://%s/%s/' % (PRODUCTION_S3_BUCKETS[0], PROJECT_SLUG)
# Will be resized to 120x120, can't be larger than 1MB
TWITTER_IMAGE_URL = ''
TWITTER_HANDLE = '@nbn_tweets'
# 16:9 ("wide") image. FB uses 16:9 in the newsfeed and crops to square in timelines.
# No documented restrictions on size
FACEBOOK_IMAGE_URL = ''
FACEBOOK_APP_ID = ''
# Thumbnail image for Google News / Search.
# No documented restrictions on resolution or size
GOOGLE_IMAGE_URL = TWITTER_IMAGE_URL
NPR_DFP = {
'STORY_ID': '1002',
'TARGET': 'homepage',
'ENVIRONMENT': 'NPRTEST',
'TESTSERVER': 'false'
}
"""
SERVICES
"""
GOOGLE_ANALYTICS = {
'ACCOUNT_ID': 'UA-15143352-1',
'DOMAIN': PRODUCTION_S3_BUCKETS[0],
'TOPICS': '' # e.g. '[1014,3,1003,1002,1001]'
}
"""
Utilities
"""
def get_secrets():
"""
A method for accessing our secrets.
"""
secrets = [
'EXAMPLE_SECRET'
]
secrets_dict = {}
for secret in secrets:
name = '%s_%s' % (PROJECT_FILENAME, secret)
secrets_dict[secret] = os.environ.get(name, None)
return secrets_dict
def configure_targets(deployment_target):
"""
Configure deployment targets. Abstracted so this can be
overriden for rendering before deployment.
"""
global S3_BUCKETS
global S3_BASE_URL
global SERVERS
global SERVER_BASE_URL
global DEBUG
global DEPLOYMENT_TARGET
global APP_LOG_PATH
if deployment_target == 'production':
S3_BUCKETS = PRODUCTION_S3_BUCKETS
S3_BASE_URL = 'http://%s/%s' % (S3_BUCKETS[0], PROJECT_SLUG)
SERVERS = PRODUCTION_SERVERS
SERVER_BASE_URL = 'http://%s/%s' % (SERVERS[0], PROJECT_SLUG)
DEBUG = False
elif deployment_target == 'staging':
S3_BUCKETS = STAGING_S3_BUCKETS
S3_BASE_URL = 'http://%s/%s' % (S3_BUCKETS[0], PROJECT_SLUG)
SERVERS = STAGING_SERVERS
SERVER_BASE_URL = 'http://%s/%s' % (SERVERS[0], PROJECT_SLUG)
DEBUG = True
else:
S3_BUCKETS = []
S3_BASE_URL = 'http://127.0.0.1:8000'
SERVERS = []
SERVER_BASE_URL = 'http://127.0.0.1:8001/%s' % PROJECT_SLUG
DEBUG = True
APP_LOG_PATH = '/tmp/%s.app.log' % PROJECT_SLUG
DEPLOYMENT_TARGET = deployment_target
"""
Run automated configuration
"""
DEPLOYMENT_TARGET = os.environ.get('DEPLOYMENT_TARGET', None)
configure_targets(DEPLOYMENT_TARGET)