Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2012 The Swarming Authors. All rights reserved. | 1 # Copyright 2012 The Swarming Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """This module defines Isolate Server frontend url handlers.""" | 5 """This module defines Isolate Server frontend url handlers.""" |
| 6 | 6 |
| 7 import datetime | 7 import datetime |
| 8 import json | 8 import json |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 ### Restricted handlers | 57 ### Restricted handlers |
| 58 | 58 |
| 59 | 59 |
| 60 class RestrictedConfigHandler(auth.AuthenticatingHandler): | 60 class RestrictedConfigHandler(auth.AuthenticatingHandler): |
| 61 @auth.autologin | 61 @auth.autologin |
| 62 @auth.require(auth.is_admin) | 62 @auth.require(auth.is_admin) |
| 63 def get(self): | 63 def get(self): |
| 64 self.common(None) | 64 self.common(None) |
| 65 | 65 |
| 66 @staticmethod | |
| 67 def cast_to_type(param_name, value): | |
| 68 def to_bool(value): | |
| 69 if type(value) is bool: | |
| 70 return value | |
| 71 return {'True': True, 'False': False}.get(value, False) | |
| 72 | |
| 73 def to_str(value): | |
|
M-A Ruel
2016/02/19 20:51:49
Remove.
Sergey Berezin
2016/02/19 23:20:34
Done.
| |
| 74 return str(value) | |
| 75 | |
| 76 cast = { | |
| 77 'enable_ts_monitoring': to_bool, | |
| 78 }.get(param_name, to_str) | |
|
M-A Ruel
2016/02/19 20:51:49
s/to_str/str/
Sergey Berezin
2016/02/19 23:20:34
Good catch, thx! done.
| |
| 79 return cast(value) | |
| 80 | |
| 66 @auth.require(auth.is_admin) | 81 @auth.require(auth.is_admin) |
| 67 def post(self): | 82 def post(self): |
| 68 # Convert MultiDict into a dict. | 83 # Convert MultiDict into a dict. |
| 69 params = { | 84 params = { |
| 70 k: self.request.params.getone(k) for k in self.request.params | 85 k: self.cast_to_type(k, self.request.params.getone(k)) |
| 86 for k in self.request.params | |
| 71 if k not in ('keyid', 'xsrf_token') | 87 if k not in ('keyid', 'xsrf_token') |
| 72 } | 88 } |
| 73 cfg = config.settings(fresh=True) | 89 cfg = config.settings(fresh=True) |
| 74 keyid = int(self.request.get('keyid', '0')) | 90 keyid = int(self.request.get('keyid', '0')) |
| 75 if cfg.key.integer_id() != keyid: | 91 if cfg.key.integer_id() != keyid: |
| 76 self.common('Update conflict %s != %s' % (cfg.key.integer_id(), keyid)) | 92 self.common('Update conflict %s != %s' % (cfg.key.integer_id(), keyid)) |
| 77 return | 93 return |
| 78 params['default_expiration'] = int(params['default_expiration']) | 94 params['default_expiration'] = int(params['default_expiration']) |
| 79 cfg.populate(**params) | 95 cfg.populate(**params) |
| 80 try: | 96 try: |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 def create_application(debug): | 316 def create_application(debug): |
| 301 """Creates the url router. | 317 """Creates the url router. |
| 302 | 318 |
| 303 The basic layouts is as follow: | 319 The basic layouts is as follow: |
| 304 - /restricted/.* requires being an instance administrator. | 320 - /restricted/.* requires being an instance administrator. |
| 305 - /stats/.* has statistics. | 321 - /stats/.* has statistics. |
| 306 """ | 322 """ |
| 307 acl.bootstrap() | 323 acl.bootstrap() |
| 308 template.bootstrap() | 324 template.bootstrap() |
| 309 return webapp2.WSGIApplication(get_routes(), debug=debug) | 325 return webapp2.WSGIApplication(get_routes(), debug=debug) |
| OLD | NEW |