Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 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 import httplib | 5 import httplib |
| 6 | 6 |
| 7 import webapp2 | 7 import webapp2 |
| 8 | 8 |
| 9 from components import decorators | 9 from components import decorators |
| 10 from components.config.proto import service_config_pb2 | 10 from components.config.proto import service_config_pb2 |
| 11 from google.appengine.ext.webapp import template | |
| 11 | 12 |
| 12 import common | 13 import common |
| 13 import gitiles_import | 14 import gitiles_import |
| 14 import notifications | 15 import notifications |
| 16 import os | |
| 15 import storage | 17 import storage |
| 16 | 18 |
| 17 | 19 |
| 18 class CronGitilesImport(webapp2.RequestHandler): | 20 class CronGitilesImport(webapp2.RequestHandler): |
| 19 """Imports configs from Gitiles.""" | 21 """Imports configs from Gitiles.""" |
| 20 @decorators.require_cronjob | 22 @decorators.require_cronjob |
| 21 def get(self): | 23 def get(self): |
| 22 gitiles_import.cron_run_import() | 24 gitiles_import.cron_run_import() |
| 23 | 25 |
| 24 | 26 |
| 25 class MainPageHandler(webapp2.RequestHandler): | 27 class MainPageHandler(webapp2.RequestHandler): |
| 26 """Redirects to API Explorer.""" | 28 """Redirects to API Explorer.""" |
| 27 | 29 |
| 28 def get(self): | 30 def get(self): |
| 29 self.redirect('_ah/api/explorer') | 31 self.redirect('_ah/api/explorer') |
| 30 | 32 |
| 33 class UIHandler(webapp2.RequestHandler): | |
| 34 """ Serves the UI with the proper client ID. """ | |
| 35 | |
| 36 def get(self): | |
| 37 template_values = { | |
| 38 'client_id': | |
| 39 '247108661754-svmo17vmk1j5hlt388gb45qblgvg2h98.apps.googleusercontent. com' | |
|
Sergey Berezin
2017/06/29 23:52:53
nit: let's add a TODO to make this configurable.
cwpayton
2017/06/30 00:12:48
Done.
| |
| 40 } | |
| 41 path = os.path.join(os.path.dirname(__file__), 'ui/static/index.html') | |
| 42 self.response.out.write(template.render(path, template_values)) | |
| 43 | |
| 31 | 44 |
| 32 class SchemasHandler(webapp2.RequestHandler): | 45 class SchemasHandler(webapp2.RequestHandler): |
| 33 """Redirects to a known schema definition.""" | 46 """Redirects to a known schema definition.""" |
| 34 | 47 |
| 35 def get(self, name): | 48 def get(self, name): |
| 36 cfg = storage.get_self_config_async( | 49 cfg = storage.get_self_config_async( |
| 37 common.SCHEMAS_FILENAME, service_config_pb2.SchemasCfg).get_result() | 50 common.SCHEMAS_FILENAME, service_config_pb2.SchemasCfg).get_result() |
| 38 # Assume cfg was validated by validation.py | 51 # Assume cfg was validated by validation.py |
| 39 if cfg: | 52 if cfg: |
| 40 for schema in cfg.schemas: | 53 for schema in cfg.schemas: |
| 41 if schema.name == name: | 54 if schema.name == name: |
| 42 # Convert from unicode. | 55 # Convert from unicode. |
| 43 assert schema.url | 56 assert schema.url |
| 44 self.redirect(str(schema.url)) | 57 self.redirect(str(schema.url)) |
| 45 return | 58 return |
| 46 | 59 |
| 47 self.response.write('Schema %s not found\n' % name) | 60 self.response.write('Schema %s not found\n' % name) |
| 48 self.response.set_status(httplib.NOT_FOUND) | 61 self.response.set_status(httplib.NOT_FOUND) |
| 49 | 62 |
| 50 | 63 |
| 51 def get_frontend_routes(): # pragma: no cover | 64 def get_frontend_routes(): # pragma: no cover |
| 52 return [ | 65 return [ |
| 53 webapp2.Route(r'/', MainPageHandler), | 66 webapp2.Route(r'/', MainPageHandler), |
| 67 webapp2.Route(r'/newui', UIHandler), | |
| 54 webapp2.Route(r'/schemas/<name:.+>', SchemasHandler), | 68 webapp2.Route(r'/schemas/<name:.+>', SchemasHandler), |
| 55 webapp2.Route(r'/_ah/bounce', notifications.BounceHandler), | 69 webapp2.Route(r'/_ah/bounce', notifications.BounceHandler), |
| 56 ] | 70 ] |
| 57 | 71 |
| 58 | 72 |
| 59 def get_backend_routes(): # pragma: no cover | 73 def get_backend_routes(): # pragma: no cover |
| 60 return [ | 74 return [ |
| 61 webapp2.Route( | 75 webapp2.Route( |
| 62 r'/internal/cron/luci-config/gitiles_import', | 76 r'/internal/cron/luci-config/gitiles_import', |
| 63 CronGitilesImport), | 77 CronGitilesImport), |
| 64 ] | 78 ] |
| OLD | NEW |