diff --git a/glare/api/middleware/version_negotiation.py b/glare/api/middleware/version_negotiation.py index f102ba0..f816922 100644 --- a/glare/api/middleware/version_negotiation.py +++ b/glare/api/middleware/version_negotiation.py @@ -67,9 +67,7 @@ class GlareVersionNegotiationFilter(base_middleware.ConfigurableMiddleware): # determine if this is request for versions if req.path_info in ('/versions', '/'): - is_multi = req.path_info == '/' - return artifacts_versions.Controller.index( - req, is_multi=is_multi) + return artifacts_versions.Controller.index(req) # determine api version from request req_version = GlareVersionNegotiationFilter.get_version_from_accept( diff --git a/glare/api/v1/api_version_request.py b/glare/api/v1/api_version_request.py index b32ab75..af9c194 100644 --- a/glare/api/v1/api_version_request.py +++ b/glare/api/v1/api_version_request.py @@ -20,6 +20,10 @@ from glare.i18n import _ REST_API_VERSION_HISTORY = """REST API Version History: + * 1.1 Added dynamic quotas API request. Added a possibility to delete blobs + with external locations. Added a possibility to define system locations to + blobs. + * 1.0 - First stable API version that supports microversion. If API version is not specified in the request then API v1.0 is used as default API version. @@ -33,7 +37,7 @@ class APIVersionRequest(object): """ _MIN_API_VERSION = "1.0" - _MAX_API_VERSION = "1.0" + _MAX_API_VERSION = "1.1" _DEFAULT_API_VERSION = "1.0" def __init__(self, version_string): diff --git a/glare/api/versions.py b/glare/api/versions.py index de24aef..9ea0f02 100644 --- a/glare/api/versions.py +++ b/glare/api/versions.py @@ -18,7 +18,6 @@ from oslo_serialization import jsonutils from six.moves import http_client import webob.dec -from glare.api.v1 import api_version_request from glare.i18n import _ @@ -52,45 +51,39 @@ Related options: CONF = cfg.CONF CONF.register_opts(versions_opts) +_LINKS = [{ + "rel": "describedby", + "type": "text/html", + "href": "http://docs.openstack.org/", +}] + class Controller(object): - """A controller that reports which API versions are supported.""" + """A controller that reports which API versions are there.""" @staticmethod - def index(req, is_multi): - """Respond to a request for all OpenStack API versions. + def index(req): + """Respond to a request for all OpenStack Glare API versions. - :param is_multi: defines if multiple choices should be response status - or not :param req: user request object :return: list of supported API versions """ - def build_version_object(max_version, min_version, status, path=None): - url = CONF.public_endpoint or req.host_url - return { - 'id': 'v%s' % max_version, - 'links': [ - { - 'rel': 'self', - 'href': '%s/%s/' % (url, path) if path else - '%s/' % url, - }, - ], - 'status': status, - 'min_version': min_version, - 'version': max_version - } - - microv_max = api_version_request.APIVersionRequest.max_version() - microv_min = api_version_request.APIVersionRequest.min_version() - version_objs = [build_version_object(microv_max.get_string(), - microv_min.get_string(), - 'EXPERIMENTAL')] - return_status = (http_client.MULTIPLE_CHOICES if is_multi else - http_client.OK) + version_objs = [ + { + 'version': '1.0', + 'status': 'STABLE', + 'links': _LINKS, + 'media-type': 'application/vnd.openstack.artifacts-1.0', + }, + { + 'version': '1.1', + 'status': 'EXPERIMENTAL', + 'links': _LINKS, + 'media-type': 'application/vnd.openstack.artifacts-1.1', + }] response = webob.Response(request=req, - status=return_status, + status=http_client.MULTIPLE_CHOICES, content_type='application/json') response.body = jsonutils.dump_as_bytes(dict(versions=version_objs)) return response diff --git a/glare/tests/unit/middleware/test_version_negotiations.py b/glare/tests/unit/middleware/test_version_negotiations.py index 7ecd590..a20c64a 100644 --- a/glare/tests/unit/middleware/test_version_negotiations.py +++ b/glare/tests/unit/middleware/test_version_negotiations.py @@ -31,14 +31,24 @@ class TestContextMiddleware(base.BaseTestCase): return version_negotiation.GlareVersionNegotiationFilter(None) def test_version_request(self): + _LINKS = [{ + "rel": "describedby", + "type": "text/html", + "href": "http://docs.openstack.org/", + }] for path_info in ('/', '/versions'): - expected = { - "versions": [{ - "status": "EXPERIMENTAL", - "min_version": "1.0", - "version": "1.0", - "id": "v1.0", - "links": [{"href": "http://localhost/", "rel": "self"}] + expected = {'versions': [ + { + 'version': '1.0', + 'status': 'STABLE', + 'links': _LINKS, + 'media-type': 'application/vnd.openstack.artifacts-1.0', + }, + { + 'version': '1.1', + 'status': 'EXPERIMENTAL', + 'links': _LINKS, + 'media-type': 'application/vnd.openstack.artifacts-1.1', }] } req = self._build_request(self.MIME_TYPE + '1.0', path_info) @@ -58,7 +68,7 @@ class TestContextMiddleware(base.BaseTestCase): def test_latest_version(self): req = self._build_request(self.MIME_TYPE + 'latest', '/artifacts') self._build_middleware().process_request(req) - self.assertEqual('1.0', req.api_version_request.get_string()) + self.assertEqual('1.1', req.api_version_request.get_string()) def test_version_unknown(self): req = self._build_request('UNKNOWN', '/artifacts') diff --git a/glare/tests/unit/test_versions.py b/glare/tests/unit/test_versions.py index 01a34c4..ec1d801 100644 --- a/glare/tests/unit/test_versions.py +++ b/glare/tests/unit/test_versions.py @@ -24,42 +24,47 @@ class VersionsTest(base.BaseTestCase): """Test the version information returned from the API service.""" - def test_get_version_list(self): + def test_root_endpoint(self): req = webob.Request.blank('/', base_url='http://127.0.0.1:9494/') req.accept = 'application/json' - res = versions.Controller().index(req, is_multi=True) + 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': 'v1.0', - 'status': 'EXPERIMENTAL', - 'links': [{'rel': 'self', - 'href': 'http://127.0.0.1:9494/'}], - 'min_version': '1.0', - 'version': '1.0' - } - ] + {'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}], + 'media-type': 'application/vnd.openstack.artifacts-1.0', + 'status': 'STABLE', + 'version': '1.0'}, + {'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}], + 'media-type': 'application/vnd.openstack.artifacts-1.1', + 'status': 'EXPERIMENTAL', + 'version': '1.1'}] self.assertEqual(expected, results) - def test_get_version_list_public_endpoint(self): - req = webob.Request.blank('/', base_url='http://127.0.0.1:9494/') + def test_versions_endpoint(self): + req = webob.Request.blank('/versions', + base_url='http://127.0.0.1:9494/') req.accept = 'application/json' - self.config(bind_host='127.0.0.1', bind_port=9494, - public_endpoint='https://example.com:9494') - res = versions.Controller().index(req, is_multi=True) + 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': 'v1.0', - 'status': 'EXPERIMENTAL', - 'links': [{'rel': 'self', - 'href': 'https://example.com:9494/'}], - 'min_version': '1.0', - 'version': '1.0' - } - ] + {'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}], + 'media-type': 'application/vnd.openstack.artifacts-1.0', + 'status': 'STABLE', + 'version': '1.0'}, + {'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}], + 'media-type': 'application/vnd.openstack.artifacts-1.1', + 'status': 'EXPERIMENTAL', + 'version': '1.1'}] self.assertEqual(expected, results)