Add config option to override url for versions
The versions url returns the wrong data when glance api is behind a proxy. This adds a new config option so it can be set properly. DocImpact Change-Id: I5ab53d608a6667435a4b03b0c832870716baaeb8 Closes-Bug: #1384379
This commit is contained in:
parent
633bec8fd4
commit
fa3b691011
|
@ -22,7 +22,17 @@ import webob.dec
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
|
|
||||||
|
|
||||||
|
versions_opts = [
|
||||||
|
cfg.StrOpt('public_endpoint', default=None,
|
||||||
|
help=_('Public url to use for versions endpoint. The default '
|
||||||
|
'is None, which will use the request\'s host_url '
|
||||||
|
'attribute to populate the URL base. If Glance is '
|
||||||
|
'operating behind a proxy, you will want to change '
|
||||||
|
'this to represent the proxy\'s URL.')),
|
||||||
|
]
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
CONF.register_opts(versions_opts)
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
|
@ -32,13 +42,14 @@ class Controller(object):
|
||||||
def index(self, req):
|
def index(self, req):
|
||||||
"""Respond to a request for all OpenStack API versions."""
|
"""Respond to a request for all OpenStack API versions."""
|
||||||
def build_version_object(version, path, status):
|
def build_version_object(version, path, status):
|
||||||
|
url = CONF.public_endpoint or req.host_url
|
||||||
return {
|
return {
|
||||||
'id': 'v%s' % version,
|
'id': 'v%s' % version,
|
||||||
'status': status,
|
'status': status,
|
||||||
'links': [
|
'links': [
|
||||||
{
|
{
|
||||||
'rel': 'self',
|
'rel': 'self',
|
||||||
'href': '%s/%s/' % (req.host_url, path),
|
'href': '%s/%s/' % (url, path),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,49 @@ class VersionsTest(base.IsolatedUnitTest):
|
||||||
]
|
]
|
||||||
self.assertEqual(expected, results)
|
self.assertEqual(expected, results)
|
||||||
|
|
||||||
|
def test_get_version_list_public_endpoint(self):
|
||||||
|
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
|
||||||
|
req.accept = 'application/json'
|
||||||
|
self.config(bind_host='127.0.0.1', bind_port=9292,
|
||||||
|
public_endpoint='https://example.com:9292')
|
||||||
|
res = versions.Controller().index(req)
|
||||||
|
self.assertEqual(300, res.status_int)
|
||||||
|
self.assertEqual('application/json', res.content_type)
|
||||||
|
results = jsonutils.loads(res.body)['versions']
|
||||||
|
expected = [
|
||||||
|
{
|
||||||
|
'id': 'v2.2',
|
||||||
|
'status': 'CURRENT',
|
||||||
|
'links': [{'rel': 'self',
|
||||||
|
'href': 'https://example.com:9292/v2/'}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'v2.1',
|
||||||
|
'status': 'SUPPORTED',
|
||||||
|
'links': [{'rel': 'self',
|
||||||
|
'href': 'https://example.com:9292/v2/'}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'v2.0',
|
||||||
|
'status': 'SUPPORTED',
|
||||||
|
'links': [{'rel': 'self',
|
||||||
|
'href': 'https://example.com:9292/v2/'}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'v1.1',
|
||||||
|
'status': 'CURRENT',
|
||||||
|
'links': [{'rel': 'self',
|
||||||
|
'href': 'https://example.com:9292/v1/'}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'v1.0',
|
||||||
|
'status': 'SUPPORTED',
|
||||||
|
'links': [{'rel': 'self',
|
||||||
|
'href': 'https://example.com:9292/v1/'}],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
self.assertEqual(expected, results)
|
||||||
|
|
||||||
|
|
||||||
class VersionNegotiationTest(base.IsolatedUnitTest):
|
class VersionNegotiationTest(base.IsolatedUnitTest):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue