| 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 under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be 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 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 params['mapreduce_jobs'] = [ | 788 params['mapreduce_jobs'] = [ |
| 789 {'id': job_id, 'name': job_def['job_name']} | 789 {'id': job_id, 'name': job_def['job_name']} |
| 790 for job_id, job_def in mapreduce_jobs.MAPREDUCE_JOBS.iteritems() | 790 for job_id, job_def in mapreduce_jobs.MAPREDUCE_JOBS.iteritems() |
| 791 ] | 791 ] |
| 792 params['xsrf_token'] = self.generate_xsrf_token() | 792 params['xsrf_token'] = self.generate_xsrf_token() |
| 793 if acl.is_bootstrapper(): | 793 if acl.is_bootstrapper(): |
| 794 params['bootstrap_token'] = bot_code.generate_bootstrap_token() | 794 params['bootstrap_token'] = bot_code.generate_bootstrap_token() |
| 795 self.response.write(template.render('swarming/root.html', params)) | 795 self.response.write(template.render('swarming/root.html', params)) |
| 796 | 796 |
| 797 | 797 |
| 798 class BotsListHandler(auth.AuthenticatingHandler): | 798 class BotsListHandler(webapp2.RequestHandler): |
| 799 """Redirects to a list of known bots.""" | 799 """Redirects to a list of known bots.""" |
| 800 | 800 |
| 801 @auth.public | 801 @auth.public |
| 802 def get(self): | 802 def get(self): |
| 803 limit = int(self.request.get('limit', 100)) | 803 limit = int(self.request.get('limit', 100)) |
| 804 | 804 |
| 805 dimensions = ( | 805 dimensions = ( |
| 806 l.strip() for l in self.request.get('dimensions', '').splitlines() | 806 l.strip() for l in self.request.get('dimensions', '').splitlines() |
| 807 ) | 807 ) |
| 808 dimensions = [i for i in dimensions if i] | 808 dimensions = [i for i in dimensions if i] |
| 809 | 809 |
| 810 new_ui_link = '/botlist?l=%d' % limit | 810 new_ui_link = '/botlist?l=%d' % limit |
| 811 if dimensions: | 811 if dimensions: |
| 812 new_ui_link += '&f=' + '&f='.join(dimensions) | 812 new_ui_link += '&f=' + '&f='.join(dimensions) |
| 813 | 813 |
| 814 self.redirect(new_ui_link) | 814 self.redirect(new_ui_link) |
| 815 | 815 |
| 816 | 816 |
| 817 class BotHandler(auth.AuthenticatingHandler): | 817 class BotHandler(webapp2.RequestHandler): |
| 818 """Redirects to a page about the bot, including last tasks and events.""" | 818 """Redirects to a page about the bot, including last tasks and events.""" |
| 819 | 819 |
| 820 @auth.public | 820 @auth.public |
| 821 def get(self, bot_id): | 821 def get(self, bot_id): |
| 822 self.redirect('/bot?id=%s' % bot_id) | 822 self.redirect('/bot?id=%s' % bot_id) |
| 823 | 823 |
| 824 | 824 |
| 825 ### User accessible pages. | 825 ### User accessible pages. |
| 826 | 826 |
| 827 | 827 |
| 828 class TasksHandler(auth.AuthenticatingHandler): | 828 class TasksHandler(webapp2.RequestHandler): |
| 829 """Redirects to a list of all task requests.""" | 829 """Redirects to a list of all task requests.""" |
| 830 | 830 |
| 831 @auth.public | 831 @auth.public |
| 832 def get(self): | 832 def get(self): |
| 833 limit = int(self.request.get('limit', 100)) | 833 limit = int(self.request.get('limit', 100)) |
| 834 task_tags = [ | 834 task_tags = [ |
| 835 line for line in self.request.get('task_tag', '').splitlines() if line | 835 line for line in self.request.get('task_tag', '').splitlines() if line |
| 836 ] | 836 ] |
| 837 | 837 |
| 838 new_ui_link = '/tasklist?l=%d' % limit | 838 new_ui_link = '/tasklist?l=%d' % limit |
| 839 if task_tags: | 839 if task_tags: |
| 840 new_ui_link += '&f=' + '&f='.join(task_tags) | 840 new_ui_link += '&f=' + '&f='.join(task_tags) |
| 841 | 841 |
| 842 self.redirect(new_ui_link) | 842 self.redirect(new_ui_link) |
| 843 | 843 |
| 844 | 844 |
| 845 class TaskHandler(auth.AuthenticatingHandler): | 845 class TaskHandler(webapp2.RequestHandler): |
| 846 """Redirects to a page containing task request and result.""" | 846 """Redirects to a page containing task request and result.""" |
| 847 | 847 |
| 848 @auth.public | 848 @auth.public |
| 849 def get(self, task_id): | 849 def get(self, task_id): |
| 850 self.redirect('/task?id=%s' % task_id) | 850 self.redirect('/task?id=%s' % task_id) |
| 851 | 851 |
| 852 | 852 |
| 853 class UIHandler(auth.AuthenticatingHandler): | 853 class UIHandler(webapp2.RequestHandler): |
| 854 """Serves the landing page for the new UI of the requested page. | 854 """Serves the landing page for the new UI of the requested page. |
| 855 | 855 |
| 856 This landing page is stamped with the OAuth 2.0 client id from the | 856 This landing page is stamped with the OAuth 2.0 client id from the |
| 857 configuration.""" | 857 configuration.""" |
| 858 @auth.public | 858 @auth.public |
| 859 def get(self, page): | 859 def get(self, page): |
| 860 if not page: | 860 if not page: |
| 861 page = 'swarming' | 861 page = 'swarming' |
| 862 | 862 |
| 863 params = { | 863 params = { |
| 864 'client_id': config.settings().ui_client_id, | 864 'client_id': config.settings().ui_client_id, |
| 865 } | 865 } |
| 866 # Can cache for 1 week, because the only thing that would change in this |
| 867 # template is the oauth client id, which changes very infrequently. |
| 868 self.response.cache_control.no_cache = None |
| 869 self.response.cache_control.public = True |
| 870 self.response.cache_control.max_age = 604800 |
| 866 try: | 871 try: |
| 867 self.response.write(template.render( | 872 self.response.write(template.render( |
| 868 'swarming/public_%s_index.html' % page, params)) | 873 'swarming/public_%s_index.html' % page, params)) |
| 869 except template.TemplateNotFound: | 874 except template.TemplateNotFound: |
| 870 self.abort(404, 'Page not found.') | 875 self.abort(404, 'Page not found.') |
| 871 | 876 |
| 872 | 877 |
| 873 class WarmupHandler(webapp2.RequestHandler): | 878 class WarmupHandler(webapp2.RequestHandler): |
| 874 def get(self): | 879 def get(self): |
| 875 auth.warmup() | 880 auth.warmup() |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 | 942 |
| 938 # If running on a local dev server, allow bots to connect without prior | 943 # If running on a local dev server, allow bots to connect without prior |
| 939 # groups configuration. Useful when running smoke test. | 944 # groups configuration. Useful when running smoke test. |
| 940 if utils.is_local_dev_server(): | 945 if utils.is_local_dev_server(): |
| 941 acl.bootstrap_dev_server_acls() | 946 acl.bootstrap_dev_server_acls() |
| 942 | 947 |
| 943 routes.extend(handlers_backend.get_routes()) | 948 routes.extend(handlers_backend.get_routes()) |
| 944 routes.extend(handlers_bot.get_routes()) | 949 routes.extend(handlers_bot.get_routes()) |
| 945 routes.extend(handlers_endpoints.get_routes()) | 950 routes.extend(handlers_endpoints.get_routes()) |
| 946 return webapp2.WSGIApplication(routes, debug=debug) | 951 return webapp2.WSGIApplication(routes, debug=debug) |
| OLD | NEW |