Fix 500 errors in the API when request context bears no project_id

This fixes 500 errors in the API that appeared when keystone authentication is
enabled, the request contexts bears no project_id, and the user doesn't have
admin rights.

This specific case did lead to badly built filters (with project_id being
None), which induced unexpected behaviour from the storage backend.

Change-Id: I62b416183f7841c4ca3f934022e90751a80b833f
Story: 2006948
Task: 37629
This commit is contained in:
Luka Peschke 2019-11-26 14:33:39 +01:00
parent 3426a6648a
commit af0613f4c6
5 changed files with 22 additions and 0 deletions

View File

@ -62,6 +62,9 @@ class DataFramesController(rest.RestController):
if pecan.request.context.is_admin:
filters = {scope_key: tenant_id} if tenant_id else None
else:
# Unscoped non-admin user
if project_id is None:
return {'dataframes': []}
filters = {scope_key: project_id}
try:
resp = backend.retrieve(

View File

@ -84,6 +84,12 @@ class DataFrameList(base.BaseResource):
metric_types = None
if not flask.request.context.is_admin:
if flask.request.context.project_id is None:
# Unscoped non-admin user
return {
'total': 0,
'dataframes': []
}
scope_key = CONF.collect.scope_key
if filters:
filters[scope_key] = flask.request.context.project_id

View File

@ -45,6 +45,13 @@ class Summary(base.BaseResource):
end = end or tzutils.get_next_month()
if not flask.request.context.is_admin:
if flask.request.context.project_id is None:
# Unscoped non-admin user
return {
'total': 0,
'columns': [],
'results': [],
}
filters['project_id'] = flask.request.context.project_id
metric_types = [filters.pop('type')] if 'type' in filters else None

View File

@ -161,6 +161,7 @@ class InfluxClient(object):
@staticmethod
def _get_filter(key, value):
format_string = ''
if isinstance(value, six.string_types):
format_string = """"{}"='{}'"""
elif isinstance(value, (six.integer_types, float)):

View File

@ -0,0 +1,5 @@
---
fixes:
- |
The 500 errors happening on some API endpoints when keystone authentication
is enabled and the request context bears no ``project_id`` have been fixed.