| 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 cast = { |
| 74 'enable_ts_monitoring': to_bool, |
| 75 }.get(param_name, str) |
| 76 return cast(value) |
| 77 |
| 66 @auth.require(auth.is_admin) | 78 @auth.require(auth.is_admin) |
| 67 def post(self): | 79 def post(self): |
| 68 # Convert MultiDict into a dict. | 80 # Convert MultiDict into a dict. |
| 69 params = { | 81 params = { |
| 70 k: self.request.params.getone(k) for k in self.request.params | 82 k: self.cast_to_type(k, self.request.params.getone(k)) |
| 83 for k in self.request.params |
| 71 if k not in ('keyid', 'xsrf_token') | 84 if k not in ('keyid', 'xsrf_token') |
| 72 } | 85 } |
| 73 cfg = config.settings(fresh=True) | 86 cfg = config.settings(fresh=True) |
| 74 keyid = int(self.request.get('keyid', '0')) | 87 keyid = int(self.request.get('keyid', '0')) |
| 75 if cfg.key.integer_id() != keyid: | 88 if cfg.key.integer_id() != keyid: |
| 76 self.common('Update conflict %s != %s' % (cfg.key.integer_id(), keyid)) | 89 self.common('Update conflict %s != %s' % (cfg.key.integer_id(), keyid)) |
| 77 return | 90 return |
| 78 params['default_expiration'] = int(params['default_expiration']) | 91 params['default_expiration'] = int(params['default_expiration']) |
| 79 cfg.populate(**params) | 92 cfg.populate(**params) |
| 80 try: | 93 try: |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 def create_application(debug): | 313 def create_application(debug): |
| 301 """Creates the url router. | 314 """Creates the url router. |
| 302 | 315 |
| 303 The basic layouts is as follow: | 316 The basic layouts is as follow: |
| 304 - /restricted/.* requires being an instance administrator. | 317 - /restricted/.* requires being an instance administrator. |
| 305 - /stats/.* has statistics. | 318 - /stats/.* has statistics. |
| 306 """ | 319 """ |
| 307 acl.bootstrap() | 320 acl.bootstrap() |
| 308 template.bootstrap() | 321 template.bootstrap() |
| 309 return webapp2.WSGIApplication(get_routes(), debug=debug) | 322 return webapp2.WSGIApplication(get_routes(), debug=debug) |
| OLD | NEW |