magpie.api.management.service.service_utils

Attributes

SERVICES_PHOENIX_ALLOWED

SERVICE_TYPE_DICT

LOGGER

Classes

Permission

Applicable Permission values (names) under certain Service and Resource.

Functions

create_group_resource_permission_response(...)

Creates a permission on a group/resource combination if it is permitted and not conflicting.

format_service(→ magpie.typedefs.JSON)

Formats a Service information into JSON.

get_constant(→ magpie.typedefs.SettingValue)

Search in order for matched value of constant_name:

sync_services_phoenix(→ bool)

Syncs Magpie services by pushing updates to Phoenix.

get_logger(→ logging.Logger)

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

create_service(→ pyramid.httpexceptions.HTTPException)

Generates an instance to register a new service.

get_services_by_type(→ Iterable[magpie.models.Service])

Obtains all services that correspond to requested service-type.

add_service_getcapabilities_perms(service, db_session)

filter_service_types(→ Optional[List[magpie.typedefs.Str]])

Obtains all valid case-insensitive service-type names from a filtered comma-separated list.

Module Contents

magpie.api.management.service.service_utils.create_group_resource_permission_response(group: magpie.models.Group, resource: magpie.typedefs.ServiceOrResourceType, permission: magpie.permissions.PermissionSet, db_session: sqlalchemy.orm.session.Session, overwrite: bool = False) pyramid.httpexceptions.HTTPException[source]

Creates a permission on a group/resource combination if it is permitted and not conflicting.

Parameters:
  • group – group for which to create/update the permission.

  • resource – service or resource for which to create the permission.

  • permission – permission with modifiers to be applied.

  • db_session – database connection.

  • overwrite – If the corresponding (group, resource, permission[name]) exists, there is a conflict. Conflict is considered only by permission-name regardless of other modifiers. If overwrite is False, the conflict will be raised and not be applied. If overwrite is True, the permission modifiers will be replaced by the new ones, or created if missing.

Returns:

valid HTTP response on successful operations.

Raises:

HTTPException – error HTTP response of corresponding situation.

magpie.api.management.service.service_utils.format_service(service: magpie.models.Service, permissions: List[magpie.permissions.PermissionSet] | None = None, permission_type: magpie.permissions.PermissionType | None = None, show_private_url: bool = False, show_public_url: bool = True, show_resources_allowed: bool = False, show_configuration: bool = False, basic_info: bool = False, dotted: bool = False) magpie.typedefs.JSON[source]

Formats a Service information into JSON.

Note

Automatically finds permissions of the service if not specified. To preserve empty permissions such as during listing of user/group resource permissions, an empty list should be specified.

Parameters:
  • serviceService to be formatted.

  • permissions – Permissions to list along with the resource. By default, these are the applicable permissions for that corresponding resource type.

  • permission_type – Override indication of provenance to apply to permissions. Only applicable when they are provided.

  • show_private_url – Display the protected and private URL employed at service registration.

  • show_public_url – Display the generated public URL from configured Twitcher Settings.

  • show_resources_allowed – Display children resource details.

  • show_configuration – Display the applicable configuration of the Service if it supports it.

  • basic_info – If True, return only sufficient details to identify the service, without any additional details about permissions, children resources or configuration information is returned.

  • dotted – Employ a dot (.) instead of underscore (_) to separate Service from its basic information.

magpie.api.management.service.service_utils.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)

class magpie.api.management.service.service_utils.Permission[source]

Bases: magpie.utils.ExtendedEnum

Applicable Permission values (names) under certain Service and Resource.

READ = 'read'
WRITE = 'write'
ACCESS = 'access'
BROWSE = 'browse'
GET_CAPABILITIES = 'getcapabilities'
GET_MAP = 'getmap'
GET_FEATURE_INFO = 'getfeatureinfo'
GET_LEGEND_GRAPHIC = 'getlegendgraphic'
GET_METADATA = 'getmetadata'
GET_PROPERTY_VALUE = 'getpropertyvalue'
GET_FEATURE = 'getfeature'
GET_FEATURE_WITH_LOCK = 'getfeaturewithlock'
GET_GML_OBJECT = 'getgmlobject'
DESCRIBE_FEATURE_TYPE = 'describefeaturetype'
DESCRIBE_LAYER = 'describelayer'
DESCRIBE_PROCESS = 'describeprocess'
EXECUTE = 'execute'
LOCK_FEATURE = 'lockfeature'
TRANSACTION = 'transaction'
CREATE_STORED_QUERY = 'createstoredquery'
DROP_STORED_QUERY = 'dropstoredquery'
LIST_STORED_QUERIES = 'liststoredqueries'
DESCRIBE_STORED_QUERIES = 'describestoredqueries'
magpie.api.management.service.service_utils.SERVICES_PHOENIX_ALLOWED[source]
magpie.api.management.service.service_utils.sync_services_phoenix(services: Iterable[magpie.models.Service] | magpie.typedefs.JSON, services_as_dicts: bool = False) bool[source]

Syncs Magpie services by pushing updates to Phoenix.

Services must be one of types specified in magpie.register.SERVICES_PHOENIX_ALLOWED.

Parameters:
  • services

    An iterable of models.Service by default, or a dictionary of {svc-name: {<service-info>}} JSON objects containing each service’s information if services_ad_dicts is True.

    where <service-info> is defined as:

    {"public_url": <url>, "service_name": <name>, "service_type": <type>}
    

  • services_as_dicts – indicate if services must be parsed as JSON definitions.

magpie.api.management.service.service_utils.SERVICE_TYPE_DICT[source]
magpie.api.management.service.service_utils.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.api.management.service.service_utils.LOGGER[source]
magpie.api.management.service.service_utils.create_service(service_name: magpie.typedefs.Str, service_type: magpie.typedefs.Str, service_url: magpie.typedefs.Str, service_push: bool, service_config: magpie.typedefs.JSON | None, db_session: sqlalchemy.orm.session.Session) pyramid.httpexceptions.HTTPException[source]

Generates an instance to register a new service.

magpie.api.management.service.service_utils.get_services_by_type(service_type: magpie.typedefs.Str, db_session: sqlalchemy.orm.session.Session) Iterable[magpie.models.Service][source]

Obtains all services that correspond to requested service-type.

magpie.api.management.service.service_utils.add_service_getcapabilities_perms(service, db_session, group_name=None)[source]
magpie.api.management.service.service_utils.filter_service_types(service_query: magpie.typedefs.Str | None, default_services: bool = False) List[magpie.typedefs.Str] | None[source]

Obtains all valid case-insensitive service-type names from a filtered comma-separated list.

Parameters:
  • service_query – query string or service type(s) comma-separated to parse.

  • default_services – specify if the complete list of known service-types must be returned if no query to parse.

Returns:

parsed service-types if query was provided, or None by default, or all known service-types if requested.