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
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