magpie.api.management.register.register_formats =============================================== .. py:module:: magpie.api.management.register.register_formats Classes ------- .. autoapisummary:: magpie.api.management.register.register_formats.TemporaryToken magpie.api.management.register.register_formats.TokenOperation Functions --------- .. autoapisummary:: magpie.api.management.register.register_formats.evaluate_call magpie.api.management.register.register_formats.get_constant magpie.api.management.register.register_formats.format_pending_user Module Contents --------------- .. py:function:: evaluate_call(call: Callable[[], Any], fallback: Optional[Callable[[], None]] = None, http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPInternalServerError, http_kwargs: Optional[magpie.typedefs.ParamsType] = None, msg_on_fail: magpie.typedefs.Str = '', content: Optional[magpie.typedefs.JSON] = None, content_type: magpie.typedefs.Str = CONTENT_TYPE_JSON, metadata: Optional[magpie.typedefs.JSON] = None) -> Any Evaluates the specified :paramref:`call` with a wrapped HTTP exception handling. On failure, tries to call. :paramref:`fallback` if specified, and finally raises the specified :paramref:`http_error`. Any potential error generated by :paramref:`fallback` or :paramref:`http_error` themselves are treated as :class:`HTTPInternalServerError`. Exceptions are generated using the standard output method formatted based on specified :paramref:`content_type`. Example: normal call:: try: res = func(args) except Exception as exc: fb_func() raise HTTPExcept(exc.message) wrapped call:: res = evaluate_call(lambda: func(args), fallback=lambda: fb_func(), http_error=HTTPExcept, **kwargs) :param call: function to call, *MUST* be specified as `lambda: ` :param fallback: function to call (if any) when `call` failed, *MUST* be `lambda: ` :param http_error: alternative exception to raise on `call` failure :param http_kwargs: additional keyword arguments to pass to `http_error` if called in case of HTTP exception :param msg_on_fail: message details to return in HTTP exception if `call` failed :param content: json formatted additional content to provide in case of exception :param content_type: format in which to return the exception (one of `magpie.common.SUPPORTED_ACCEPT_TYPES`) :param metadata: request metadata to add to the response body. (see: :func:`magpie.api.requests.get_request_info`) :raises http_error: on `call` failure :raises `HTTPInternalServerError`: on `fallback` failure :return: whichever return value `call` might have if no exception occurred .. py:function:: get_constant(constant_name: magpie.typedefs.Str, settings_container: Optional[magpie.typedefs.AnySettingsContainer] = None, settings_name: Optional[magpie.typedefs.Str] = None, default_value: Optional[magpie.typedefs.SettingValue] = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) -> magpie.typedefs.SettingValue Search in order for matched value of :paramref:`constant_name`: 1. search in :py:data:`MAGPIE_CONSTANTS` 2. search in settings if specified 3. search alternative setting names (see below) 4. search in :mod:`magpie.constants` definitions 5. search in environment variables Parameter :paramref:`constant_name` is expected to have the format ``MAGPIE_[VARIABLE_NAME]`` although any value can be passed to retrieve generic settings from all above-mentioned search locations. If :paramref:`settings_name` is provided as alternative name, it is used as is to search for results if :paramref:`constant_name` was not found. Otherwise, ``magpie.[variable_name]`` is used for additional search when the format ``MAGPIE_[VARIABLE_NAME]`` was used for :paramref:`constant_name` (i.e.: ``MAGPIE_ADMIN_USER`` will also search for ``magpie.admin_user`` and so on for corresponding constants). :param constant_name: key to search for a value :param settings_container: WSGI application settings container (if not provided, uses found one in current thread) :param settings_name: alternative name for `settings` if specified :param default_value: default value to be returned if not found anywhere, and exception raises are disabled. :param raise_not_set: raise an exception if the found key is ``None``, search until last case if others are ``None`` :param raise_missing: raise exception if key is not found anywhere :param print_missing: print message if key is not found anywhere, return ``None`` :param empty_missing: consider an empty value for an existing key as if it was missing (i.e.: as if not set). :returns: found value or `default_value` :raises ValueError: if resulting value is invalid based on options (by default raise missing/empty/``None`` value) :raises LookupError: if no appropriate value could be found from all search locations (according to options) .. py:class:: TemporaryToken(*_, **__) Bases: :py:obj:`ziggurat_foundations.models.base.BaseModel`, :py:obj:`Base` Model that defines a token for temporary URL completion of a given pending operation. .. py:attribute:: __tablename__ :value: 'tmp_tokens' .. py:attribute:: token .. py:attribute:: operation .. py:attribute:: created .. py:attribute:: user_id .. py:attribute:: _user .. py:attribute:: user_pending_id .. py:attribute:: _pending_user .. py:attribute:: group_id .. py:attribute:: group .. py:method:: user() -> AnyUser .. py:method:: url(settings: magpie.typedefs.AnySettingsContainer = None) -> magpie.typedefs.Str .. py:method:: expired() -> bool .. py:method:: by_token(token: Union[magpie.typedefs.Str, sqlalchemy.dialects.postgresql.UUID], db_session: Optional[sqlalchemy.orm.session.Session] = None) -> Optional[TemporaryToken] :staticmethod: .. py:method:: by_user(user: AnyUser, db_session: Optional[sqlalchemy.orm.session.Session] = None) -> Optional[sqlalchemy.orm.query.Query] :staticmethod: .. py:method:: json() -> magpie.typedefs.JSON .. py:class:: TokenOperation Bases: :py:obj:`magpie.utils.ExtendedEnum` Supported operations by the temporary tokens. .. py:attribute:: GROUP_ACCEPT_TERMS :value: 'group-accept-terms' Temporary token associated to an URL endpoint called by a user that accepts the terms and conditions (T&C) to join a particular group. .. py:attribute:: USER_PASSWORD_RESET :value: 'user-password-reset' Temporary token associated to an URL endpoint to request a user password reset. .. py:attribute:: USER_REGISTRATION_CONFIRM_EMAIL :value: 'user-registration-confirm-email' Temporary token associated to a pending user registration that requires email validation by visiting the link. .. py:attribute:: USER_REGISTRATION_ADMIN_APPROVE :value: 'user-registration-admin-approve' Temporary token associated to a pending user registration that will be approved by an administrator when visited. .. py:attribute:: USER_REGISTRATION_ADMIN_DECLINE :value: 'user-registration-admin-decline' Temporary token associated to a pending user registration that will be declined by an administrator when visited. .. py:attribute:: WEBHOOK_USER_STATUS_ERROR :value: 'webhook-user-status-error' Temporary token employed to provide a callback URL that a registered webhook can call following the triggered event to indicate that the corresponding operation resulted into an invalid user status. .. py:function:: format_pending_user(user: magpie.models.UserPending, basic_info: bool = False, dotted: bool = False, container: Optional[magpie.typedefs.AnySettingsContainer] = None) -> magpie.typedefs.JSON Formats a :term:`Pending User` information into JSON. :param user: :term:`Pending User` to be formatted. :param basic_info: If ``True``, return only sufficient details to identify the :term:`Pending User` registration. :param dotted: Employ a dot (``.``) instead of underscore (``_``) to separate :term:`Pending User` from its basic information. :param container: application settings container used to retrieve more metadata about the :term:`Pending User`.