Use application_url in API version document

This handles the possible vhost in Glance API path correctly
(like https://cloud.example.com/image) contrary to host_url.

Change-Id: If86d805ddc46944e3aa2785aa5d775fe15b8468c
Closes-Bug: #1823703
This commit is contained in:
Vlad Gusev 2019-04-08 15:49:16 +03:00
parent 8649fdc2a2
commit 33626369e5
2 changed files with 17 additions and 2 deletions

View File

@ -17,6 +17,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from six.moves import http_client
from six.moves import urllib
import webob.dec
from glance.common import wsgi
@ -59,14 +60,17 @@ class Controller(object):
def index(self, req, explicit=False):
"""Respond to a request for all OpenStack API versions."""
def build_version_object(version, path, status):
url = CONF.public_endpoint or req.host_url
url = CONF.public_endpoint or req.application_url
# Always add '/' to url end for urljoin href url
url = url.rstrip('/') + '/'
href = urllib.parse.urljoin(url, path).rstrip('/') + '/'
return {
'id': 'v%s' % version,
'status': status,
'links': [
{
'rel': 'self',
'href': '%s/%s/' % (url, path),
'href': '%s' % href,
},
],
}

View File

@ -135,6 +135,17 @@ class VersionsTest(base.IsolatedUnitTest):
expected = self._get_versions_list(ssl_url)
self.assertEqual(expected, results)
def test_get_version_list_for_external_app(self):
url = 'http://customhost:9292/app/api'
req = webob.Request.blank('/', base_url=url)
self.config(bind_host='127.0.0.1', bind_port=9292)
res = versions.Controller().index(req)
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions']
expected = self._get_versions_list(url)
self.assertEqual(expected, results)
class VersionNegotiationTest(base.IsolatedUnitTest):