magpie.adapter

Package Contents

Classes

MagpieOWSSecurity

MagpieServiceStore

Registry for OWS services.

MagpieAdapter

Initialize self. See help(type(self)) for accurate signature.

Functions

raise_http(http_error: Type[HTTPError] = HTTPInternalServerError, http_kwargs: Optional[ParamsType] = None, detail: Str = ‘’, content: Optional[JSON] = None, content_type: Str = CONTENT_TYPE_JSON, nothrow: bool = False) → Optional[HTTPException]

Raises error HTTP with standardized information formatted with content type.

valid_http(http_success: Union[Type[HTTPSuccessful], Type[HTTPRedirection]] = HTTPOk, http_kwargs: Optional[ParamsType] = None, detail: Optional[Str] = ‘’, content: Optional[JSON] = None, content_type: Optional[Str] = CONTENT_TYPE_JSON) → Union[HTTPSuccessful, HTTPRedirection]

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

get_engine(container: Optional[AnySettingsContainer] = None, prefix: Str = ‘sqlalchemy.’, **kwargs: Any) → Engine

get_session_factory(engine)

get_tm_session(session_factory, transaction_manager)

Get a sqlalchemy.orm.Session instance backed by a transaction.

get_auth_config(container: AnySettingsContainer) → Configurator

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

debug_cookie_identify(request)

Logs debug information about request cookie.

get_user(request: Request) → Optional[User]

Obtains the authenticated user from the request (if any).

verify_user(request: Request) → HTTPException

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

class magpie.adapter.MagpieOWSSecurity(request)[source]

Bases: twitcher.owssecurity.OWSSecurityInterface

check_request(self, request)
update_request_cookies(self, request)

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 in Authorization header. Counter-validate the login procedure by calling Magpie’s /session which should indicated a logged user.

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

Bases: twitcher.store.ServiceStoreInterface

Registry for OWS services.

Uses magpie to fetch service url and attributes.

abstract save_service(self, service, overwrite=True, request=None)

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

abstract delete_service(self, name, request=None)

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

list_services(self, request=None)

Lists all services registered in magpie.

fetch_by_name(self, name, visibility=None, request=None)

Gets service for given name from magpie.

fetch_by_url(self, url, request=None)

Gets service for given url from mongodb storage.

abstract clear_services(self, request=None)

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

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

  • 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: Union[Type[HTTPSuccessful], Type[HTTPRedirection]] = HTTPOk, http_kwargs: Optional[ParamsType] = None, detail: Optional[Str] = '', content: Optional[JSON] = None, content_type: Optional[Str] = CONTENT_TYPE_JSON) → Union[HTTPSuccessful, 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)

Returns

formatted successful response with additional details and HTTP code

magpie.adapter.SigninAPI[source]
magpie.adapter.get_engine(container: Optional[AnySettingsContainer] = None, prefix: Str = 'sqlalchemy.', **kwargs: Any) → Engine[source]
magpie.adapter.get_session_factory(engine)[source]
magpie.adapter.get_tm_session(session_factory, transaction_manager)[source]

Get a sqlalchemy.orm.Session instance backed by a transaction.

This function will hook the session to the transaction manager which will take care of committing any changes.

  • When using pyramid_tm it will automatically be committed or aborted depending on whether an exception is raised.

  • When using scripts you should wrap the session in a manager yourself. For example:

    import transaction
    
    engine = get_engine(settings)
    session_factory = get_session_factory(engine)
    with transaction.manager:
        db_session = get_tm_session(session_factory, transaction.manager)
    
magpie.adapter.get_auth_config(container: AnySettingsContainer) → Configurator[source]

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

magpie.adapter.LOGGER[source]

Logs debug information about request cookie.

Warning

This function is intended for debugging purposes only. It reveals sensible configuration information.

Re-implements basic functionality of pyramid.AuthTktAuthenticationPolicy.cookie.identify() called via request.unauthenticated_userid() within get_user() to provide additional logging.

See also

  • pyramid.authentication.AuthTktCookieHelper

  • pyramid.authentication.AuthTktAuthenticationPolicy

magpie.adapter.get_user(request: Request) → Optional[User][source]

Obtains the authenticated user from the request (if any).

Parameters

request – incoming HTTP request potentially containing authentication definitions.

Returns

the authenticated user if parameters were valid (good credentials, not expired, etc.) or None.

magpie.adapter.verify_user(request: Request) → 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)[source]

Bases: six.with_metaclass()

Initialize self. See help(type(self)) for accurate signature.

property name(self) → Str[source]
describe_adapter(self) → JSON[source]
servicestore_factory(self: Request, request) → MagpieServiceStore[source]
abstract tokenstore_factory(self: Request, request) → AccessTokenStoreInterface[source]
owssecurity_factory(self: Request, request) → MagpieOWSSecurity[source]
owsproxy_config(self: AnySettingsContainer, container) → None[source]
configurator_factory(self: AnySettingsContainer, container) → Configurator[source]