From 0549ee16cb52d46bdc598943e2fa985ad9442339 Mon Sep 17 00:00:00 2001 From: Alvaro Lopez Garcia Date: Fri, 31 Mar 2017 13:34:36 +0200 Subject: [PATCH] Check if project id is None from headers To check if the user was providing a scoped token we were relying on the "HTTP_X_PROJECT_ID" environment variable, relying on a KeyError exception when accessing the dictionary. However, the variable can be empty, resulting in a dictionary key "HTTP_X_PROJECT_ID":None. As a consequence, we were using None as the project ID, resulting in misleading errors. Closes-bug: #1678060 Change-Id: I1956fd99be5771371b1d3401e335528c5cc6455e --- ooi/api/helpers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ooi/api/helpers.py b/ooi/api/helpers.py index 45611df..35d873e 100644 --- a/ooi/api/helpers.py +++ b/ooi/api/helpers.py @@ -256,6 +256,13 @@ class OpenStackHelper(BaseHelper): } } + @staticmethod + def tenant_from_req(req): + project_id = req.environ.get("HTTP_X_PROJECT_ID", None) + if project_id is not None: + return project_id + raise exception.Forbidden(reason="Cannot find project ID in the token") + def _get_index_req(self, req): tenant_id = self.tenant_from_req(req) path = "/%s/servers" % tenant_id