"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-3.1.0/monasca_api/v2/reference/versions.py" (27 Sep 2019, 2212 Bytes) of package /linux/misc/openstack/monasca-api-3.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "versions.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2014 Hewlett-Packard
    2 # Copyright 2018 OP5 AB
    3 #
    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
    7 #
    8 # http://www.apache.org/licenses/LICENSE-2.0
    9 #
   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
   14 # under the License.
   15 
   16 import falcon
   17 import six
   18 
   19 from monasca_api.api import versions_api
   20 from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
   21 from monasca_api.v2.reference import helpers
   22 
   23 VERSIONS = {
   24     'v2.0': {
   25         'id': 'v2.0',
   26         'links': [{
   27             'rel': 'self',
   28             'href': ''
   29         }],
   30         'status': 'CURRENT',
   31         'updated': "2013-03-06T00:00:00.000Z"
   32     }
   33 }
   34 
   35 
   36 class Versions(versions_api.VersionsAPI):
   37     def __init__(self):
   38         super(Versions, self).__init__()
   39 
   40     def on_get(self, req, res, version_id=None):
   41         req_uri = req.uri.decode('utf8') if six.PY2 else req.uri
   42         helpers.validate_authorization(req,
   43                                        ['api:versions'])
   44         result = {
   45             'links': [{
   46                 'rel': 'self',
   47                 'href': req_uri
   48             }],
   49             'elements': []
   50         }
   51         if version_id is None:
   52             for version in VERSIONS:
   53                 VERSIONS[version]['links'][0]['href'] = (
   54                     req_uri + version)
   55                 result['elements'].append(VERSIONS[version])
   56             res.body = helpers.to_json(result)
   57             res.status = falcon.HTTP_200
   58         else:
   59             if version_id in VERSIONS:
   60                 VERSIONS[version_id]['links'][0]['href'] = req_uri
   61                 res.body = helpers.to_json(VERSIONS[version_id])
   62                 res.status = falcon.HTTP_200
   63             else:
   64                 raise HTTPUnprocessableEntityError('Invalid version',
   65                                                    'No versions found matching ' + version_id)