Fix auth middleware configuration
Initialze the configuration object before initializing the middleware, and pass the resulting config in to the middleware so it can get the configuration settings. addresses bug #1071047 Change-Id: I2a487d2a2f2d3467e522868ac78dc4645bf7d643 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
parent
015c7cdc92
commit
085fa79ec0
@ -20,14 +20,30 @@
|
|||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ceilometer.api.app import app
|
from ceilometer.api import acl
|
||||||
|
from ceilometer.api import app
|
||||||
from ceilometer.openstack.common import cfg
|
from ceilometer.openstack.common import cfg
|
||||||
from ceilometer.openstack.common import log as logging
|
from ceilometer.openstack.common import log as logging
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# Register keystone middleware option before
|
||||||
|
# parsing the config file and command line
|
||||||
|
# inputs.
|
||||||
|
acl.register_opts(cfg.CONF)
|
||||||
|
|
||||||
|
# Parse config file and command line options,
|
||||||
|
# then configure logging.
|
||||||
cfg.CONF(sys.argv[1:])
|
cfg.CONF(sys.argv[1:])
|
||||||
logging.setup('ceilometer.api')
|
logging.setup('ceilometer.api')
|
||||||
|
|
||||||
|
root = app.app
|
||||||
|
|
||||||
|
# Enable debug mode
|
||||||
if cfg.CONF.verbose or cfg.CONF.debug:
|
if cfg.CONF.verbose or cfg.CONF.debug:
|
||||||
app.debug = True
|
root.debug = True
|
||||||
app.run(host='0.0.0.0', port=cfg.CONF.metering_api_port)
|
|
||||||
|
# Install the middleware wrapper
|
||||||
|
root = acl.install(root, cfg.CONF)
|
||||||
|
|
||||||
|
root.run(host='0.0.0.0', port=cfg.CONF.metering_api_port)
|
||||||
|
@ -18,22 +18,27 @@
|
|||||||
"""Set up the ACL to acces the API server."""
|
"""Set up the ACL to acces the API server."""
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from ceilometer.openstack.common import cfg
|
|
||||||
from ceilometer import policy
|
from ceilometer import policy
|
||||||
|
|
||||||
import keystone.middleware.auth_token
|
import keystone.middleware.auth_token
|
||||||
|
|
||||||
# Register keystone middleware option
|
|
||||||
cfg.CONF.register_opts(keystone.middleware.auth_token.opts,
|
def register_opts(conf):
|
||||||
group='keystone_authtoken')
|
"""Register keystone middleware options
|
||||||
keystone.middleware.auth_token.CONF = cfg.CONF
|
"""
|
||||||
|
conf.register_opts(keystone.middleware.auth_token.opts,
|
||||||
|
group='keystone_authtoken',
|
||||||
|
)
|
||||||
|
keystone.middleware.auth_token.CONF = conf
|
||||||
|
|
||||||
|
|
||||||
def install(app):
|
def install(app, conf):
|
||||||
"""Install ACL check on application."""
|
"""Install ACL check on application."""
|
||||||
app.wsgi_app = keystone.middleware.auth_token.AuthProtocol(app.wsgi_app,
|
app.wsgi_app = keystone.middleware.auth_token.AuthProtocol(app.wsgi_app,
|
||||||
{})
|
conf=conf,
|
||||||
|
)
|
||||||
app.before_request(check)
|
app.before_request(check)
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
|
@ -24,7 +24,6 @@ from ceilometer.openstack.common import cfg
|
|||||||
from ceilometer.openstack.common import jsonutils
|
from ceilometer.openstack.common import jsonutils
|
||||||
from ceilometer import storage
|
from ceilometer import storage
|
||||||
from ceilometer.api import v1
|
from ceilometer.api import v1
|
||||||
from ceilometer.api import acl
|
|
||||||
|
|
||||||
|
|
||||||
app = flask.Flask('ceilometer.api')
|
app = flask.Flask('ceilometer.api')
|
||||||
@ -45,6 +44,3 @@ def attach_config():
|
|||||||
def attach_sources():
|
def attach_sources():
|
||||||
with open("sources.json", "r") as f:
|
with open("sources.json", "r") as f:
|
||||||
flask.request.sources = jsonutils.load(f)
|
flask.request.sources = jsonutils.load(f)
|
||||||
|
|
||||||
|
|
||||||
acl.install(app)
|
|
||||||
|
@ -26,7 +26,7 @@ class TestAPIACL(tests_api.TestBase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAPIACL, self).setUp()
|
super(TestAPIACL, self).setUp()
|
||||||
acl.install(self.app)
|
acl.install(self.app, {})
|
||||||
|
|
||||||
def test_non_authenticated(self):
|
def test_non_authenticated(self):
|
||||||
with self.app.test_request_context('/'):
|
with self.app.test_request_context('/'):
|
||||||
|
Loading…
Reference in New Issue
Block a user