Fix enabling authentication via --config
Because of an ordering problem, the configuration file provided via --config (as opposed to environment) is read after WSGI is set up. This change fixes it by moving Application configuration into a new method. Change-Id: I3b69e148f2f82704d636ebdea88e5c86a483f86e
This commit is contained in:
parent
7688392865
commit
cb10724139
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixes authentication when the configuration is provided via the
|
||||||
|
``--config`` option (as opposed to the environment).
|
|
@ -74,18 +74,20 @@ class RedfishAuthMiddleware(auth_basic.BasicAuthMiddleware):
|
||||||
|
|
||||||
class Application(flask.Flask):
|
class Application(flask.Flask):
|
||||||
|
|
||||||
def __init__(self, extra_config=None):
|
def __init__(self):
|
||||||
super().__init__(__name__)
|
super().__init__(__name__)
|
||||||
# Turn off strict_slashes on all routes
|
# Turn off strict_slashes on all routes
|
||||||
self.url_map.strict_slashes = False
|
self.url_map.strict_slashes = False
|
||||||
config_file = os.environ.get('SUSHY_EMULATOR_CONFIG')
|
|
||||||
|
def configure(self, config_file=None, extra_config=None):
|
||||||
|
config_file = config_file or os.environ.get('SUSHY_EMULATOR_CONFIG')
|
||||||
if config_file:
|
if config_file:
|
||||||
self.config.from_pyfile(config_file)
|
self.config.from_pyfile(config_file)
|
||||||
if extra_config:
|
if extra_config:
|
||||||
self.config.update(extra_config)
|
self.config.update(extra_config)
|
||||||
|
|
||||||
auth_file = self.config.get("SUSHY_EMULATOR_AUTH_FILE")
|
auth_file = self.config.get("SUSHY_EMULATOR_AUTH_FILE")
|
||||||
if auth_file:
|
if auth_file and not isinstance(self.wsgi_app, RedfishAuthMiddleware):
|
||||||
self.wsgi_app = RedfishAuthMiddleware(self.wsgi_app, auth_file)
|
self.wsgi_app = RedfishAuthMiddleware(self.wsgi_app, auth_file)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -768,8 +770,7 @@ def main():
|
||||||
|
|
||||||
app.debug = args.debug
|
app.debug = args.debug
|
||||||
|
|
||||||
if args.config:
|
app.configure(config_file=args.config)
|
||||||
app.config.from_pyfile(args.config)
|
|
||||||
|
|
||||||
if args.os_cloud:
|
if args.os_cloud:
|
||||||
app.config['SUSHY_EMULATOR_OS_CLOUD'] = args.os_cloud
|
app.config['SUSHY_EMULATOR_OS_CLOUD'] = args.os_cloud
|
||||||
|
|
|
@ -65,8 +65,9 @@ class AuthenticatedTestCase(base.BaseTestCase):
|
||||||
self.auth_file.write(TEST_PASSWD)
|
self.auth_file.write(TEST_PASSWD)
|
||||||
self.auth_file.flush()
|
self.auth_file.flush()
|
||||||
self.addCleanup(self.auth_file.close)
|
self.addCleanup(self.auth_file.close)
|
||||||
app = main.Application({
|
app = main.Application()
|
||||||
'SUSHY_EMULATOR_AUTH_FILE': self.auth_file.name})
|
app.configure(
|
||||||
|
extra_config={'SUSHY_EMULATOR_AUTH_FILE': self.auth_file.name})
|
||||||
self.app = app.test_client()
|
self.app = app.test_client()
|
||||||
|
|
||||||
def test_root_resource(self):
|
def test_root_resource(self):
|
||||||
|
|
Loading…
Reference in New Issue