Allow configuring payload of noauth middleware

This adds the ability to return a catalog in the noauth middleware
response.

Change-Id: I5413ae4eadd5affdd1ae01678b61eafbe50b7919
Related-Bug: #1724263
This commit is contained in:
Thomas Herve 2017-10-18 13:57:54 +02:00
parent a532535b61
commit 800e0f3830
2 changed files with 19 additions and 0 deletions

View File

@ -369,6 +369,13 @@ volumes_opts = [
"This is a temporary workaround until cinder-backup "
"service becomes discoverable, see LP#1334856."))]
noauth_group = cfg.OptGroup('noauth')
noauth_opts = [
cfg.StrOpt('token_response',
default='',
help=_("JSON file containing the content returned by the "
"noauth middleware."))]
def startup_sanity_check():
if (not cfg.CONF.stack_user_domain_id and
@ -403,6 +410,7 @@ def list_opts():
yield auth_password_group.name, auth_password_opts
yield revision_group.name, revision_opts
yield volumes_group.name, volumes_opts
yield noauth_group.name, noauth_opts
yield profiler.list_opts()[0]
yield 'clients', default_clients_opts

View File

@ -16,6 +16,10 @@
"""Middleware that accepts any authentication."""
import json
import os
from oslo_config import cfg
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
@ -25,6 +29,11 @@ class NoAuthProtocol(object):
def __init__(self, app, conf):
self.conf = conf
self.app = app
self._token_info = {}
response_file = cfg.CONF.noauth.token_response
if os.path.exists(response_file):
with open(response_file) as f:
self._token_info = json.loads(f.read())
def __call__(self, env, start_response):
"""Handle incoming request.
@ -56,6 +65,8 @@ class NoAuthProtocol(object):
'HTTP_X_SERVICE_CATALOG': {},
'HTTP_X_AUTH_USER': username,
'HTTP_X_AUTH_KEY': 'unset',
'HTTP_X_AUTH_URL': 'url',
'keystone.token_info': self._token_info,
}
return headers