From aa4f3aba179020c0e9e42e8c01e97d30749787e1 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 16 Nov 2018 10:08:27 -0800 Subject: [PATCH] Fix the version discovery document In Queens the API version discovery document did not include the "links" section. This is causing problems with newer versions of the openstacksdk. This patch addes the "links" section to the version discovery document. Change-Id: Id791339a912a15aa6dded31ce22baedb253c78a0 Story: 2004368 Task: 27970 --- octavia/api/root_controller.py | 57 ++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/octavia/api/root_controller.py b/octavia/api/root_controller.py index bb7d06405..1b43bc43c 100644 --- a/octavia/api/root_controller.py +++ b/octavia/api/root_controller.py @@ -15,6 +15,7 @@ import logging from oslo_config import cfg +from pecan import request as pecan_request from pecan import rest from wsme import types as wtypes from wsmeext import pecan as wsme_pecan @@ -33,33 +34,49 @@ class RootController(rest.RestController): def __init__(self): super(RootController, self).__init__() - self._versions = [] - v1_enabled = CONF.api_settings.api_v1_enabled - v2_enabled = CONF.api_settings.api_v2_enabled - if v1_enabled: + self.v1_enabled = CONF.api_settings.api_v1_enabled + self.v2_enabled = CONF.api_settings.api_v2_enabled + if self.v1_enabled: self.v1 = v1_controller.V1Controller() - self._versions.append( - { - 'status': 'SUPPORTED', - 'updated': '2014-12-11T00:00:00Z', - 'id': 'v1' - }) - if v2_enabled: + if self.v2_enabled: setattr(self, 'v2.0', v2_controller.V2Controller()) - self._versions.append( - { - 'status': 'CURRENT', - 'updated': '2017-06-22T00:00:00Z', - 'id': 'v2.0' - }) - if not (v1_enabled or v2_enabled): + if not (self.v1_enabled or self.v2_enabled): LOG.warning("Both v1 and v2.0 API endpoints are disabled -- is " "this intentional?") - elif v1_enabled and v2_enabled: + elif self.v1_enabled and self.v2_enabled: LOG.warning("Both v1 and v2.0 API endpoints are enabled -- it is " "a security risk to expose the v1 endpoint publicly," "so please make sure access to it is secured.") @wsme_pecan.wsexpose(wtypes.text) def get(self): - return {'versions': self._versions} + host_url = pecan_request.path_url + + if not host_url.endswith('/'): + host_url = '{}/'.format(host_url) + + versions = [] + if CONF.api_settings.api_v1_enabled: + versions.append( + { + 'status': 'SUPPORTED', + 'updated': '2014-12-11T00:00:00Z', + 'id': 'v1', + 'links': [{ + 'href': host_url + 'v1', + 'rel': 'self' + }] + }) + if CONF.api_settings.api_v2_enabled: + versions.append( + { + 'status': 'CURRENT', + 'updated': '2017-06-22T00:00:00Z', + 'id': 'v2.0', + 'links': [{ + 'href': host_url + 'v2.0', + 'rel': 'self' + }] + }) + + return {'versions': versions}