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
This commit is contained in:
Alvaro Lopez Garcia 2017-03-31 13:34:36 +02:00
parent ddbe190568
commit 0549ee16cb
1 changed files with 7 additions and 0 deletions

View File

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