diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2015-01-09 16:17:50 +0100 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2015-01-09 16:17:50 +0100 |
commit | ebc6f9e06e9328eac55b55ea9d02ceb2c15ae4c0 (patch) | |
tree | 2d9db889c315a8c1a29a05a1fcf2fc7ca588903d | |
parent | d60be57f0cd61a5ccef5f79128dae7eeab7b3fbf (diff) |
Add /report[s] handler.
* Add new handler to retrieve email reports status information.
Change-Id: Iac0260cfab06e178c8d3b3ba51bce9f5e10d8a92
-rw-r--r-- | app/handlers/common.py | 13 | ||||
-rw-r--r-- | app/handlers/report.py | 68 | ||||
-rw-r--r-- | app/urls.py | 7 |
3 files changed, 88 insertions, 0 deletions
diff --git a/app/handlers/common.py b/app/handlers/common.py index 37c177e..ed6fdd8 100644 --- a/app/handlers/common.py +++ b/app/handlers/common.py @@ -297,6 +297,19 @@ LAB_VALID_KEYS = { ] } +REPORT_VALID_KEYS = { + "GET": [ + models.CREATED_KEY, + models.ID_KEY, + models.JOB_KEY, + models.KERNEL_KEY, + models.NAME_KEY, + models.STATUS_KEY, + models.TYPE_KEY, + models.UPDATED_KEY + ] +} + ID_KEYS = [ models.BOOT_ID_KEY, models.DEFCONFIG_ID_KEY, diff --git a/app/handlers/report.py b/app/handlers/report.py new file mode 100644 index 0000000..c13e0cd --- /dev/null +++ b/app/handlers/report.py @@ -0,0 +1,68 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""The RequestHandler for /report URLs.""" + +import handlers.base as hbase +import handlers.common as hcommon +import handlers.response as hresponse +import models + + +class ReportHandler(hbase.BaseHandler): + """Handle the /report[s] URLs.""" + + def __init__(self, application, request, **kwargs): + super(ReportHandler, self).__init__(application, request, **kwargs) + + @property + def collection(self): + return self.db[models.REPORT_COLLECTION] + + @staticmethod + def _valid_keys(method): + return hcommon.REPORT_VALID_KEYS.get(method, None) + + @staticmethod + def _token_validation_func(): + return hcommon.valid_token_th + + def execute_delete(self, *args, **kwargs): + """Perform DELETE pre-operations. + + Check that the DELETE request is OK. + """ + response = None + + if self.validate_req_token("DELETE"): + response = hresponse.HandlerResponse(501) + else: + response = hresponse.HandlerResponse(403) + response.reason = hcommon.NOT_VALID_TOKEN + + return response + + def execute_post(self, *args, **kwargs): + """Execute the POST pre-operations. + + Checks that everything is OK to perform a POST. + """ + response = None + + if self.validate_req_token("POST"): + response = hresponse.HandlerResponse(501) + else: + response = hresponse.HandlerResponse(403) + response.reason = hcommon.NOT_VALID_TOKEN + + return response diff --git a/app/urls.py b/app/urls.py index 269e15f..a5b9c3b 100644 --- a/app/urls.py +++ b/app/urls.py @@ -24,6 +24,7 @@ import handlers.count import handlers.defconf import handlers.job import handlers.lab +import handlers.report import handlers.subscription import handlers.token import handlers.version @@ -65,6 +66,11 @@ _LAB_URL = url( _VERSION_URL = url( r"/version", handlers.version.VersionHandler, name="version" ) +_REPORT_URL = url( + r"/report[s]?(?P<sl>/)?(?P<id>.*)", + handlers.report.ReportHandler, + name="response" +) APP_URLS = [ _BATCH_URL, @@ -77,4 +83,5 @@ APP_URLS = [ _SUBSCRIPTION_URL, _TOKEN_URL, _VERSION_URL, + _REPORT_URL, ] |