magpie.api.management.register.register_formats¶
Classes¶
Model that defines a token for temporary URL completion of a given pending operation. |
|
Supported operations by the temporary tokens. |
Functions¶
|
Evaluates the specified |
|
Search in order for matched value of |
|
Formats a Pending User information into JSON. |
Module Contents¶
- magpie.api.management.register.register_formats.evaluate_call(call: Callable[[], Any], fallback: Callable[[], None] | None = None, http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPInternalServerError, http_kwargs: magpie.typedefs.ParamsType | None = None, msg_on_fail: magpie.typedefs.Str = '', content: magpie.typedefs.JSON | None = None, content_type: magpie.typedefs.Str = CONTENT_TYPE_JSON, metadata: magpie.typedefs.JSON | None = None) Any[source]¶
Evaluates the specified
callwith a wrapped HTTP exception handling. On failure, tries to call.fallbackif specified, and finally raises the specifiedhttp_error.Any potential error generated by
fallbackorhttp_errorthemselves are treated asHTTPInternalServerError.Exceptions are generated using the standard output method formatted based on specified
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)
- Parameters:
call – function to call, MUST be specified as lambda: <function_call>
fallback – function to call (if any) when call failed, MUST be lambda: <function_call>
http_error – alternative exception to raise on call failure
http_kwargs – additional keyword arguments to pass to http_error if called in case of HTTP exception
msg_on_fail – message details to return in HTTP exception if call failed
content – json formatted additional content to provide in case of exception
content_type – format in which to return the exception (one of magpie.common.SUPPORTED_ACCEPT_TYPES)
metadata – request metadata to add to the response body. (see:
magpie.api.requests.get_request_info())
- Raises:
http_error – on call failure
HTTPInternalServerError – on fallback failure
- Returns:
whichever return value call might have if no exception occurred
- magpie.api.management.register.register_formats.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue[source]¶
- Search in order for matched value of
constant_name: search in
MAGPIE_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
magpie.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatMAGPIE_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,magpie.[variable_name]is used for additional search when the formatMAGPIE_[VARIABLE_NAME]was used forconstant_name(i.e.:MAGPIE_ADMIN_USERwill also search formagpie.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_not_set – raise an exception if the found key is
None, search until last case if others areNoneraise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneempty_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/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of
- class magpie.api.management.register.register_formats.TemporaryToken(*_, **__)[source]¶
Bases:
ziggurat_foundations.models.base.BaseModel,BaseModel that defines a token for temporary URL completion of a given pending operation.
- __tablename__ = 'tmp_tokens'¶
- token¶
- operation¶
- created¶
- user_id¶
- _user¶
- user_pending_id¶
- _pending_user¶
- group_id¶
- group¶
- static by_token(token: magpie.typedefs.Str | sqlalchemy.dialects.postgresql.UUID, db_session: sqlalchemy.orm.session.Session | None = None) TemporaryToken | None[source]¶
- class magpie.api.management.register.register_formats.TokenOperation[source]¶
Bases:
magpie.utils.ExtendedEnumSupported operations by the temporary tokens.
- GROUP_ACCEPT_TERMS = '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.
- USER_PASSWORD_RESET = 'user-password-reset'¶
Temporary token associated to an URL endpoint to request a user password reset.
- USER_REGISTRATION_CONFIRM_EMAIL = 'user-registration-confirm-email'¶
Temporary token associated to a pending user registration that requires email validation by visiting the link.
- USER_REGISTRATION_ADMIN_APPROVE = 'user-registration-admin-approve'¶
Temporary token associated to a pending user registration that will be approved by an administrator when visited.
- USER_REGISTRATION_ADMIN_DECLINE = 'user-registration-admin-decline'¶
Temporary token associated to a pending user registration that will be declined by an administrator when visited.
- WEBHOOK_USER_STATUS_ERROR = '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.
- magpie.api.management.register.register_formats.format_pending_user(user: magpie.models.UserPending, basic_info: bool = False, dotted: bool = False, container: magpie.typedefs.AnySettingsContainer | None = None) magpie.typedefs.JSON[source]¶
Formats a Pending User information into JSON.
- Parameters:
user – Pending User to be formatted.
basic_info – If
True, return only sufficient details to identify the Pending User registration.dotted – Employ a dot (
.) instead of underscore (_) to separate Pending User from its basic information.container – application settings container used to retrieve more metadata about the Pending User.