magpie.adapter

Submodules

Package Contents

Classes

MagpieOWSSecurity

MagpieServiceStore

Registry for OWS services.

LooseVersion

This class abstracts handling of a project's versions.

SingletonMeta

A metaclass that creates a Singleton base class when called.

MagpieAdapter

HookContext

Context handlers associated to the request/response for the Service Hook to be evaluated.

Functions

evaluate_call(→ Any)

Evaluates the specified call with a wrapped HTTP exception handling. On failure, tries to call.

raise_http(→ NoReturn)

Raises error HTTP with standardized information formatted with content type.

valid_http(...)

Returns successful HTTP with standardized information formatted with content type. (see raise_http() for HTTP

verify_param(→ None)

Evaluate various parameter combinations given the requested verification flags. Given a failing verification,

get_request_info(→ magpie.typedefs.JSON)

Obtains additional content details about the request according to available information.

setup_magpie_configs(→ None)

Resolve known configuration file paths from settings or environment variables and process them for the application.

get_constant(→ magpie.typedefs.SettingValue)

Search in order for matched value of constant_name:

get_auth_config(→ pyramid.config.Configurator)

Generates Magpie application configuration with all utilities required for security and access control.

get_cookies(→ magpie.typedefs.CookiesType)

Retrieves a dictionary of cookie names and values from distinct implementations and container types.

get_json(→ magpie.typedefs.JSON)

Retrieves the 'JSON' body of a response using the property/callable according to the response's implementation.

get_logger(→ logging.Logger)

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when

get_magpie_url(→ magpie.typedefs.Str)

Obtains the configured Magpie URL entrypoint based on the various combinations of supported configuration settings.

get_settings(→ magpie.typedefs.SettingsType)

Retrieve application settings from a supported container.

import_target(→ Optional[Any])

Imports a target resource from a Python script as module.

is_json_body(→ bool)

normalize_field_pattern(→ magpie.typedefs.Str)

Escapes necessary regex pattern characters and applies start/end-of-line control characters.

setup_cache_settings(→ None)

Setup caching settings if not defined in configuration and enforce values if requested.

setup_pyramid_config(→ None)

Setup Pyramid utilities in the application configuration to define expected object references.

setup_session_config(→ None)

Setup database Session transaction handlers and Request properties for active User.

verify_user(→ pyramid.httpexceptions.HTTPException)

Verifies that a valid user authentication on the pointed Magpie instance (via configuration) also results into a

Attributes

magpie_version

SigninAPI

CONTENT_TYPE_JSON

LOGGER

magpie.adapter.magpie_version = '4.0.0'
class magpie.adapter.MagpieOWSSecurity(container: magpie.typedefs.AnySettingsContainer)[source]

Bases: twitcher.interface.OWSSecurityInterface

_cached_request: Dict[uuid.UUID, pyramid.request.Request]
_get_service_cached(service_name: magpie.typedefs.Str, request_uuid: uuid.UUID) Tuple[magpie.services.ServiceInterface, Dict[str, magpie.typedefs.AnyValue]][source]

Cache this method with beaker based on the provided caching key parameters.

If the cache is not hit (expired timeout or new key entry), calls service_factory() to retrieve the actual ServiceInterface implementation. Otherwise, returns the cached service to avoid SQL queries.

Note

Function arguments are required to generate caching keys by which cached elements will be retrieved. Those arguments must be serializable to generate the cache key (i.e.: cannot pass a Request object that contains session and other unserializable/circular references).

get_service(request: pyramid.request.Request) magpie.services.ServiceInterface[source]

Obtains the service referenced by the request.

Caching is automatically handled according to configured application settings and whether the specific service name being requested was already processed recently and not expired.

verify_request(request: pyramid.request.Request) bool[source]

Verify that the service request is allowed.

Added in version 3.18: Available only in Twitcher >= 0.6.x.

check_request(request: pyramid.request.Request) None[source]

Verifies if the request user has access to the targeted resource according to parent service and permissions.

If the request path corresponds to configured Twitcher proxy, evaluate the ACL. Otherwise, ignore request access validation.

In the case Twitcher proxy path is matched, the Logged User MUST be allowed access following Effective Permissions resolution via ACL. Otherwise, :exception:`OWSAccessForbidden` is raised.

Failing to parse the request or any underlying component that raises an exception will be left up to the parent caller to handle the exception. In most typical use case, this means Twitcher will raise a generic :exception:`OWSException` with NoApplicableCode, unless the exception was more specifically handled.

Raises:
  • OWSAccessForbidden – If the user does not have access to the targeted resource under the service.

  • HTTPBadRequest – If a request parsing error was detected when trying to resolve the permission based on the service/resource.

  • Exception – Any derived exception that was not explicitly handled is re-raised directly after logging the event.

Returns:

Nothing if user has access.

update_request_cookies(request: pyramid.request.Request) None[source]

Ensure login of the user and update the request cookies if Twitcher is in a special configuration.

Only update if MAGPIE_COOKIE_NAME is missing and is retrievable from access_token field within the Authorization header. Counter-validate the login procedure by calling Magpie’s /session which should indicate if there is a logged user.

class magpie.adapter.MagpieServiceStore(request: pyramid.request.Request)[source]

Bases: twitcher.store.ServiceStoreInterface

Registry for OWS services.

Uses magpie to fetch service url and attributes.

save_service(name: magpie.typedefs.Str, url: magpie.typedefs.Str, *args: Any, **kwargs: Any) NoReturn[source]

Store is read-only, use Magpie API to add services.

Note

Multiple redundant parameters are applied to support different Twitcher versions.

  • Twitcher <=0.5.x uses (service, *args, **kwargs)

  • Twitcher >=0.6.x uses (name, url, *args, **kwargs)

  • Some alternate interfaces also provided extra parameters at some point.

delete_service(name: magpie.typedefs.Str, *args: Any, **kwargs: Any) NoReturn[source]

Store is read-only, use Magpie API to delete services.

list_services() List[twitcher.models.Service][source]

Lists all services registered in Magpie.

_fetch_by_name_cached(service_name: magpie.typedefs.Str) twitcher.models.Service[source]

Cache this method with beaker based on the provided caching key parameters.

If the cache is not hit (expired timeout or new key entry), calls fetch_by_name() to retrieve the actual twitcher.datatype.Service definition. Otherwise, returns the cached item to avoid SQL queries.

Note

Function arguments are required to generate caching keys by which cached elements will be retrieved.

Note

Method fetch_by_name() gets triggered by twitcher.owsproxy.owsproxy_view() after successful validation of granted access for Logged User to the service / resources following call to magpie.adapter.magpieowssecurity.MagpieOWSSecurity.check_request() in order to send and retrieve the actual response of that proxied service and forward it back to the requesting user. Caching helps greatly reduce recurrent SQL queries to convert Twitcher to Magpie service.

fetch_by_name(name: magpie.typedefs.Str) twitcher.models.Service[source]

Gets twitcher.datatype.Service corresponding to magpie.models.Service by name.

fetch_by_url(url: magpie.typedefs.Str) twitcher.models.Service[source]

Gets service for given url from mongodb storage.

abstract clear_services() NoReturn[source]

Magpie store is read-only, use magpie api to delete services.

magpie.adapter.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 call with a wrapped HTTP exception handling. On failure, tries to call.

fallback if specified, and finally raises the specified http_error.

Any potential error generated by fallback or http_error themselves are treated as HTTPInternalServerError.

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.adapter.raise_http(http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPInternalServerError, http_kwargs: magpie.typedefs.ParamsType | None = None, detail: magpie.typedefs.Str = '', content: magpie.typedefs.JSON | None = None, content_type: magpie.typedefs.Str = CONTENT_TYPE_JSON, metadata: magpie.typedefs.JSON | None = None, nothrow: bool = False) NoReturn[source]

Raises error HTTP with standardized information formatted with content type.

The content contains the corresponding http error code, the provided message as detail and optional specified additional json content (kwarg dict).

See also

valid_http() for HTTP successful calls

Parameters:
  • http_error – any derived class from base HTTPError (default: HTTPInternalServerError)

  • http_kwargs – additional keyword arguments to pass to http_error if called in case of HTTP exception

  • detail – additional message information (default: empty)

  • content – JSON formatted content to include

  • 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())

  • nothrow – returns the error response instead of raising it automatically, but still handles execution errors

Raises:

HTTPError – formatted raised exception with additional details and HTTP code

Returns:

HTTPError formatted exception with additional details and HTTP code only if nothrow is True

magpie.adapter.valid_http(http_success: Type[pyramid.httpexceptions.HTTPSuccessful] | Type[pyramid.httpexceptions.HTTPRedirection] = HTTPOk, http_kwargs: magpie.typedefs.ParamsType | None = None, detail: magpie.typedefs.Str | None = '', content: magpie.typedefs.JSON | None = None, content_type: magpie.typedefs.Str | None = CONTENT_TYPE_JSON, metadata: magpie.typedefs.JSON | None = None) pyramid.httpexceptions.HTTPSuccessful | pyramid.httpexceptions.HTTPRedirection[source]

Returns successful HTTP with standardized information formatted with content type. (see raise_http() for HTTP error calls)

Parameters:
  • http_success – any derived class from valid HTTP codes (<400) (default: HTTPOk)

  • http_kwargs – additional keyword arguments to pass to http_success when called

  • detail – additional message information (default: empty)

  • content – json formatted content to include

  • 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())

Returns:

formatted successful response with additional details and HTTP code

magpie.adapter.verify_param(param: Any, param_compare: Any | List[Any] | None = None, param_name: magpie.typedefs.Str | None = None, param_content: magpie.typedefs.JSON | None = None, with_param: bool = True, http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPBadRequest, 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, not_none: bool = False, not_empty: bool = False, not_in: bool = False, not_equal: bool = False, is_true: bool = False, is_false: bool = False, is_none: bool = False, is_empty: bool = False, is_in: bool = False, is_equal: bool = False, is_type: bool = False, matches: bool = False) None[source]

Evaluate various parameter combinations given the requested verification flags. Given a failing verification, directly raises the specified http_error. Invalid usage exceptions generated by this verification process are treated as HTTPInternalServerError. Exceptions are generated using the standard output method.

Parameters:
  • param – parameter value to evaluate

  • param_compare – Other value(s) to test param against. Can be an iterable (single value resolved as iterable unless None). To test for None type, use is_none/not_none flags instead.

  • param_name – name of the tested parameter returned in response if specified for debugging purposes

  • param_content – Additional JSON content to apply to generated error content on raise when with_param is True. Must be JSON serializable. Provided content can override generated error parameter if matching fields.

  • with_param – On raise, adds values of param, param_name and param_compare, as well as additional failing conditions metadata to the JSON response body for each of the corresponding value.

  • http_error – derived exception to raise on test failure (default: HTTPBadRequest)

  • http_kwargs – additional keyword arguments to pass to http_error called in case of HTTP exception

  • msg_on_fail – message details to return in HTTP exception if flag condition 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())

  • not_none – test that param is not None type

  • not_empty – test that param is not an empty iterable (string, list, set, etc.)

  • not_in – test that param does not exist in param_compare values

  • not_equal – test that param is not equal to param_compare value

  • is_true – test that param is True

  • is_false – test that param is False

  • is_none – test that param is None type

  • is_empty – test param for an empty iterable (string, list, set, etc.)

  • is_in – test that param exists in param_compare values

  • is_equal – test that param equals param_compare value

  • is_type – test that param is of same type as specified by param_compare type

  • matches – test that param matches the regex specified by param_compare value

Raises:
  • HTTPError – if tests fail, specified exception is raised (default: HTTPBadRequest)

  • HTTPInternalServerError – for evaluation error

Returns:

nothing if all tests passed

magpie.adapter.get_request_info(request: pyramid.request.Request | pyramid.httpexceptions.HTTPException, default_message: magpie.typedefs.Str | None = None, exception_details: bool = False) magpie.typedefs.JSON[source]

Obtains additional content details about the request according to available information.

magpie.adapter.SigninAPI[source]
magpie.adapter.setup_magpie_configs(settings: magpie.typedefs.SettingsType, db_session: sqlalchemy.orm.session.Session | None = None, setup_providers: bool = True, setup_permissions: bool = True, setup_webhooks: bool = True, skip_registration: bool = False) None[source]

Resolve known configuration file paths from settings or environment variables and process them for the application.

class magpie.adapter.LooseVersion(version: str)[source]

Bases: packaging.version.Version, VersionInterface

This class abstracts handling of a project’s versions.

A Version instance is comparison aware and can be compared and sorted using the standard Python interfaces.

>>> v1 = Version("1.0a5")
>>> v2 = Version("1.0")
>>> v1
<Version('1.0a5')>
>>> v2
<Version('1.0')>
>>> v1 < v2
True
>>> v1 == v2
False
>>> v1 > v2
False
>>> v1 >= v2
False
>>> v1 <= v2
True

Initialize a Version object.

Parameters:

version – The string representation of a version which will be parsed and normalized before use.

Raises:

InvalidVersion – If the version does not conform to PEP 440 in any way then this exception will be raised.

property version: Tuple[int | str, Ellipsis]
property patch
_cmp(other: LooseVersion | str) int[source]
magpie.adapter.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:
  1. search in MAGPIE_CONSTANTS

  2. search in settings if specified

  3. search alternative setting names (see below)

  4. search in magpie.constants definitions

  5. search in environment variables

Parameter 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 settings_name is provided as alternative name, it is used as is to search for results if constant_name was not found. Otherwise, magpie.[variable_name] is used for additional search when the format MAGPIE_[VARIABLE_NAME] was used for constant_name (i.e.: MAGPIE_ADMIN_USER will also search for magpie.admin_user and 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 are None

  • raise_missing – raise exception if key is not found anywhere

  • print_missing – print message if key is not found anywhere, return None

  • 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)

  • LookupError – if no appropriate value could be found from all search locations (according to options)

magpie.adapter.get_auth_config(container: magpie.typedefs.AnySettingsContainer) pyramid.config.Configurator[source]

Generates Magpie application configuration with all utilities required for security and access control.

magpie.adapter.CONTENT_TYPE_JSON = 'application/json'[source]
class magpie.adapter.SingletonMeta[source]

Bases: type

A metaclass that creates a Singleton base class when called.

Create a class such that:

@six.add_metaclass(SingletonMeta)
class A(object):
    pass

@six.add_metaclass(SingletonMeta)
class B(object):
    pass

a1 = A()
a2 = A()
b1 = B()
b2 = B()
a1 is a2    # True
b1 is b2    # True
a1 is b1    # False
_instances
__call__(*args, **kwargs)[source]

Call self as a function.

magpie.adapter.get_cookies(request_or_response: magpie.typedefs.AnyRequestType | magpie.typedefs.AnyResponseType) magpie.typedefs.CookiesType[source]

Retrieves a dictionary of cookie names and values from distinct implementations and container types.

Parameters:

request_or_response – Object that potentially contains cookies, by literal property or corresponding headers.

Returns:

Found cookies.

magpie.adapter.get_json(request_or_response: magpie.typedefs.AnyRequestType | magpie.typedefs.AnyResponseType) magpie.typedefs.JSON[source]

Retrieves the ‘JSON’ body of a response using the property/callable according to the response’s implementation.

magpie.adapter.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.Str | None = None) logging.Logger[source]

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is logging.NOTSET.

magpie.adapter.get_magpie_url(container: magpie.typedefs.AnySettingsContainer | None = None) magpie.typedefs.Str[source]

Obtains the configured Magpie URL entrypoint based on the various combinations of supported configuration settings.

See also

Documentation section Application Settings for available setting combinations.

Parameters:

container – container that provides access to application settings.

Returns:

resolved Magpie URL

magpie.adapter.get_settings(container: magpie.typedefs.AnySettingsContainer | None, app: bool = False) magpie.typedefs.SettingsType[source]

Retrieve application settings from a supported container.

Parameters:
  • container – supported container with a handle to application settings.

  • app – allow retrieving from current thread registry if no container was defined.

Returns:

found application settings dictionary.

Raises:

TypeError – when no application settings could be found or unsupported container.

magpie.adapter.import_target(target: magpie.typedefs.Str, default_root: magpie.typedefs.Str | None = None) Any | None[source]

Imports a target resource from a Python script as module.

The Python script does not need to be defined within a module directory (i.e.: with __init__.py). Files can be imported from virtually anywhere. To avoid name conflicts in generated module references, each imported target employs its full escaped file path as module name.

Format expected as follows:

"path/to/script.py:function"
Parameters:
  • target – Resource to be imported.

  • default_root – Root directory to employ if target is relative (default magpie.constants.MAGPIE_ROOT).

Returns:

Found and imported resource or None.

magpie.adapter.is_json_body(body: Any, return_body: bool = False) bool[source]
magpie.adapter.normalize_field_pattern(pattern: magpie.typedefs.Str, escape: bool = True) magpie.typedefs.Str[source]

Escapes necessary regex pattern characters and applies start/end-of-line control characters.

magpie.adapter.setup_cache_settings(settings: magpie.typedefs.SettingsType, force: bool = False, enabled: bool = False, expire: int = 0) None[source]

Setup caching settings if not defined in configuration and enforce values if requested.

Required caching regions that were missing from configuration are initiated with disabled caching by default. This ensures that any decorators or region references will not cause unknown key or region errors.

Parameters:
  • settings – reference to application settings that will be updated in place.

  • force – enforce following parameters, otherwise only ensure that caching regions exist.

  • enabled – enable caching when enforced settings is requested.

  • expire – cache expiration delay if setting values are enforced and enabled.

magpie.adapter.setup_pyramid_config(config: pyramid.config.Configurator) None[source]

Setup Pyramid utilities in the application configuration to define expected object references.

magpie.adapter.setup_session_config(config: pyramid.config.Configurator) None[source]

Setup database Session transaction handlers and Request properties for active User.

magpie.adapter.LOGGER[source]
magpie.adapter.verify_user(request: pyramid.request.Request) pyramid.httpexceptions.HTTPException[source]

Verifies that a valid user authentication on the pointed Magpie instance (via configuration) also results into a valid user authentication with the current Twitcher instance to ensure settings match between them.

Parameters:

request – an HTTP request with valid authentication token/cookie credentials.

Returns:

appropriate HTTP success or error response with details about the result.

class magpie.adapter.MagpieAdapter(container: magpie.typedefs.AnySettingsContainer)[source]

Bases: twitcher.adapter.base.AdapterInterface

property name: magpie.typedefs.Str[source]
reset() None[source]
describe_adapter() magpie.typedefs.JSON[source]
servicestore_factory(request: pyramid.request.Request) magpieservice.MagpieServiceStore[source]
abstract tokenstore_factory(request: pyramid.request.Request) twitcher.store.AccessTokenStoreInterface[source]

Unused token store implementation.

Changed in version 3.18: Available only in Twitcher <= 0.5.x.

owsregistry_factory(request: pyramid.request.Request) twitcher.owsregistry.OWSRegistry[source]

Creates the OWSRegistry implementation derived from MagpieServiceStore.

Added in version 3.18: Available only in Twitcher >= 0.6.x.

owssecurity_factory(request: magpie.typedefs.AnySettingsContainer | None = None) magpieowssecurity.MagpieOWSSecurity[source]

Creates the OWSSecurity implementation derived from MagpieOWSSecurity.

Changed in version 3.18: Method request does not exist starting in Twitcher >= 0.6.x.

owsproxy_config(container: magpie.typedefs.AnySettingsContainer) None[source]
configurator_factory(container: magpie.typedefs.AnySettingsContainer) pyramid.config.Configurator[source]
_apply_hooks(instance: pyramid.request.Request | pyramid.response.Response, service_name: magpie.typedefs.Str, hook_type: magpie.typedefs.ServiceHookType, method: magpie.typedefs.Str, path: magpie.typedefs.Str, query: magpie.typedefs.Str) pyramid.request.Request | pyramid.response.Response[source]

Executes the hooks processing chain.

static _proxied_service_path(request: pyramid.request.Request) magpie.typedefs.Str[source]

Extract the request extra path of the proxied service without Twitcher proxy prefix.

request_hook(request: pyramid.request.Request, service: twitcher.models.service.ServiceConfig) pyramid.request.Request[source]

Apply modifications onto the request before sending it.

Added in version 3.25: Requires Twitcher >= 0.7.x.

Request members employed after this hook is called include: - Request.headers() - Request.method() - Request.body()

This method can modified those members to adapt the request for specific service logic.

response_hook(response: pyramid.response.Response, service: twitcher.models.service.ServiceConfig) pyramid.response.Response[source]

Apply modifications onto the response from sent request.

Added in version 3.25: Requires Twitcher >= 0.7.x.

The received response from the proxied service is normally returned directly. This method can modify the response to adapt it for specific service logic.

send_request(request: pyramid.request.Request, service: twitcher.models.service.ServiceConfig) pyramid.response.Response[source]

Send the request to the proxied service and handle its response.

Added in version 3.31: Requires Twitcher >= 0.8.x.

Because requests are sometimes handled using requests depending on the service type, the request reference in the produced response is not always set. Ensure it is applied to allow response_hook() retrieving it when attempting to resolve the proxied service path.

class magpie.adapter.HookContext(instance: pyramid.request.Request | pyramid.response.Response, adapter: MagpieAdapter, config: magpie.typedefs.ServiceConfigItem, hook: magpie.typedefs.ServiceHookConfigItem)[source]

Bases: object

Context handlers associated to the request/response for the Service Hook to be evaluated.

Dispatch calls to database or other derived operations on demand as much as possible to minimize the impact of retrieving some parameters by each request that requires this hook context.

property service: magpie.services.ServiceInterface[source]

Service implementation that defines the Resource structure and Permission resolution method.

property resource: magpie.models.Resource[source]

Database Resource that represents the Service reference implementation.

adapter: MagpieAdapter[source]
request: pyramid.request.Request[source]
response: pyramid.response.Response | None[source]
config: magpie.typedefs.ServiceConfigItem[source]
hook: magpie.typedefs.ServiceHookConfigItem[source]
_service: magpie.services.ServiceInterface | None[source]