magpie.api.requests

Module Contents

Functions

get_request_method_content(request)

get_multiformat_body(request: Request, key: Str, default: Optional[Any] = None) → Any

Obtains the value of key element from the request body according to specified Content-Type header.

get_permission_multiformat_body_checked(request: Request, service_or_resource: ServiceOrResourceType, permission_name_key: Str = ‘permission_name’) → Permission

Retrieves the permission from the body and validates that it is allowed for the specified service or resource.

get_value_multiformat_body_checked(request: Request, key: Str, default: Any = None, check_type: Any = six.string_types, pattern: Optional[Union[Str, bool]] = ax.PARAM_REGEX) → Str

Obtains and validates the matched value under key element from the request body.

get_principals(request: Request) → List[AnyAccessPrincipalType]

Obtains the list of effective principals according to detected request session user.

get_logged_user(request: Request) → Optional[models.User]

get_user(request: Request, user_name_or_token: Optional[Str] = None) → models.User

Obtains the user corresponding to the provided user-name, token or via lookup of the logged user request session.

get_user_matchdict_checked_or_logged(request: Request, user_name_key: Str = ‘user_name’) → models.User

Obtains either the explicit or logged user specified in the request path variable.

get_user_matchdict_checked(request: Request, user_name_key: Str = ‘user_name’) → models.User

Obtains the user matched against the specified request path variable.

get_group_matchdict_checked(request: Request, group_name_key: Str = ‘group_name’) → models.Group

Obtains the group matched against the specified request path variable.

get_resource_matchdict_checked(request: Request, resource_name_key: Str = ‘resource_id’) → models.Resource

Obtains the resource matched against the specified request path variable.

get_service_matchdict_checked(request: Request, service_name_key: Str = ‘service_name’) → models.Service

Obtains the service matched against the specified request path variable.

get_permission_matchdict_checked(request: Request, service_or_resource: models.Resource, permission_name_key: Str = ‘permission_name’) → Permission

Obtains the permission specified in the request path variable and validates that it is allowed for the specified.

get_value_matchdict_checked(request: Request, key: Str, check_type: Any = six.string_types, pattern: Optional[Union[Str, bool]] = ax.PARAM_REGEX) → Str

Obtains the matched value located at the expected position of the specified path variable.

get_query_param(request: Request, case_insensitive_key: Str, default: Optional[Any] = None) → Any

Retrieves a query string value by name (case insensitive), or returns the default if not present.

magpie.api.requests.LOGGER[source]
magpie.api.requests.get_request_method_content(request)[source]
magpie.api.requests.get_multiformat_body(request: Request, key: Str, default: Optional[Any] = None) → Any[source]

Obtains the value of key element from the request body according to specified Content-Type header.

magpie.api.requests.get_permission_multiformat_body_checked(request: Request, service_or_resource: ServiceOrResourceType, permission_name_key: Str = 'permission_name') → Permission[source]

Retrieves the permission from the body and validates that it is allowed for the specified service or resource.

Validation combines basic field checks followed by contextual values applicable for the service or resource.

magpie.api.requests.get_value_multiformat_body_checked(request: Request, key: Str, default: Any = None, check_type: Any = six.string_types, pattern: Optional[Union[Str, bool]] = ax.PARAM_REGEX) → Str[source]

Obtains and validates the matched value under key element from the request body.

Parsing of the body is accomplished according to Content-Type header.

Parameters
  • request – request from which to retrieve the key.

  • key – body key variable.

  • default – value to return instead if not found. If this default is None, it will raise.

  • check_type – verify that parameter value is of specified type. Set to None to disable check.

  • pattern – regex pattern to validate the input with. If value evaluates to False, skip this kind of validation (default: magpie.api.exception.PARAM_REGEX).

Returns

matched path variable value.

Raises
  • HTTPBadRequest – if the key could not be retrieved from the request body and has no provided default value.

  • HTTPUnprocessableEntity – if the retrieved value from the key is invalid for this request.

magpie.api.requests.get_principals(request: Request) → List[AnyAccessPrincipalType][source]

Obtains the list of effective principals according to detected request session user.

magpie.api.requests.get_logged_user(request: Request) → Optional[models.User][source]
magpie.api.requests.get_user(request: Request, user_name_or_token: Optional[Str] = None) → models.User[source]

Obtains the user corresponding to the provided user-name, token or via lookup of the logged user request session.

Parameters
  • request – request from which to obtain application settings and session user as applicable.

  • user_name_or_token – reference value to employ for lookup of the user.

Returns

found user.

Raises
  • HTTPForbidden – if the requesting user does not have sufficient permission to execute this request.

  • HTTPNotFound – if the specified user name or token does not correspond to any existing user.

magpie.api.requests.get_user_matchdict_checked_or_logged(request: Request, user_name_key: Str = 'user_name') → models.User[source]

Obtains either the explicit or logged user specified in the request path variable.

:returns found user. :raises HTTPForbidden: if the requesting user does not have sufficient permission to execute this request. :raises HTTPNotFound: if the specified user name or logged user keyword does not correspond to any existing user.

magpie.api.requests.get_user_matchdict_checked(request: Request, user_name_key: Str = 'user_name') → models.User[source]

Obtains the user matched against the specified request path variable.

Returns

found user.

Raises
  • HTTPForbidden – if the requesting user does not have sufficient permission to execute this request.

  • HTTPNotFound – if the specified user name does not correspond to any existing user.

magpie.api.requests.get_group_matchdict_checked(request: Request, group_name_key: Str = 'group_name') → models.Group[source]

Obtains the group matched against the specified request path variable.

Returns

found group.

Raises
  • HTTPForbidden – if the requesting user does not have sufficient permission to execute this request.

  • HTTPNotFound – if the specified group name does not correspond to any existing group.

magpie.api.requests.get_resource_matchdict_checked(request: Request, resource_name_key: Str = 'resource_id') → models.Resource[source]

Obtains the resource matched against the specified request path variable.

Returns

found resource.

Raises
  • HTTPForbidden – if the requesting user does not have sufficient permission to execute this request.

  • HTTPNotFound – if the specified resource ID does not correspond to any existing resource.

magpie.api.requests.get_service_matchdict_checked(request: Request, service_name_key: Str = 'service_name') → models.Service[source]

Obtains the service matched against the specified request path variable.

Returns

found service.

Raises
  • HTTPForbidden – if the requesting user does not have sufficient permission to execute this request.

  • HTTPNotFound – if the specified service name does not correspond to any existing service.

magpie.api.requests.get_permission_matchdict_checked(request: Request, service_or_resource: models.Resource, permission_name_key: Str = 'permission_name') → Permission[source]

Obtains the permission specified in the request path variable and validates that it is allowed for the specified.

service_or_resource which can be a service or a children resource.

Allowed permissions correspond to the direct service permissions or restrained permissions of the resource under its root service.

Returns

found permission name if valid for the service/resource

magpie.api.requests.get_value_matchdict_checked(request: Request, key: Str, check_type: Any = six.string_types, pattern: Optional[Union[Str, bool]] = ax.PARAM_REGEX) → Str[source]

Obtains the matched value located at the expected position of the specified path variable.

Parameters
  • request – request from which to retrieve the key.

  • key – path variable key.

  • check_type – verify that parameter value is of specified type. Set to None to disable check.

  • pattern – regex pattern to validate the input with. If value evaluates to False, skip this kind of validation (default: ax.PARAM_REGEX).

Returns

matched path variable value.

Raises

HTTPUnprocessableEntity – if the key is not an applicable path variable for this request.

magpie.api.requests.get_query_param(request: Request, case_insensitive_key: Str, default: Optional[Any] = None) → Any[source]

Retrieves a query string value by name (case insensitive), or returns the default if not present.