autoland-webapi: move the repos route to its own file in anticipation of it growing (bug 1343662). r?mars draft
authorSteven MacLeod <smacleod@mozilla.com>
Wed, 01 Mar 2017 16:46:48 -0500
changeset 311 379e4d3bdf85f58e93459a2742733716676fab3c
parent 298 aa672fb8a9c0faa7af7131954643858da83bba2b
child 312 e95e09e66b9ea858b0f5240cb4087ed279e004c8
push id144
push userbmo:smacleod@mozilla.com
push dateTue, 07 Mar 2017 15:57:30 +0000
reviewersmars
bugs1343662
autoland-webapi: move the repos route to its own file in anticipation of it growing (bug 1343662). r?mars The repos endpoint is going to start acting like it will in production which means it will grow considerably in complexity. Move it to its own file to not clutter up routes.py MozReview-Commit-ID: 2xvNCUpcc6z
autoland/webapi/autolandweb/repos.py
autoland/webapi/autolandweb/routes.py
new file mode 100644
--- /dev/null
+++ b/autoland/webapi/autolandweb/repos.py
@@ -0,0 +1,36 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import tornado.httpclient
+import tornado.web
+
+
+class ReposHandler(tornado.web.RequestHandler):
+    """Handler for repositories."""
+
+    async def get(self, repo=None):
+        if repo is None:
+            return
+
+        http = tornado.httpclient.AsyncHTTPClient()
+        # FIXME: We don't validate the user input here!  Security problem?
+        repo_url = self.settings['reviewboard_url'] + '/repos/' + repo
+        # FIXME: Should the user agent be configurable or a constant?
+        response = await http.fetch(
+            repo_url,
+            headers={'Accept': 'application/json'},
+            user_agent='autoland tornado AsyncHTTPClient',
+            raise_error=False
+        )
+
+        # Handle HTTP response codes.  3XX codes have already been handled
+        # and followed by the tornado HTTP client.
+        if response.code == 200:
+            self.set_status(200)
+        elif response.code == 404:
+            self.set_status(404)
+            self.write({'error': 'Repo not found'})
+        else:
+            # Everything not 2XX or 404 is an exception.
+            response.rethrow()
--- a/autoland/webapi/autolandweb/routes.py
+++ b/autoland/webapi/autolandweb/routes.py
@@ -1,54 +1,25 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import tornado.httpclient
 import tornado.web
 
 from autolandweb.dockerflow import DOCKERFLOW_ROUTES
+from autolandweb.repos import ReposHandler
 from autolandweb.series import get_series_status
 
 
 class MainHandler(tornado.web.RequestHandler):
     def get(self):
         self.write('Hello, from Autoland')
 
 
-class ReposHandler(tornado.web.RequestHandler):
-    """Handler for repositories."""
-
-    async def get(self, repo=None):
-        if repo is None:
-            return
-
-        http = tornado.httpclient.AsyncHTTPClient()
-        # FIXME: We don't validate the user input here!  Security problem?
-        repo_url = self.settings['reviewboard_url'] + '/repos/' + repo
-        # FIXME: Should the user agent be configurable or a constant?
-        response = await http.fetch(
-            repo_url,
-            headers={'Accept': 'application/json'},
-            user_agent='autoland tornado AsyncHTTPClient',
-            raise_error=False
-        )
-
-        # Handle HTTP response codes.  3XX codes have already been handled
-        # and followed by the tornado HTTP client.
-        if response.code == 200:
-            self.set_status(200)
-        elif response.code == 404:
-            self.set_status(404)
-            self.write({'error': 'Repo not found'})
-        else:
-            # Everything not 2XX or 404 is an exception.
-            response.rethrow()
-
-
 class SeriesHandler(tornado.web.RequestHandler):
     """Handler for series'."""
 
     async def get(self, repo, series=None):
         if series is None:
             self.write({})
             return