Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: appengine/swarming/handlers_frontend.py

Issue 1926443003: swarming: read configs from luci-config (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: unlint Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 cfg, rev, rev_url = config.settings_info()
59
60 @staticmethod
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 = { 59 params = {
78 k: self.cast_to_type(k, self.request.params.getone(k)) 60 'cfg': cfg,
79 for k in self.request.params 61 'rev': rev,
80 if k not in ('keyid', 'xsrf_token') 62 'rev_url': rev_url,
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 } 63 }
98 self.response.write( 64 self.response.write(
99 template.render('swarming/restricted_config.html', params)) 65 template.render('swarming/restricted_config.html', params))
100 66
101 67
102 class UploadBotConfigHandler(auth.AuthenticatingHandler): 68 class UploadBotConfigHandler(auth.AuthenticatingHandler):
103 """Stores a new bot_config.py script.""" 69 """Stores a new bot_config.py script."""
104 70
105 @auth.autologin 71 @auth.autologin
106 @auth.require(acl.is_admin) 72 @auth.require(acl.is_admin)
107 def get(self): 73 def get(self):
108 bot_config = bot_code.get_bot_config() 74 bot_config = bot_code.get_bot_config()
109 params = { 75 params = {
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 # If running on a local dev server, allow bots to connect without prior 794 # If running on a local dev server, allow bots to connect without prior
829 # groups configuration. Useful when running smoke test. 795 # groups configuration. Useful when running smoke test.
830 if utils.is_local_dev_server(): 796 if utils.is_local_dev_server():
831 acl.bootstrap_dev_server_acls() 797 acl.bootstrap_dev_server_acls()
832 798
833 # TODO(maruel): Split backend into a separate module. For now add routes here. 799 # TODO(maruel): Split backend into a separate module. For now add routes here.
834 routes.extend(handlers_backend.get_routes()) 800 routes.extend(handlers_backend.get_routes())
835 routes.extend(handlers_bot.get_routes()) 801 routes.extend(handlers_bot.get_routes())
836 802
837 return webapp2.WSGIApplication(routes, debug=debug) 803 return webapp2.WSGIApplication(routes, debug=debug)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698