"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/api/registered_limits.py" (13 May 2020, 3699 Bytes) of package /linux/misc/openstack/keystone-17.0.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 "registered_limits.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 16.0.1_vs_17.0.0.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 # This file handles all flask-restful resources for /v3/registered_limits
   14 
   15 import flask
   16 import http.client
   17 
   18 from keystone.common import json_home
   19 from keystone.common import provider_api
   20 from keystone.common import rbac_enforcer
   21 from keystone.common import validation
   22 from keystone.limit import schema
   23 from keystone.server import flask as ks_flask
   24 
   25 
   26 PROVIDERS = provider_api.ProviderAPIs
   27 ENFORCER = rbac_enforcer.RBACEnforcer
   28 
   29 
   30 class RegisteredLimitResource(ks_flask.ResourceBase):
   31     collection_key = 'registered_limits'
   32     member_key = 'registered_limit'
   33     json_home_resource_status = json_home.Status.EXPERIMENTAL
   34 
   35     def _get_registered_limit(self, registered_limit_id):
   36         ENFORCER.enforce_call(action='identity:get_registered_limit')
   37         ref = PROVIDERS.unified_limit_api.get_registered_limit(
   38             registered_limit_id)
   39         return self.wrap_member(ref)
   40 
   41     def _list_registered_limits(self):
   42         filters = ['service_id', 'region_id', 'resource_name']
   43         ENFORCER.enforce_call(action='identity:list_registered_limits',
   44                               filters=filters)
   45         hints = self.build_driver_hints(filters)
   46         refs = PROVIDERS.unified_limit_api.list_registered_limits(hints)
   47         return self.wrap_collection(refs, hints=hints)
   48 
   49     def get(self, registered_limit_id=None):
   50         if registered_limit_id is not None:
   51             return self._get_registered_limit(registered_limit_id)
   52         return self._list_registered_limits()
   53 
   54     def post(self):
   55         ENFORCER.enforce_call(action='identity:create_registered_limits')
   56         reg_limits = (flask.request.get_json(
   57             silent=True, force=True) or {}).get('registered_limits', {})
   58         validation.lazy_validate(schema.registered_limit_create, reg_limits)
   59         registered_limits = [self._assign_unique_id(self._normalize_dict(r))
   60                              for r in reg_limits]
   61         refs = PROVIDERS.unified_limit_api.create_registered_limits(
   62             registered_limits)
   63         refs = self.wrap_collection(refs)
   64         refs.pop('links')
   65         return refs, http.client.CREATED
   66 
   67     def patch(self, registered_limit_id):
   68         ENFORCER.enforce_call(action='identity:update_registered_limit')
   69         registered_limit = (flask.request.get_json(
   70             silent=True, force=True) or {}).get('registered_limit', {})
   71         validation.lazy_validate(schema.registered_limit_update,
   72                                  registered_limit)
   73         self._require_matching_id(registered_limit)
   74         ref = PROVIDERS.unified_limit_api.update_registered_limit(
   75             registered_limit_id, registered_limit)
   76         return self.wrap_member(ref)
   77 
   78     def delete(self, registered_limit_id):
   79         ENFORCER.enforce_call(action='identity:delete_registered_limit')
   80         return (PROVIDERS.unified_limit_api.delete_registered_limit(
   81             registered_limit_id), http.client.NO_CONTENT)
   82 
   83 
   84 class RegisteredLimitsAPI(ks_flask.APIBase):
   85     _name = 'registered_limit'
   86     _import_name = __name__
   87     resources = [RegisteredLimitResource]
   88     resource_mapping = []
   89 
   90 
   91 APIs = (RegisteredLimitsAPI,)