Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 from ConfigParser import SafeConfigParser | 3 from ConfigParser import SafeConfigParser |
4 import hashlib | 4 import hashlib |
5 import hmac | 5 import hmac |
6 import json | 6 import json |
7 import os | 7 import os |
8 import re | 8 import re |
9 import sys | 9 import sys |
10 import urllib | 10 import urllib |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 196 |
197 response.set_email(email) | 197 response.set_email(email) |
198 response.set_user_id(user_id) | 198 response.set_user_id(user_id) |
199 response.set_auth_domain(user_service_stub._DEFAULT_AUTH_DOMAIN) | 199 response.set_auth_domain(user_service_stub._DEFAULT_AUTH_DOMAIN) |
200 response.set_is_admin(is_admin) | 200 response.set_is_admin(is_admin) |
201 response.set_client_id(client_id) | 201 response.set_client_id(client_id) |
202 response.add_scopes(OAUTH2_SCOPE) | 202 response.add_scopes(OAUTH2_SCOPE) |
203 | 203 |
204 user_service_stub.UserServiceStub._Dynamic_GetOAuthUser = _Dynamic_GetOAuthUse r | 204 user_service_stub.UserServiceStub._Dynamic_GetOAuthUser = _Dynamic_GetOAuthUse r |
205 | 205 |
206 def dispatch_tasks_to_user_port(): | 206 def fix_target_resolution(): |
Sebastian Noack
2015/06/23 09:40:27
This function name is inaccurate. This function do
Wladimir Palant
2015/06/23 09:53:09
I'd rather go with fix_target_resolution().
mathias
2015/06/23 10:13:18
Done.
mathias
2015/06/23 10:13:18
Done.
| |
207 """ | 207 """ |
208 By default, the dispatcher assumes port 80 for target authorities that | 208 By default, the dispatcher assumes port 80 for target authorities that |
209 only contain a hostname but no port part. This hard-coded behavior is | 209 only contain a hostname but no port part. This hard-coded behavior is |
210 altered in function dispatch_tasks_to_user_port() so that the port given | 210 altered in function fix_target_resolution() so that the port given |
211 as --port option to the appserver-script is used instead. Without this | 211 as --port option to the appserver-script is used instead. Without this |
212 monkey-patch, dispatching tasks from an application run behind a HTTP | 212 monkey-patch, dispatching tasks from an application run behind a HTTP |
213 proxy server on port 80 will fail, because applications will omit the | 213 proxy server on port 80 (or HTTPS on 443) will fail, because |
214 default port when addressing resources. | 214 applications will omit the default port when addressing resources. |
215 """ | 215 """ |
216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher | 216 from google.appengine.tools.devappserver2.dispatcher import Dispatcher |
217 resolve_target = Dispatcher._resolve_target | 217 orig_resolve_target = Dispatcher._resolve_target |
218 | 218 |
219 def callback(dispatcher, authority, path): | 219 def resolve_target(dispatcher, hostname, path): |
Sebastian Noack
2015/06/23 09:40:27
It's arguable whether a method override should be
Wladimir Palant
2015/06/23 09:53:09
Also, please keep the parameter names of the origi
mathias
2015/06/23 10:13:17
Done.
mathias
2015/06/23 10:13:17
Done.
| |
220 hostname, port = authority.split(":") if ":" in authority else (authority, d ispatcher._port) | 220 new_hostname = hostname if ":" in hostname else "%s:%d" % (hostname, dispatc her._port) |
Sebastian Noack
2015/06/23 09:40:27
It seems that the logic here can be simplified:
Wladimir Palant
2015/06/23 09:53:10
Actually, that's not quite it. The dispatcher assu
mathias
2015/06/23 10:13:18
Overwriting function arguments is something I cons
mathias
2015/06/23 10:13:18
It's not 443 either, we do not allow unauthorized
Sebastian Noack
2015/06/23 11:34:05
I don't think that a bogus dislike of overwriting
mathias
2015/06/23 11:53:45
Again labeling something bogus without any rationa
Sebastian Noack
2015/06/23 12:00:23
Interesting, since labeling something "bad practic
| |
221 new_authority = "%s:%d" % (hostname, port) | 221 result = orig_resolve_target(dispatcher, new_hostname, path) |
222 result = resolve_target(dispatcher, new_authority, path) | |
223 return result | 222 return result |
Wladimir Palant
2015/06/23 09:53:10
Nit: drop the intermediate result variable?
ret
mathias
2015/06/23 10:32:42
Again something I consider bad practice. Without t
Sebastian Noack
2015/06/23 11:34:05
Frankly, I agree with Wladimir here. Bloating your
mathias
2015/06/23 11:53:45
Let me point out at "bloating" is way over the top
Wladimir Palant
2015/06/23 11:58:07
Yes, this is primarily a matter of opinion which i
| |
224 | 223 |
225 Dispatcher._resolve_target = callback | 224 Dispatcher._resolve_target = resolve_target |
226 | 225 |
227 if __name__ == '__main__': | 226 if __name__ == '__main__': |
228 engine_dir = '/opt/google_appengine' | 227 engine_dir = '/opt/google_appengine' |
229 storage_path = '/var/lib/rietveld' | 228 storage_path = '/var/lib/rietveld' |
230 | 229 |
231 script_name, script_file = setup_paths(engine_dir) | 230 script_name, script_file = setup_paths(engine_dir) |
232 adjust_server_id() | 231 adjust_server_id() |
233 fix_request_scheme() | 232 fix_request_scheme() |
234 | 233 |
235 if script_name == 'dev_appserver.py': | 234 if script_name == 'dev_appserver.py': |
236 config = read_config(os.path.join(storage_path, 'config.ini')) | 235 config = read_config(os.path.join(storage_path, 'config.ini')) |
237 | 236 |
238 set_storage_path(storage_path) | 237 set_storage_path(storage_path) |
239 replace_runtime() | 238 replace_runtime() |
240 protect_cookies(config.get('main', 'cookie_secret')) | 239 protect_cookies(config.get('main', 'cookie_secret')) |
241 enable_oauth2( | 240 enable_oauth2( |
242 config.get('oauth2', 'client_id'), | 241 config.get('oauth2', 'client_id'), |
243 config.get('oauth2', 'client_secret'), | 242 config.get('oauth2', 'client_secret'), |
244 config.get('main', 'admins').split() | 243 config.get('main', 'admins').split() |
245 ) | 244 ) |
246 dispatch_tasks_to_user_port() | 245 fix_target_resolution() |
247 | 246 |
248 execfile(script_file) | 247 execfile(script_file) |
LEFT | RIGHT |