1 # Copyright 2012 OpenStack Foundation.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
18 from oslo.serialization import jsonutils
19 from oslo.config import cfg
22 from escalator.common import wsgi
23 from escalator import i18n
28 cfg.StrOpt('public_endpoint', default=None,
29 help=_('Public url to use for versions endpoint. The default '
30 'is None, which will use the request\'s host_url '
31 'attribute to populate the URL base. If Escalator is '
32 'operating behind a proxy, you will want to change '
33 'this to represent the proxy\'s URL.')),
37 CONF.register_opts(versions_opts)
40 class Controller(object):
42 """A wsgi controller that reports which API versions are supported."""
45 """Respond to a request for all OpenStack API versions."""
46 def build_version_object(version, path, status):
47 url = CONF.public_endpoint or req.host_url
49 'id': 'v%s' % version,
54 'href': '%s/%s/' % (url, path),
60 if CONF.enable_v1_api:
62 build_version_object(1.1, 'v1', 'SUPPORTED'),
63 build_version_object(1.0, 'v1', 'SUPPORTED'),
66 response = webob.Response(request=req,
67 status=httplib.MULTIPLE_CHOICES,
68 content_type='application/json')
69 response.body = jsonutils.dumps(dict(versions=version_objs))
72 @webob.dec.wsgify(RequestClass=wsgi.Request)
73 def __call__(self, req):
74 return self.index(req)
77 def create_resource(conf):
78 return wsgi.Resource(Controller())