![Eric Barrett](/assets/img/avatar_default.png)
Flake8 currently ignores do not use mutable default arguments error Enable B006 for more thorough testing of code Change-Id: I5b08a56f945158c3b3c23574c048363e59da6001 Story: 2004515 Task: 30172 Signed-off-by: Eric Barrett <eric.barrett@windriver.com>
39 lines
1017 B
Python
39 lines
1017 B
Python
#
|
|
# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
# -*- encoding: utf-8 -*-
|
|
#
|
|
|
|
from keystonemiddleware import auth_token
|
|
|
|
from sm_api.common import utils
|
|
|
|
|
|
class AuthTokenMiddleware(auth_token.AuthProtocol):
|
|
"""A wrapper on Keystone auth_token middleware.
|
|
|
|
Does not perform verification of authentication tokens
|
|
for public routes in the API.
|
|
|
|
"""
|
|
|
|
def __init__(self, app, conf, public_api_routes=None):
|
|
self.smapi_app = app
|
|
if public_api_routes is None:
|
|
public_api_routes = []
|
|
self.public_api_routes = set(public_api_routes)
|
|
|
|
super(AuthTokenMiddleware, self).__init__(app, conf)
|
|
|
|
def __call__(self, env, start_response):
|
|
path = utils.safe_rstrip(env.get('PATH_INFO'), '/')
|
|
|
|
if path in self.public_api_routes:
|
|
return self.smapi_app(env, start_response)
|
|
|
|
return super(AuthTokenMiddleware, self).__call__(env, start_response)
|