"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/api/services.py" (13 May 2020, 2977 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 "services.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/services
   14 
   15 import http.client
   16 
   17 from keystone.catalog import schema
   18 from keystone.common import provider_api
   19 from keystone.common import rbac_enforcer
   20 from keystone.common import validation
   21 from keystone.server import flask as ks_flask
   22 
   23 
   24 ENFORCER = rbac_enforcer.RBACEnforcer
   25 PROVIDERS = provider_api.ProviderAPIs
   26 
   27 
   28 class ServicesResource(ks_flask.ResourceBase):
   29     collection_key = 'services'
   30     member_key = 'service'
   31 
   32     def _get_service(self, service_id):
   33         ENFORCER.enforce_call(action='identity:get_service')
   34         return self.wrap_member(PROVIDERS.catalog_api.get_service(service_id))
   35 
   36     def _list_service(self):
   37         filters = ['type', 'name']
   38         ENFORCER.enforce_call(action='identity:list_services', filters=filters)
   39         hints = self.build_driver_hints(filters)
   40         refs = PROVIDERS.catalog_api.list_services(hints=hints)
   41         return self.wrap_collection(refs, hints=hints)
   42 
   43     def get(self, service_id=None):
   44         if service_id is not None:
   45             return self._get_service(service_id)
   46         return self._list_service()
   47 
   48     def post(self):
   49         ENFORCER.enforce_call(action='identity:create_service')
   50         service = self.request_body_json.get('service')
   51         validation.lazy_validate(schema.service_create, service)
   52         service = self._assign_unique_id(self._normalize_dict(service))
   53         ref = PROVIDERS.catalog_api.create_service(
   54             service['id'], service, initiator=self.audit_initiator)
   55         return self.wrap_member(ref), http.client.CREATED
   56 
   57     def patch(self, service_id):
   58         ENFORCER.enforce_call(action='identity:update_service')
   59         service = self.request_body_json.get('service')
   60         validation.lazy_validate(schema.service_update, service)
   61         self._require_matching_id(service)
   62         ref = PROVIDERS.catalog_api.update_service(
   63             service_id, service, initiator=self.audit_initiator)
   64         return self.wrap_member(ref)
   65 
   66     def delete(self, service_id):
   67         ENFORCER.enforce_call(action='identity:delete_service')
   68         return PROVIDERS.catalog_api.delete_service(
   69             service_id, initiator=self.audit_initiator), http.client.NO_CONTENT
   70 
   71 
   72 class ServiceAPI(ks_flask.APIBase):
   73     _name = 'services'
   74     _import_name = __name__
   75     resources = [ServicesResource]
   76     resource_mapping = []
   77 
   78 
   79 APIs = (ServiceAPI,)