magpie.adapter.magpieservice ============================ .. py:module:: magpie.adapter.magpieservice .. autoapi-nested-parse:: Store adapters to read data from magpie. Attributes ---------- .. autoapisummary:: magpie.adapter.magpieservice.ServicesAPI magpie.adapter.magpieservice.CONTENT_TYPE_JSON magpie.adapter.magpieservice.LOGGER Classes ------- .. autoapisummary:: magpie.adapter.magpieservice.LooseVersion magpie.adapter.magpieservice.MagpieService magpie.adapter.magpieservice.ServiceStoreInterface magpie.adapter.magpieservice.MagpieServiceStore Functions --------- .. autoapisummary:: magpie.adapter.magpieservice.get_connected_session magpie.adapter.magpieservice.invalidate_service magpie.adapter.magpieservice.get_admin_cookies magpie.adapter.magpieservice.get_logger magpie.adapter.magpieservice.get_magpie_url magpie.adapter.magpieservice.get_settings magpie.adapter.magpieservice.get_twitcher_url Module Contents --------------- .. py:data:: ServicesAPI .. py:class:: LooseVersion(version: str) Bases: :py:obj:`packaging.version.Version`, :py:obj:`VersionInterface` This class abstracts handling of a project's versions. A :class:`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 >>> v2 >>> v1 < v2 True >>> v1 == v2 False >>> v1 > v2 False >>> v1 >= v2 False >>> v1 <= v2 True Initialize a Version object. :param 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. .. py:property:: version :type: Tuple[Union[int, str], Ellipsis] .. py:property:: patch .. py:method:: _cmp(other: Union[LooseVersion, str]) -> int .. py:function:: get_connected_session(request: pyramid.request.Request) -> sqlalchemy.orm.session.Session Retrieve the session attached to the request or recreated it to ensure it is open and within scoped transaction. .. py:class:: MagpieService Bases: :py:obj:`Resource` Resource of `service` type. .. py:attribute:: __tablename__ :value: 'services' .. py:attribute:: resource_id .. py:attribute:: resource_type_name :value: 'service' .. py:attribute:: __mapper_args__ .. py:property:: permissions .. py:property:: url .. py:property:: type Identifier matching ``magpie.services.ServiceInterface.service_type``. .. py:property:: sync_type Identifier matching ``magpie.cli.SyncServiceInterface.sync_type``. .. py:property:: configuration Configuration modifiers for parsing access to resources and permissions. .. seealso:: - :meth:`magpie.services.ServiceInterface.get_config` .. py:method:: by_service_name(service_name, db_session) :staticmethod: .. py:function:: invalidate_service(service_name: magpie.typedefs.Str) -> None Invalidates any caching reference to the specified service name. .. py:data:: CONTENT_TYPE_JSON :value: 'application/json' .. py:function:: get_admin_cookies(container: magpie.typedefs.AnySettingsContainer, verify: bool = True, raise_message: Optional[magpie.typedefs.Str] = None) -> magpie.typedefs.CookiesType .. py:function:: get_logger(name: magpie.typedefs.Str, level: Optional[int] = None, force_stdout: bool = None, message_format: Optional[magpie.typedefs.Str] = None, datetime_format: Optional[magpie.typedefs.Str] = None) -> logging.Logger Immediately sets the logger level to avoid duplicate log outputs from the `root logger` and `this logger` when `level` is ``logging.NOTSET``. .. py:function:: get_magpie_url(container: Optional[magpie.typedefs.AnySettingsContainer] = None) -> magpie.typedefs.Str Obtains the configured Magpie URL entrypoint based on the various combinations of supported configuration settings. .. seealso:: Documentation section :ref:`config_app_settings` for available setting combinations. :param container: container that provides access to application settings. :return: resolved Magpie URL .. py:function:: get_settings(container: Optional[magpie.typedefs.AnySettingsContainer], app: bool = False) -> magpie.typedefs.SettingsType Retrieve application settings from a supported container. :param container: supported container with a handle to application settings. :param app: allow retrieving from current thread registry if no container was defined. :return: found application settings dictionary. :raise TypeError: when no application settings could be found or unsupported container. .. py:function:: get_twitcher_url(container: Optional[magpie.typedefs.AnySettingsContainer] = None, hostname: Optional[magpie.typedefs.Str] = None) -> magpie.typedefs.Str Obtains the configured Twitcher URL entrypoint based on various combinations of supported configuration settings. .. seealso:: Documentation section :ref:`config_twitcher` for available setting combinations. :param container: container that provides access to application settings. :param hostname: override literal hostname to generate the URL instead of resolving using settings. :return: resolved Twitcher URL .. py:class:: ServiceStoreInterface(request) Bases: :py:obj:`object` .. py:data:: LOGGER .. py:class:: MagpieServiceStore(request: pyramid.request.Request) Bases: :py:obj:`twitcher.store.ServiceStoreInterface` Registry for OWS services. Uses magpie to fetch service url and attributes. .. py:method:: save_service(name: magpie.typedefs.Str, url: magpie.typedefs.Str, *args: Any, **kwargs: Any) -> NoReturn Store is read-only, use `Magpie` :term:`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. .. py:method:: delete_service(name: magpie.typedefs.Str, *args: Any, **kwargs: Any) -> NoReturn Store is read-only, use :mod:`Magpie` :term:`API` to delete services. .. py:method:: list_services() -> List[twitcher.models.Service] Lists all services registered in `Magpie`. .. py:method:: _fetch_by_name_cached(service_name: magpie.typedefs.Str) -> twitcher.models.Service Cache this method with :py:mod:`beaker` based on the provided caching key parameters. If the cache is not hit (expired timeout or new key entry), calls :meth:`fetch_by_name` to retrieve the actual :class:`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 :meth:`fetch_by_name` gets triggered by :meth:`twitcher.owsproxy.owsproxy_view` after successful validation of granted access for :term:`Logged User` to the service / resources following call to :meth:`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. .. seealso:: - :meth:`magpie.adapter.magpieowssecurity.MagpieOWSSecurity.get_service` - :meth:`magpie.adapter.magpieservice.MagpieServiceStore.fetch_by_name` .. py:method:: fetch_by_name(name: magpie.typedefs.Str) -> twitcher.models.Service Gets :class:`twitcher.datatype.Service` corresponding to :class:`magpie.models.Service` by ``name``. .. py:method:: fetch_by_url(url: magpie.typedefs.Str) -> twitcher.models.Service Gets service for given ``url`` from mongodb storage. .. py:method:: clear_services() -> NoReturn :abstractmethod: Magpie store is read-only, use magpie api to delete services.