def _schedule_execution(self, action_alias_db, params, notify, context): action_ref = action_alias_db.action_ref action_db = action_utils.get_action_by_ref(action_ref) assert_request_user_has_resource_permission(request=pecan.request, resource_db=action_db, permission_type=PermissionType.ACTION_EXECUTE) try: # prior to shipping off the params cast them to the right type. params = action_param_utils.cast_params(action_ref=action_alias_db.action_ref, params=params, cast_overrides=CAST_OVERRIDES) if not context: context = { 'action_alias_ref': reference.get_ref_from_model(action_alias_db), 'user': get_system_username() } liveaction = LiveActionDB(action=action_alias_db.action_ref, context=context, parameters=params, notify=notify) _, action_execution_db = action_service.request(liveaction) return action_execution_db except ValueError as e: LOG.exception('Unable to execute action.') pecan.abort(http_client.BAD_REQUEST, str(e)) except jsonschema.ValidationError as e: LOG.exception('Unable to execute action. Parameter validation failed.') pecan.abort(http_client.BAD_REQUEST, str(e)) except Exception as e: LOG.exception('Unable to execute action. Unexpected error encountered.') pecan.abort(http_client.INTERNAL_SERVER_ERROR, str(e))
def _handle_schedule_execution(self, liveaction): # Assert the permissions action_ref = liveaction.action action_db = action_utils.get_action_by_ref(action_ref) assert_request_user_has_resource_permission( request=pecan.request, resource_db=action_db, permission_type=PermissionType.ACTION_EXECUTE) try: return self._schedule_execution(liveaction=liveaction) except ValueError as e: LOG.exception('Unable to execute action.') abort(http_client.BAD_REQUEST, str(e)) except jsonschema.ValidationError as e: LOG.exception( 'Unable to execute action. Parameter validation failed.') abort(http_client.BAD_REQUEST, re.sub("u'([^']*)'", r"'\1'", e.message)) except TraceNotFoundException as e: abort(http_client.BAD_REQUEST, str(e)) except Exception as e: LOG.exception( 'Unable to execute action. Unexpected error encountered.') abort(http_client.INTERNAL_SERVER_ERROR, str(e))
def func_wrapper(*args, **kwargs): hook = '/'.join(args[1:]) # TODO: There must be a better way to do this. webhook_db = WebhookDB(name=hook) resource_db = webhook_db utils.assert_request_user_has_resource_permission(request=pecan.request, resource_db=resource_db, permission_type=permission_type) return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): controller_instance = args[0] resource_id = args[1] # Note: This can either be id, name or ref get_one_db_method = controller_instance.get_one_db_method resource_db = get_one_db_method(resource_id) utils.assert_request_user_has_resource_permission(request=pecan.request, resource_db=resource_db, permission_type=permission_type) return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): controller_instance = args[0] resource_id = args[1] # Note: This can either be id, name or ref get_one_db_method = controller_instance.get_one_db_method resource_db = get_one_db_method(resource_id) utils.assert_request_user_has_resource_permission( request=pecan.request, resource_db=resource_db, permission_type=permission_type) return func(*args, **kwargs)
def func_wrapper(*args, **kwargs): hook = '/'.join( args[1:]) # TODO: There must be a better way to do this. webhook_db = WebhookDB(name=hook) resource_db = webhook_db utils.assert_request_user_has_resource_permission( request=pecan.request, resource_db=resource_db, permission_type=permission_type) return func(*args, **kwargs)
def _handle_schedule_execution(self, liveaction): # Assert the permissions action_ref = liveaction.action action_db = action_utils.get_action_by_ref(action_ref) assert_request_user_has_resource_permission(request=pecan.request, resource_db=action_db, permission_type=PermissionType.ACTION_EXECUTE) try: return self._schedule_execution(liveaction=liveaction) except ValueError as e: LOG.exception('Unable to execute action.') abort(http_client.BAD_REQUEST, str(e)) except jsonschema.ValidationError as e: LOG.exception('Unable to execute action. Parameter validation failed.') abort(http_client.BAD_REQUEST, re.sub("u'([^']*)'", r"'\1'", e.message)) except TraceNotFoundException as e: abort(http_client.BAD_REQUEST, str(e)) except Exception as e: LOG.exception('Unable to execute action. Unexpected error encountered.') abort(http_client.INTERNAL_SERVER_ERROR, str(e))