Remove repetitive body schema check for karbor API
Change-Id: Ifa669b0ef07871dc84eb5db973a2d4a017887a04 Partial-Implements: bp karbor-json-schema-validation
This commit is contained in:
parent
36bc97d810
commit
947dc8f982
|
@ -253,8 +253,6 @@ class PlansController(wsgi.Controller):
|
|||
@validation.schema(plan_schema.create)
|
||||
def create(self, req, body):
|
||||
"""Creates a new plan."""
|
||||
if not self.is_valid_body(body, 'plan'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
||||
LOG.debug('Create plan request body: %s', body)
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -262,23 +260,8 @@ class PlansController(wsgi.Controller):
|
|||
plan = body['plan']
|
||||
LOG.debug('Create plan request plan: %s', plan)
|
||||
|
||||
if not plan.get("provider_id"):
|
||||
msg = _("provider_id must be provided when creating "
|
||||
"a plan.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
parameters = plan.get("parameters", None)
|
||||
|
||||
if parameters is None:
|
||||
msg = _("parameters must be provided when creating "
|
||||
"a plan.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
if not isinstance(parameters, dict):
|
||||
msg = _("parameters must be a dict when creating a plan.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
self.validate_name_and_description(plan)
|
||||
self.validate_plan_resources(plan)
|
||||
self.validate_plan_parameters(context, plan)
|
||||
|
||||
|
@ -327,18 +310,6 @@ class PlansController(wsgi.Controller):
|
|||
"""Update a plan."""
|
||||
context = req.environ['karbor.context']
|
||||
|
||||
if not body:
|
||||
msg = _("Missing request body")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
if 'plan' not in body:
|
||||
msg = _("Missing required element '%s' in request body") % 'plan'
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
if not uuidutils.is_uuid_like(id):
|
||||
msg = _("Invalid plan id provided.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
plan = body['plan']
|
||||
update_dict = {}
|
||||
|
||||
|
@ -354,7 +325,6 @@ class PlansController(wsgi.Controller):
|
|||
msg = _("Missing updated parameters in request body.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
self.validate_name_and_description(update_dict)
|
||||
if update_dict.get("resources"):
|
||||
self.validate_plan_resources(update_dict)
|
||||
|
||||
|
|
|
@ -338,8 +338,6 @@ class ProvidersController(wsgi.Controller):
|
|||
@validation.schema(checkpoint_schema.create)
|
||||
def checkpoints_create(self, req, provider_id, body):
|
||||
"""Creates a new checkpoint."""
|
||||
if not self.is_valid_body(body, 'checkpoint'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
||||
context = req.environ['karbor.context']
|
||||
|
||||
|
@ -358,15 +356,6 @@ class ProvidersController(wsgi.Controller):
|
|||
|
||||
plan_id = checkpoint.get("plan_id")
|
||||
|
||||
if not plan_id:
|
||||
msg = _("plan_id must be provided when creating "
|
||||
"a checkpoint.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
if not uuidutils.is_uuid_like(plan_id):
|
||||
msg = _("Invalid plan id provided.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
plan = objects.Plan.get_by_id(context, plan_id)
|
||||
if not plan:
|
||||
raise exception.PlanNotFound(plan_id=plan_id)
|
||||
|
|
|
@ -206,8 +206,6 @@ class RestoresController(wsgi.Controller):
|
|||
@validation.schema(restore_schema.create)
|
||||
def create(self, req, body):
|
||||
"""Creates a new restore."""
|
||||
if not self.is_valid_body(body, 'restore'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
||||
LOG.debug('Create restore request body: %s', body)
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -215,30 +213,8 @@ class RestoresController(wsgi.Controller):
|
|||
restore = body['restore']
|
||||
LOG.debug('Create restore request : %s', restore)
|
||||
|
||||
if not restore.get("provider_id"):
|
||||
msg = _("provider_id must be provided when creating "
|
||||
"a restore.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
if not restore.get("checkpoint_id"):
|
||||
msg = _("checkpoint_id must be provided when creating "
|
||||
"a restore.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
parameters = restore.get("parameters")
|
||||
if not isinstance(parameters, dict):
|
||||
msg = _("parameters must be a dict when creating"
|
||||
" a restore.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
# restore_auth and restore_target are optional
|
||||
restore_auth = restore.get("restore_auth")
|
||||
if restore_auth is not None:
|
||||
if not isinstance(restore_auth, dict):
|
||||
msg = _("restore_auth must be a dict when creating"
|
||||
" a restore.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
restore_auth = restore.get("restore_auth", None)
|
||||
restore_properties = {
|
||||
'project_id': context.project_id,
|
||||
'provider_id': restore.get('provider_id'),
|
||||
|
|
|
@ -86,8 +86,6 @@ class ScheduledOperationController(wsgi.Controller):
|
|||
|
||||
LOG.debug('Create scheduled operation start')
|
||||
|
||||
if not self.is_valid_body(body, 'scheduled_operation'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
LOG.debug('Create a scheduled operation, request body: %s', body)
|
||||
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -102,8 +100,6 @@ class ScheduledOperationController(wsgi.Controller):
|
|||
msg = _("Operation name or type or definition is not provided.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
self.validate_name_and_description(operation_info)
|
||||
|
||||
trigger_id = operation_info.get("trigger_id", None)
|
||||
trigger = self._get_trigger_by_id(context, trigger_id)
|
||||
if context.project_id != trigger.project_id:
|
||||
|
|
|
@ -86,8 +86,6 @@ class TriggersController(wsgi.Controller):
|
|||
|
||||
LOG.debug('Create trigger start')
|
||||
|
||||
if not self.is_valid_body(body, 'trigger_info'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
LOG.debug('Create a trigger, request body: %s', body)
|
||||
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -97,10 +95,6 @@ class TriggersController(wsgi.Controller):
|
|||
trigger_name = trigger_info.get("name", None)
|
||||
trigger_type = trigger_info.get("type", None)
|
||||
trigger_property = trigger_info.get("properties", None)
|
||||
if not trigger_name or not trigger_type or not trigger_property:
|
||||
msg = _("Trigger name or type or property is not provided.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
self.validate_name_and_description(trigger_info)
|
||||
|
||||
trigger_format = trigger_property.get('format', None)
|
||||
if trigger_format != CONF.time_format:
|
||||
|
|
|
@ -200,8 +200,6 @@ class VerificationsController(wsgi.Controller):
|
|||
@validation.schema(verification_schema.create)
|
||||
def create(self, req, body):
|
||||
"""Creates a new verification."""
|
||||
if not self.is_valid_body(body, 'verification'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
||||
LOG.debug('Create verification request body: %s', body)
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -209,21 +207,7 @@ class VerificationsController(wsgi.Controller):
|
|||
verification = body['verification']
|
||||
LOG.debug('Create verification request : %s', verification)
|
||||
|
||||
if not verification.get("provider_id"):
|
||||
msg = _("provider_id must be provided when creating "
|
||||
"a verification.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
if not verification.get("checkpoint_id"):
|
||||
msg = _("checkpoint_id must be provided when creating "
|
||||
"a verification.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
parameters = verification.get("parameters")
|
||||
if not isinstance(parameters, dict):
|
||||
msg = _("parameters must be a dict when creating"
|
||||
" a verification.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
verification_properties = {
|
||||
'project_id': context.project_id,
|
||||
|
|
Loading…
Reference in New Issue