本文整理汇总了Python中st2common.router.abort函数的典型用法代码示例。如果您正苦于以下问题:Python abort函数的具体用法?Python abort怎么用?Python abort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_one_by_id
def _get_one_by_id(self, id, requester_user, permission_type, exclude_fields=None,
from_model_kwargs=None):
"""Override ResourceController._get_one_by_id to contain scope of Inquiries UID hack
:param exclude_fields: A list of object fields to exclude.
:type exclude_fields: ``list``
"""
instance = self._get_by_id(resource_id=id, exclude_fields=exclude_fields)
# _get_by_id pulls the resource by ID directly off of the database. Since
# Inquiries don't have their own DB model yet, this comes in the format
# "execution:<id>". So, to allow RBAC to get a handle on inquiries specifically,
# we're overriding the "get_uid" function to return one specific to Inquiries.
#
# TODO (mierdin): All of this should be removed once Inquiries get their own DB model
if getattr(instance, 'runner', None) and instance.runner.get('runner_module') == 'inquirer':
def get_uid():
return "inquiry"
instance.get_uid = get_uid
if permission_type:
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=instance,
permission_type=permission_type)
if not instance:
msg = 'Unable to identify resource with id "%s".' % id
abort(http_client.NOT_FOUND, msg)
from_model_kwargs = from_model_kwargs or {}
from_model_kwargs.update(self.from_model_kwargs)
result = self.model.from_model(instance, **from_model_kwargs)
return result
开发者ID:lyandut,项目名称:st2,代码行数:35,代码来源:inquiries.py
示例2: _get_runner_by_name
def _get_runner_by_name(name):
try:
return RunnerType.get_by_name(name)
except (ValueError, ValidationError) as e:
msg = 'Database lookup for name="%s" resulted in exception. %s' % (id, e)
LOG.exception(msg)
abort(http_client.NOT_FOUND, msg)
开发者ID:StackStorm,项目名称:st2,代码行数:7,代码来源:action_views.py
示例3: _get_one_by_id
def _get_one_by_id(self, id, requester_user, permission_type, exclude_fields=None,
from_model_kwargs=None):
"""
:param exclude_fields: A list of object fields to exclude.
:type exclude_fields: ``list``
"""
instance = self._get_by_id(resource_id=id, exclude_fields=exclude_fields)
if permission_type:
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=instance,
permission_type=permission_type)
if not instance:
msg = 'Unable to identify resource with id "%s".' % id
abort(http_client.NOT_FOUND, msg)
from_model_kwargs = from_model_kwargs or {}
from_model_kwargs.update(self.from_model_kwargs)
result = self.resource_model_filter(model=self.model, instance=instance,
requester_user=requester_user,
**from_model_kwargs)
if not result:
LOG.debug('Not returning the result because RBAC resource isolation is enabled and '
'current user doesn\'t match the resource user')
raise ResourceAccessDeniedPermissionIsolationError(user_db=requester_user,
resource_api_or_db=instance,
permission_type=permission_type)
return result
开发者ID:lyandut,项目名称:st2,代码行数:33,代码来源:resource.py
示例4: post
def post(self, trigger_instance_id):
"""
Re-send the provided trigger instance optionally specifying override parameters.
Handles requests:
POST /triggerinstance/<id>/re_emit
POST /triggerinstance/<id>/re_send
"""
# Note: We only really need parameters here
existing_trigger_instance = self._get_one_by_id(id=trigger_instance_id,
permission_type=None,
requester_user=None)
new_payload = copy.deepcopy(existing_trigger_instance.payload)
new_payload['__context'] = {
'original_id': trigger_instance_id
}
try:
self.trigger_dispatcher.dispatch(existing_trigger_instance.trigger,
new_payload)
return {
'message': 'Trigger instance %s succesfully re-sent.' % trigger_instance_id,
'payload': new_payload
}
except Exception as e:
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
开发者ID:StackStorm,项目名称:st2,代码行数:28,代码来源:triggers.py
示例5: _get_action_by_id
def _get_action_by_id(id):
try:
return Action.get_by_id(id)
except Exception as e:
msg = 'Database lookup for id="%s" resulted in exception. %s' % (id, e)
LOG.exception(msg)
abort(http_client.NOT_FOUND, msg)
开发者ID:StackStorm,项目名称:st2,代码行数:7,代码来源:action_views.py
示例6: delete
def delete(self, triggertype_ref_or_id):
"""
Delete a triggertype.
Handles requests:
DELETE /triggertypes/1
DELETE /triggertypes/pack.name
"""
LOG.info('DELETE /triggertypes/ with ref_or_id=%s',
triggertype_ref_or_id)
triggertype_db = self._get_by_ref_or_id(ref_or_id=triggertype_ref_or_id)
triggertype_id = triggertype_db.id
try:
validate_not_part_of_system_pack(triggertype_db)
except ValueValidationException as e:
abort(http_client.BAD_REQUEST, six.text_type(e))
try:
TriggerType.delete(triggertype_db)
except Exception as e:
LOG.exception('Database delete encountered exception during delete of id="%s". ',
triggertype_id)
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
return
else:
extra = {'triggertype': triggertype_db}
LOG.audit('TriggerType deleted. TriggerType.id=%s' % (triggertype_db.id), extra=extra)
if not triggertype_db.parameters_schema:
TriggerTypeController._delete_shadow_trigger(triggertype_db)
return Response(status=http_client.NO_CONTENT)
开发者ID:StackStorm,项目名称:st2,代码行数:33,代码来源:triggers.py
示例7: get_one
def get_one(self, api_key_id_or_key, requester_user, show_secrets=None):
"""
List api keys.
Handle:
GET /apikeys/1
"""
api_key_db = None
try:
api_key_db = ApiKey.get_by_key_or_id(api_key_id_or_key)
except ApiKeyNotFoundError:
msg = ('ApiKey matching %s for reference and id not found.' % (api_key_id_or_key))
LOG.exception(msg)
abort(http_client.NOT_FOUND, msg)
permission_type = PermissionType.API_KEY_VIEW
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=api_key_db,
permission_type=permission_type)
try:
mask_secrets = self._get_mask_secrets(show_secrets=show_secrets,
requester_user=requester_user)
return ApiKeyAPI.from_model(api_key_db, mask_secrets=mask_secrets)
except (ValidationError, ValueError) as e:
LOG.exception('Failed to serialize API key.')
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
开发者ID:StackStorm,项目名称:st2,代码行数:28,代码来源:auth.py
示例8: put
def put(self, triggertype, triggertype_ref_or_id):
triggertype_db = self._get_by_ref_or_id(ref_or_id=triggertype_ref_or_id)
triggertype_id = triggertype_db.id
try:
validate_not_part_of_system_pack(triggertype_db)
except ValueValidationException as e:
abort(http_client.BAD_REQUEST, six.text_type(e))
try:
triggertype_db = TriggerTypeAPI.to_model(triggertype)
if triggertype.id is not None and len(triggertype.id) > 0 and \
triggertype.id != triggertype_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
triggertype.id, triggertype_id)
triggertype_db.id = triggertype_id
old_triggertype_db = triggertype_db
triggertype_db = TriggerType.add_or_update(triggertype_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for triggertype data=%s', triggertype)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_triggertype_db': old_triggertype_db, 'new_triggertype_db': triggertype_db}
LOG.audit('TriggerType updated. TriggerType.id=%s' % (triggertype_db.id), extra=extra)
triggertype_api = TriggerTypeAPI.from_model(triggertype_db)
return triggertype_api
开发者ID:StackStorm,项目名称:st2,代码行数:28,代码来源:triggers.py
示例9: _get_one
def _get_one(self, ref_or_id, requester_user, permission_type, exclude_fields=None,
include_fields=None, from_model_kwargs=None):
try:
instance = self._get_by_ref_or_id(ref_or_id=ref_or_id, exclude_fields=exclude_fields,
include_fields=include_fields)
except Exception as e:
LOG.exception(six.text_type(e))
abort(http_client.NOT_FOUND, six.text_type(e))
return
if permission_type:
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=instance,
permission_type=permission_type)
# Perform resource isolation check (if supported)
from_model_kwargs = from_model_kwargs or {}
from_model_kwargs.update(self.from_model_kwargs)
result = self.resource_model_filter(model=self.model, instance=instance,
requester_user=requester_user,
**from_model_kwargs)
if not result:
LOG.debug('Not returning the result because RBAC resource isolation is enabled and '
'current user doesn\'t match the resource user')
raise ResourceAccessDeniedPermissionIsolationError(user_db=requester_user,
resource_api_or_db=instance,
permission_type=permission_type)
return Response(json=result)
开发者ID:nzlosh,项目名称:st2,代码行数:31,代码来源:resource.py
示例10: __get_by_id
def __get_by_id(id):
try:
return RuleType.get_by_id(id)
except (ValueError, ValidationError) as e:
msg = 'Database lookup for id="%s" resulted in exception. %s' % (id, e)
LOG.exception(msg)
abort(http_client.NOT_FOUND, msg)
开发者ID:lyandut,项目名称:st2,代码行数:7,代码来源:ruletypes.py
示例11: _get_one_by_name_or_id
def _get_one_by_name_or_id(self, name_or_id, requester_user, permission_type,
exclude_fields=None, include_fields=None, from_model_kwargs=None):
"""
:param exclude_fields: A list of object fields to exclude.
:type exclude_fields: ``list``
:param include_fields: A list of object fields to include.
:type include_fields: ``list``
"""
instance = self._get_by_name_or_id(name_or_id=name_or_id, exclude_fields=exclude_fields,
include_fields=include_fields)
if permission_type:
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=instance,
permission_type=permission_type)
if not instance:
msg = 'Unable to identify resource with name_or_id "%s".' % (name_or_id)
abort(http_client.NOT_FOUND, msg)
from_model_kwargs = from_model_kwargs or {}
from_model_kwargs.update(self.from_model_kwargs)
result = self.model.from_model(instance, **from_model_kwargs)
return result
开发者ID:nzlosh,项目名称:st2,代码行数:26,代码来源:resource.py
示例12: delete
def delete(self, ref_or_id, requester_user):
"""
Delete an action alias.
Handles requests:
DELETE /actionalias/1
"""
action_alias_db = self._get_by_ref_or_id(ref_or_id=ref_or_id)
LOG.debug('DELETE /actionalias/ lookup with id=%s found object: %s', ref_or_id,
action_alias_db)
permission_type = PermissionType.ACTION_ALIAS_DELETE
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=action_alias_db,
permission_type=permission_type)
try:
ActionAlias.delete(action_alias_db)
except Exception as e:
LOG.exception('Database delete encountered exception during delete of id="%s".',
ref_or_id)
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
return
extra = {'action_alias_db': action_alias_db}
LOG.audit('Action alias deleted. ActionAlias.id=%s.' % (action_alias_db.id), extra=extra)
return Response(status=http_client.NO_CONTENT)
开发者ID:StackStorm,项目名称:st2,代码行数:29,代码来源:actionalias.py
示例13: post
def post(self, action_alias, requester_user):
"""
Create a new ActionAlias.
Handles requests:
POST /actionalias/
"""
permission_type = PermissionType.ACTION_ALIAS_CREATE
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_has_resource_api_permission(user_db=requester_user,
resource_api=action_alias,
permission_type=permission_type)
try:
action_alias_db = ActionAliasAPI.to_model(action_alias)
LOG.debug('/actionalias/ POST verified ActionAliasAPI and formulated ActionAliasDB=%s',
action_alias_db)
action_alias_db = ActionAlias.add_or_update(action_alias_db)
except (ValidationError, ValueError, ValueValidationException) as e:
LOG.exception('Validation failed for action alias data=%s.', action_alias)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'action_alias_db': action_alias_db}
LOG.audit('Action alias created. ActionAlias.id=%s' % (action_alias_db.id), extra=extra)
action_alias_api = ActionAliasAPI.from_model(action_alias_db)
return Response(json=action_alias_api, status=http_client.CREATED)
开发者ID:StackStorm,项目名称:st2,代码行数:29,代码来源:actionalias.py
示例14: delete
def delete(self, rule_ref_or_id, requester_user):
"""
Delete a rule.
Handles requests:
DELETE /rules/1
"""
rule_db = self._get_by_ref_or_id(ref_or_id=rule_ref_or_id)
permission_type = PermissionType.RULE_DELETE
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=rule_db,
permission_type=permission_type)
LOG.debug('DELETE /rules/ lookup with id=%s found object: %s', rule_ref_or_id, rule_db)
try:
Rule.delete(rule_db)
except Exception as e:
LOG.exception('Database delete encountered exception during delete of id="%s".',
rule_ref_or_id)
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
return
# use old_rule_db for cleanup.
cleanup_trigger_db_for_rule(rule_db)
extra = {'rule_db': rule_db}
LOG.audit('Rule deleted. Rule.id=%s.' % (rule_db.id), extra=extra)
return Response(status=http_client.NO_CONTENT)
开发者ID:StackStorm,项目名称:st2,代码行数:31,代码来源:rules.py
示例15: put
def put(self, runner_type_api, name_or_id, requester_user):
# Note: We only allow "enabled" attribute of the runner to be changed
runner_type_db = self._get_by_name_or_id(name_or_id=name_or_id)
permission_type = PermissionType.RUNNER_MODIFY
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=runner_type_db,
permission_type=permission_type)
old_runner_type_db = runner_type_db
LOG.debug('PUT /runnertypes/ lookup with id=%s found object: %s', name_or_id,
runner_type_db)
try:
if runner_type_api.id and runner_type_api.id != name_or_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
runner_type_api.id, name_or_id)
runner_type_db.enabled = runner_type_api.enabled
runner_type_db = RunnerType.add_or_update(runner_type_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for runner type data=%s', runner_type_api)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_runner_type_db': old_runner_type_db, 'new_runner_type_db': runner_type_db}
LOG.audit('Runner Type updated. RunnerType.id=%s.' % (runner_type_db.id), extra=extra)
runner_type_api = RunnerTypeAPI.from_model(runner_type_db)
return runner_type_api
开发者ID:nzlosh,项目名称:st2,代码行数:29,代码来源:runnertypes.py
示例16: put
def put(self, rule, rule_ref_or_id, requester_user):
rule_db = self._get_by_ref_or_id(rule_ref_or_id)
rbac_utils = get_rbac_backend().get_utils_class()
permission_type = PermissionType.RULE_MODIFY
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=rule,
permission_type=permission_type)
LOG.debug('PUT /rules/ lookup with id=%s found object: %s', rule_ref_or_id, rule_db)
if not requester_user:
requester_user = UserDB(cfg.CONF.system_user.user)
# Validate that the authenticated user is admin if user query param is provided
user = requester_user.name
rbac_utils.assert_user_is_admin_if_user_query_param_is_provided(user_db=requester_user,
user=user)
if not hasattr(rule, 'context'):
rule.context = dict()
rule.context['user'] = user
try:
if rule.id is not None and rule.id != '' and rule.id != rule_ref_or_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
rule.id, rule_ref_or_id)
old_rule_db = rule_db
try:
rule_db = RuleAPI.to_model(rule)
except TriggerDoesNotExistException as e:
abort(http_client.BAD_REQUEST, six.text_type(e))
return
# Check referenced trigger and action permissions
# Note: This needs to happen after "to_model" call since to_model performs some
# validation (trigger exists, etc.)
rbac_utils.assert_user_has_rule_trigger_and_action_permission(user_db=requester_user,
rule_api=rule)
rule_db.id = rule_ref_or_id
rule_db = Rule.add_or_update(rule_db)
# After the rule has been added modify the ref_count. This way a failure to add
# the rule due to violated constraints will have no impact on ref_count.
increment_trigger_ref_count(rule_api=rule)
except (ValueValidationException, jsonschema.ValidationError, ValueError) as e:
LOG.exception('Validation failed for rule data=%s', rule)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
# use old_rule_db for cleanup.
cleanup_trigger_db_for_rule(old_rule_db)
extra = {'old_rule_db': old_rule_db, 'new_rule_db': rule_db}
LOG.audit('Rule updated. Rule.id=%s.' % (rule_db.id), extra=extra)
rule_api = RuleAPI.from_model(rule_db)
return rule_api
开发者ID:StackStorm,项目名称:st2,代码行数:58,代码来源:rules.py
示例17: get_all
def get_all(self, timer_type=None):
if timer_type and timer_type not in self._allowed_timer_types:
msg = 'Timer type %s not in supported types - %s.' % (timer_type,
self._allowed_timer_types)
abort(http_client.BAD_REQUEST, msg)
t_all = self._timers.get_all(timer_type=timer_type)
LOG.debug('Got timers: %s', t_all)
return t_all
开发者ID:nzlosh,项目名称:st2,代码行数:9,代码来源:timers.py
示例18: post
def post(self, hook, webhook_body_api, headers, requester_user):
body = webhook_body_api.data
permission_type = PermissionType.WEBHOOK_SEND
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=WebhookDB(name=hook),
permission_type=permission_type)
headers = self._get_headers_as_dict(headers)
# If webhook contains a trace-tag use that else create create a unique trace-tag.
trace_context = self._create_trace_context(trace_tag=headers.pop(TRACE_TAG_HEADER, None),
hook=hook)
if hook == 'st2' or hook == 'st2/':
# When using st2 or system webhook, body needs to always be a dict
if not isinstance(body, dict):
type_string = get_json_type_for_python_value(body)
msg = ('Webhook body needs to be an object, got: %s' % (type_string))
raise ValueError(msg)
trigger = body.get('trigger', None)
payload = body.get('payload', None)
if not trigger:
msg = 'Trigger not specified.'
return abort(http_client.BAD_REQUEST, msg)
self._trigger_dispatcher_service.dispatch_with_context(trigger=trigger,
payload=payload,
trace_context=trace_context,
throw_on_validation_error=True)
else:
if not self._is_valid_hook(hook):
self._log_request('Invalid hook.', headers, body)
msg = 'Webhook %s not registered with st2' % hook
return abort(http_client.NOT_FOUND, msg)
triggers = self._hooks.get_triggers_for_hook(hook)
payload = {}
payload['headers'] = headers
payload['body'] = body
# Dispatch trigger instance for each of the trigger found
for trigger_dict in triggers:
# TODO: Instead of dispatching the whole dict we should just
# dispatch TriggerDB.ref or similar
self._trigger_dispatcher_service.dispatch_with_context(trigger=trigger_dict,
payload=payload,
trace_context=trace_context,
throw_on_validation_error=True)
return Response(json=body, status=http_client.ACCEPTED)
开发者ID:StackStorm,项目名称:st2,代码行数:55,代码来源:webhooks.py
示例19: delete
def delete(self, name, requester_user, scope=FULL_SYSTEM_SCOPE, user=None):
"""
Delete the key value pair.
Handles requests:
DELETE /keys/1
"""
if not scope:
scope = FULL_SYSTEM_SCOPE
if not requester_user:
requester_user = UserDB(cfg.CONF.system_user.user)
scope = get_datastore_full_scope(scope)
self._validate_scope(scope=scope)
user = user or requester_user.name
# Validate that the authenticated user is admin if user query param is provided
rbac_utils = get_rbac_backend().get_utils_class()
rbac_utils.assert_user_is_admin_if_user_query_param_is_provided(user_db=requester_user,
user=user,
require_rbac=True)
key_ref = get_key_reference(scope=scope, name=name, user=user)
lock_name = self._get_lock_name_for_key(name=key_ref, scope=scope)
# Note: We use lock to avoid a race
with self._coordinator.get_lock(lock_name):
from_model_kwargs = {'mask_secrets': True}
kvp_api = self._get_one_by_scope_and_name(
name=key_ref,
scope=scope,
from_model_kwargs=from_model_kwargs
)
kvp_db = KeyValuePairAPI.to_model(kvp_api)
LOG.debug('DELETE /keys/ lookup with scope=%s name=%s found object: %s',
scope, name, kvp_db)
try:
KeyValuePair.delete(kvp_db)
except Exception as e:
LOG.exception('Database delete encountered exception during '
'delete of name="%s". ', name)
abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))
return
extra = {'kvp_db': kvp_db}
LOG.audit('KeyValuePair deleted. KeyValuePair.id=%s' % (kvp_db.id), extra=extra)
return Response(status=http_client.NO_CONTENT)
开发者ID:StackStorm,项目名称:st2,代码行数:53,代码来源:keyvalue.py
示例20: post
def post(self, def_yaml):
if not mistral:
abort(http_client.NOT_FOUND)
return
result = self.validator.validate(def_yaml)
for error in result:
if not error.get('path', None):
error['path'] = ''
return Response(json=result)
开发者ID:StackStorm,项目名称:st2,代码行数:12,代码来源:validation.py
注:本文中的st2common.router.abort函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论