magpie.adapter.magpieservice

Store adapters to read data from magpie.

Attributes

ServicesAPI

CONTENT_TYPE_JSON

LOGGER

Classes

LooseVersion

This class abstracts handling of a project's versions.

MagpieService

Resource of service type.

ServiceStoreInterface

MagpieServiceStore

Registry for OWS services.

Functions

get_connected_session(→ sqlalchemy.orm.session.Session)

Retrieve the session attached to the request or recreated it to ensure it is open and within scoped transaction.

invalidate_service(→ None)

Invalidates any caching reference to the specified service name.

get_admin_cookies(→ magpie.typedefs.CookiesType)

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.

get_twitcher_url(→ magpie.typedefs.Str)

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

Module Contents

magpie.adapter.magpieservice.ServicesAPI[source]
class magpie.adapter.magpieservice.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.magpieservice.get_connected_session(request: pyramid.request.Request) sqlalchemy.orm.session.Session[source]

Retrieve the session attached to the request or recreated it to ensure it is open and within scoped transaction.

class magpie.adapter.magpieservice.MagpieService

Bases: Resource

Resource of service type.

__tablename__ = 'services'
resource_id
resource_type_name = 'service'
__mapper_args__
property permissions
property url
property type
Identifier matching ``magpie.services.ServiceInterface.service_type``.
property sync_type
Identifier matching ``magpie.cli.SyncServiceInterface.sync_type``.
property configuration
Configuration modifiers for parsing access to resources and permissions.
static by_service_name(service_name, db_session)
magpie.adapter.magpieservice.invalidate_service(service_name: magpie.typedefs.Str) None[source]

Invalidates any caching reference to the specified service name.

magpie.adapter.magpieservice.CONTENT_TYPE_JSON = 'application/json'[source]
magpie.adapter.magpieservice.get_admin_cookies(container: magpie.typedefs.AnySettingsContainer, verify: bool = True, raise_message: magpie.typedefs.Str | None = None) magpie.typedefs.CookiesType[source]
magpie.adapter.magpieservice.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.magpieservice.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.magpieservice.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.magpieservice.get_twitcher_url(container: magpie.typedefs.AnySettingsContainer | None = None, hostname: magpie.typedefs.Str | None = None) magpie.typedefs.Str[source]

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

See also

Documentation section Twitcher Settings for available setting combinations.

Parameters:
  • container – container that provides access to application settings.

  • hostname – override literal hostname to generate the URL instead of resolving using settings.

Returns:

resolved Twitcher URL

class magpie.adapter.magpieservice.ServiceStoreInterface(request)[source]

Bases: object

magpie.adapter.magpieservice.LOGGER[source]
class magpie.adapter.magpieservice.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.