OLD | NEW |
1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI 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 """Main entry point for Swarming service. | 5 """Main entry point for Swarming service. |
6 | 6 |
7 This file contains the URL handlers for all the Swarming service URLs, | 7 This file contains the URL handlers for all the Swarming service URLs, |
8 implemented using the webapp2 framework. | 8 implemented using the webapp2 framework. |
9 """ | 9 """ |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 ### is_admin pages. | 49 ### is_admin pages. |
50 | 50 |
51 # TODO(maruel): Sort the handlers once they got their final name. | 51 # TODO(maruel): Sort the handlers once they got their final name. |
52 | 52 |
53 | 53 |
54 class RestrictedConfigHandler(auth.AuthenticatingHandler): | 54 class RestrictedConfigHandler(auth.AuthenticatingHandler): |
55 @auth.autologin | 55 @auth.autologin |
56 @auth.require(acl.is_admin) | 56 @auth.require(acl.is_admin) |
57 def get(self): | 57 def get(self): |
58 self.common(None) | 58 # Template parameters schema matches settings_info() return value. |
59 | 59 self.response.write(template.render( |
60 @staticmethod | 60 'swarming/restricted_config.html', config.settings_info())) |
61 def cast_to_type(param_name, value): | |
62 def to_bool(value): | |
63 if type(value) is bool: | |
64 return value | |
65 return {'True': True, 'False': False}.get(value, False) | |
66 | |
67 cast = { | |
68 'bot_death_timeout_secs': int, | |
69 'enable_ts_monitoring': to_bool, | |
70 'reusable_task_age_secs': int, | |
71 }.get(param_name, str) | |
72 return cast(value) | |
73 | |
74 @auth.require(acl.is_admin) | |
75 def post(self): | |
76 # Convert MultiDict into a dict. | |
77 params = { | |
78 k: self.cast_to_type(k, self.request.params.getone(k)) | |
79 for k in self.request.params | |
80 if k not in ('keyid', 'xsrf_token') | |
81 } | |
82 cfg = config.settings(fresh=True) | |
83 keyid = int(self.request.get('keyid', '0')) | |
84 if cfg.key.integer_id() != keyid: | |
85 self.common('Update conflict %s != %s' % (cfg.key.integer_id(), keyid)) | |
86 return | |
87 cfg.populate(**params) | |
88 cfg.store() | |
89 self.common('Settings updated') | |
90 | |
91 def common(self, note): | |
92 params = { | |
93 'cfg': config.settings(fresh=True), | |
94 'note': note, | |
95 'path': self.request.path, | |
96 'xsrf_token': self.generate_xsrf_token(), | |
97 } | |
98 self.response.write( | |
99 template.render('swarming/restricted_config.html', params)) | |
100 | 61 |
101 | 62 |
102 class UploadBotConfigHandler(auth.AuthenticatingHandler): | 63 class UploadBotConfigHandler(auth.AuthenticatingHandler): |
103 """Stores a new bot_config.py script.""" | 64 """Stores a new bot_config.py script.""" |
104 | 65 |
105 @auth.autologin | 66 @auth.autologin |
106 @auth.require(acl.is_admin) | 67 @auth.require(acl.is_admin) |
107 def get(self): | 68 def get(self): |
108 bot_config = bot_code.get_bot_config() | 69 bot_config = bot_code.get_bot_config() |
109 params = { | 70 params = { |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 # If running on a local dev server, allow bots to connect without prior | 789 # If running on a local dev server, allow bots to connect without prior |
829 # groups configuration. Useful when running smoke test. | 790 # groups configuration. Useful when running smoke test. |
830 if utils.is_local_dev_server(): | 791 if utils.is_local_dev_server(): |
831 acl.bootstrap_dev_server_acls() | 792 acl.bootstrap_dev_server_acls() |
832 | 793 |
833 # TODO(maruel): Split backend into a separate module. For now add routes here. | 794 # TODO(maruel): Split backend into a separate module. For now add routes here. |
834 routes.extend(handlers_backend.get_routes()) | 795 routes.extend(handlers_backend.get_routes()) |
835 routes.extend(handlers_bot.get_routes()) | 796 routes.extend(handlers_bot.get_routes()) |
836 | 797 |
837 return webapp2.WSGIApplication(routes, debug=debug) | 798 return webapp2.WSGIApplication(routes, debug=debug) |
OLD | NEW |