:mod:`magpie.adapter` ===================== .. py:module:: magpie.adapter Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 magpieowssecurity/index.rst magpieservice/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: magpie.adapter.MagpieOWSSecurity magpie.adapter.MagpieServiceStore magpie.adapter.MagpieAdapter Functions ~~~~~~~~~ .. autoapisummary:: magpie.adapter.raise_http magpie.adapter.valid_http magpie.adapter.get_engine magpie.adapter.get_session_factory magpie.adapter.get_tm_session magpie.adapter.get_auth_config magpie.adapter.debug_cookie_identify magpie.adapter.get_user magpie.adapter.verify_user .. py:class:: MagpieOWSSecurity(request) Bases: :class:`twitcher.owssecurity.OWSSecurityInterface` .. method:: check_request(self, request) .. method:: 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. .. py:class:: MagpieServiceStore(: Request, request) Bases: :class:`twitcher.store.ServiceStoreInterface` Registry for OWS services. Uses magpie to fetch service url and attributes. .. method:: save_service(self, service, overwrite=True, request=None) :abstractmethod: Magpie store is read-only, use magpie api to add services. .. method:: delete_service(self, name, request=None) :abstractmethod: Magpie store is read-only, use magpie api to delete services. .. method:: list_services(self, request=None) Lists all services registered in magpie. .. method:: fetch_by_name(self, name, visibility=None, request=None) Gets service for given ``name`` from magpie. .. method:: fetch_by_url(self, url, request=None) Gets service for given ``url`` from mongodb storage. .. method:: clear_services(self, request=None) :abstractmethod: Magpie store is read-only, use magpie api to delete services. .. function:: 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) -> NoReturn 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). .. seealso:: :func:`valid_http` for HTTP successful calls :param http_error: any derived class from base `HTTPError` (default: `HTTPInternalServerError`) :param http_kwargs: additional keyword arguments to pass to `http_error` if called in case of HTTP exception :param detail: additional message information (default: empty) :param content: json formatted content to include :param content_type: format in which to return the exception (one of `magpie.common.SUPPORTED_ACCEPT_TYPES`) :param 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` .. function:: 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 :func:`raise_http` for HTTP error calls) :param http_success: any derived class from *valid* HTTP codes (<400) (default: `HTTPOk`) :param http_kwargs: additional keyword arguments to pass to `http_success` when called :param detail: additional message information (default: empty) :param content: json formatted content to include :param 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 .. data:: SigninAPI .. function:: get_engine(container: Optional[AnySettingsContainer] = None, prefix: Str = 'sqlalchemy.', **kwargs: Any) -> Engine .. function:: get_session_factory(engine) .. function:: get_tm_session(session_factory, transaction_manager) 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) .. function:: get_auth_config(container: AnySettingsContainer) -> Configurator Generates Magpie application configuration with all utilities required for security and access control. .. data:: LOGGER .. function:: debug_cookie_identify(request) 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 :func:`pyramid.AuthTktAuthenticationPolicy.cookie.identify` called via :func:`request.unauthenticated_userid` within :func:`get_user` to provide additional logging. .. seealso:: - :class:`pyramid.authentication.AuthTktCookieHelper` - :class:`pyramid.authentication.AuthTktAuthenticationPolicy` .. function:: get_user(request: Request) -> Optional[User] Obtains the authenticated user from the request (if any). :param request: incoming HTTP request potentially containing authentication definitions. :return: the authenticated user if parameters were valid (good credentials, not expired, etc.) or ``None``. .. function:: verify_user(request: Request) -> HTTPException 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. :param request: an HTTP request with valid authentication token/cookie credentials. :return: appropriate HTTP success or error response with details about the result. .. py:class:: MagpieAdapter(container) Bases: :class:`twitcher.adapter.base.AdapterInterface` .. method:: name(self) -> Str :property: .. method:: describe_adapter(self) -> JSON .. method:: servicestore_factory(self: Request, request) -> MagpieServiceStore .. method:: tokenstore_factory(self: Request, request) -> AccessTokenStoreInterface :abstractmethod: .. method:: owssecurity_factory(self: Request, request) -> MagpieOWSSecurity .. method:: owsproxy_config(self: AnySettingsContainer, container) -> None .. method:: configurator_factory(self: AnySettingsContainer, container) -> Configurator