Merge "Convert services api to flask native dispatching"

This commit is contained in:
Zuul 2018-08-15 01:01:54 +00:00 committed by Gerrit Code Review
commit 3280aaacfc
5 changed files with 84 additions and 50 deletions

View File

@ -19,6 +19,7 @@ from keystone.api import os_revoke
from keystone.api import os_simple_cert
from keystone.api import regions
from keystone.api import registered_limits
from keystone.api import services
from keystone.api import trusts
__all__ = (
@ -31,6 +32,7 @@ __all__ = (
'os_simple_cert',
'regions',
'registered_limits',
'services',
'trusts',
)
@ -44,5 +46,6 @@ __apis__ = (
os_simple_cert,
regions,
registered_limits,
services,
trusts,
)

79
keystone/api/services.py Normal file
View File

@ -0,0 +1,79 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# This file handles all flask-restful resources for /v3/services
from six.moves import http_client
from keystone.catalog import schema
from keystone.common import provider_api
from keystone.common import rbac_enforcer
from keystone.common import validation
from keystone.server import flask as ks_flask
ENFORCER = rbac_enforcer.RBACEnforcer
PROVIDERS = provider_api.ProviderAPIs
class ServicesResource(ks_flask.ResourceBase):
collection_key = 'services'
member_key = 'service'
def _get_service(self, service_id):
ENFORCER.enforce_call(action='identity:get_service')
return self.wrap_member(PROVIDERS.catalog_api.get_service(service_id))
def _list_service(self):
filters = ['type', 'name']
ENFORCER.enforce_call(action='identity:list_services', filters=filters)
hints = self.build_driver_hints(filters)
refs = PROVIDERS.catalog_api.list_services(hints=hints)
return self.wrap_collection(refs, hints=hints)
def get(self, service_id=None):
if service_id is not None:
return self._get_service(service_id)
return self._list_service()
def post(self):
ENFORCER.enforce_call(action='identity:create_service')
service = self.request_body_json.get('service')
validation.lazy_validate(schema.service_create, service)
service = self._assign_unique_id(self._normalize_dict(service))
ref = PROVIDERS.catalog_api.create_service(
service['id'], service, initiator=self.audit_initiator)
return self.wrap_member(ref), http_client.CREATED
def patch(self, service_id):
ENFORCER.enforce_call(action='identity:update_service')
service = self.request_body_json.get('service')
validation.lazy_validate(schema.service_update, service)
self._require_matching_id(service)
ref = PROVIDERS.catalog_api.update_service(
service_id, service, initiator=self.audit_initiator)
return self.wrap_member(ref)
def delete(self, service_id):
ENFORCER.enforce_call(action='identity:delete_service')
return PROVIDERS.catalog_api.delete_service(
service_id, initiator=self.audit_initiator), http_client.NO_CONTENT
class ServiceAPI(ks_flask.APIBase):
_name = 'services'
_import_name = __name__
resources = [ServicesResource]
resource_mapping = []
APIs = (ServiceAPI,)

View File

@ -25,52 +25,6 @@ INTERFACES = ['public', 'internal', 'admin']
PROVIDERS = provider_api.ProviderAPIs
class ServiceV3(controller.V3Controller):
collection_name = 'services'
member_name = 'service'
def __init__(self):
super(ServiceV3, self).__init__()
self.get_member_from_driver = PROVIDERS.catalog_api.get_service
@controller.protected()
def create_service(self, request, service):
validation.lazy_validate(schema.service_create, service)
ref = self._assign_unique_id(self._normalize_dict(service))
ref = PROVIDERS.catalog_api.create_service(
ref['id'], ref, initiator=request.audit_initiator
)
return ServiceV3.wrap_member(request.context_dict, ref)
@controller.filterprotected('type', 'name')
def list_services(self, request, filters):
hints = ServiceV3.build_driver_hints(request, filters)
refs = PROVIDERS.catalog_api.list_services(hints=hints)
return ServiceV3.wrap_collection(request.context_dict,
refs,
hints=hints)
@controller.protected()
def get_service(self, request, service_id):
ref = PROVIDERS.catalog_api.get_service(service_id)
return ServiceV3.wrap_member(request.context_dict, ref)
@controller.protected()
def update_service(self, request, service_id, service):
validation.lazy_validate(schema.service_update, service)
self._require_matching_id(service_id, service)
ref = PROVIDERS.catalog_api.update_service(
service_id, service, initiator=request.audit_initiator
)
return ServiceV3.wrap_member(request.context_dict, ref)
@controller.protected()
def delete_service(self, request, service_id):
return PROVIDERS.catalog_api.delete_service(
service_id, initiator=request.audit_initiator
)
class EndpointV3(controller.V3Controller):
collection_name = 'endpoints'
member_name = 'endpoint'

View File

@ -20,12 +20,9 @@ from keystone.common import wsgi
class Routers(wsgi.RoutersBase):
"""API for the keystone catalog."""
_path_prefixes = ('endpoints', 'services')
_path_prefixes = ('endpoints',)
def append_v3_routers(self, mapper, routers):
routers.append(router.Router(controllers.ServiceV3(),
'services', 'service',
resource_descriptions=self.v3_resources))
routers.append(router.Router(controllers.EndpointV3(),
'endpoints', 'endpoint',
resource_descriptions=self.v3_resources))

View File

@ -50,6 +50,7 @@ _MOVED_API_PREFIXES = frozenset(
'limits',
'regions',
'registered_limits',
'services',
]
)