magpie.api.management.service.service_utils =========================================== .. py:module:: magpie.api.management.service.service_utils Attributes ---------- .. autoapisummary:: magpie.api.management.service.service_utils.SERVICES_PHOENIX_ALLOWED magpie.api.management.service.service_utils.SERVICE_TYPE_DICT magpie.api.management.service.service_utils.LOGGER Classes ------- .. autoapisummary:: magpie.api.management.service.service_utils.Permission Functions --------- .. autoapisummary:: magpie.api.management.service.service_utils.create_group_resource_permission_response magpie.api.management.service.service_utils.format_service magpie.api.management.service.service_utils.get_constant magpie.api.management.service.service_utils.sync_services_phoenix magpie.api.management.service.service_utils.get_logger magpie.api.management.service.service_utils.create_service magpie.api.management.service.service_utils.get_services_by_type magpie.api.management.service.service_utils.add_service_getcapabilities_perms magpie.api.management.service.service_utils.filter_service_types Module Contents --------------- .. py:function:: 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 Creates a permission on a group/resource combination if it is permitted and not conflicting. :param group: group for which to create/update the permission. :param resource: service or resource for which to create the permission. :param permission: permission with modifiers to be applied. :param db_session: database connection. :param 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. .. py:function:: format_service(service: magpie.models.Service, permissions: Optional[List[magpie.permissions.PermissionSet]] = None, permission_type: Optional[magpie.permissions.PermissionType] = 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 Formats a :term:`Service` information into JSON. .. note:: Automatically finds :paramref:`permissions` of the :paramref:`service` if not specified. To preserve `empty` permissions such as during listing of `user`/`group` resource permissions, an empty ``list`` should be specified. :param service: :term:`Service` to be formatted. :param permissions: Permissions to list along with the :paramref:`resource`. By default, these are the applicable permissions for that corresponding resource type. :param permission_type: Override indication of provenance to apply to :paramref:`permissions`. Only applicable when they are provided. :param show_private_url: Display the protected and private URL employed at service registration. :param show_public_url: Display the generated public URL from configured :ref:`config_twitcher`. :param show_resources_allowed: Display children resource details. :param show_configuration: Display the applicable configuration of the :term:`Service` if it supports it. :param basic_info: If ``True``, return only sufficient details to identify the service, without any additional details about :paramref:`permissions`, children resources or configuration information is returned. :param dotted: Employ a dot (``.``) instead of underscore (``_``) to separate :term:`Service` from its basic information. .. seealso:: :func:`magpie.api.management.resource.resource_formats.format_resource` .. py:function:: get_constant(constant_name: magpie.typedefs.Str, settings_container: Optional[magpie.typedefs.AnySettingsContainer] = None, settings_name: Optional[magpie.typedefs.Str] = None, default_value: Optional[magpie.typedefs.SettingValue] = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) -> magpie.typedefs.SettingValue Search in order for matched value of :paramref:`constant_name`: 1. search in :py:data:`MAGPIE_CONSTANTS` 2. search in settings if specified 3. search alternative setting names (see below) 4. search in :mod:`magpie.constants` definitions 5. search in environment variables Parameter :paramref:`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 :paramref:`settings_name` is provided as alternative name, it is used as is to search for results if :paramref:`constant_name` was not found. Otherwise, ``magpie.[variable_name]`` is used for additional search when the format ``MAGPIE_[VARIABLE_NAME]`` was used for :paramref:`constant_name` (i.e.: ``MAGPIE_ADMIN_USER`` will also search for ``magpie.admin_user`` and so on for corresponding constants). :param constant_name: key to search for a value :param settings_container: WSGI application settings container (if not provided, uses found one in current thread) :param settings_name: alternative name for `settings` if specified :param default_value: default value to be returned if not found anywhere, and exception raises are disabled. :param raise_not_set: raise an exception if the found key is ``None``, search until last case if others are ``None`` :param raise_missing: raise exception if key is not found anywhere :param print_missing: print message if key is not found anywhere, return ``None`` :param 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) :raises LookupError: if no appropriate value could be found from all search locations (according to options) .. py:class:: Permission Bases: :py:obj:`magpie.utils.ExtendedEnum` Applicable :term:`Permission` values (names) under certain :term:`Service` and :term:`Resource`. .. py:attribute:: READ :value: 'read' .. py:attribute:: WRITE :value: 'write' .. py:attribute:: ACCESS :value: 'access' .. py:attribute:: BROWSE :value: 'browse' .. py:attribute:: GET_CAPABILITIES :value: 'getcapabilities' .. py:attribute:: GET_MAP :value: 'getmap' .. py:attribute:: GET_FEATURE_INFO :value: 'getfeatureinfo' .. py:attribute:: GET_LEGEND_GRAPHIC :value: 'getlegendgraphic' .. py:attribute:: GET_METADATA :value: 'getmetadata' .. py:attribute:: GET_PROPERTY_VALUE :value: 'getpropertyvalue' .. py:attribute:: GET_FEATURE :value: 'getfeature' .. py:attribute:: GET_FEATURE_WITH_LOCK :value: 'getfeaturewithlock' .. py:attribute:: GET_GML_OBJECT :value: 'getgmlobject' .. py:attribute:: DESCRIBE_FEATURE_TYPE :value: 'describefeaturetype' .. py:attribute:: DESCRIBE_LAYER :value: 'describelayer' .. py:attribute:: DESCRIBE_PROCESS :value: 'describeprocess' .. py:attribute:: EXECUTE :value: 'execute' .. py:attribute:: LOCK_FEATURE :value: 'lockfeature' .. py:attribute:: TRANSACTION :value: 'transaction' .. py:attribute:: CREATE_STORED_QUERY :value: 'createstoredquery' .. py:attribute:: DROP_STORED_QUERY :value: 'dropstoredquery' .. py:attribute:: LIST_STORED_QUERIES :value: 'liststoredqueries' .. py:attribute:: DESCRIBE_STORED_QUERIES :value: 'describestoredqueries' .. py:data:: SERVICES_PHOENIX_ALLOWED .. py:function:: sync_services_phoenix(services: Union[Iterable[magpie.models.Service], magpie.typedefs.JSON], services_as_dicts: bool = False) -> bool Syncs Magpie services by pushing updates to Phoenix. Services must be one of types specified in :py:data:`magpie.register.SERVICES_PHOENIX_ALLOWED`. :param services: An iterable of :class:`models.Service` by default, or a dictionary of ``{svc-name: {}}`` JSON objects containing each service's information if :paramref:`services_ad_dicts` is ``True``. where ```` is defined as:: {"public_url": , "service_name": , "service_type": } :param services_as_dicts: indicate if services must be parsed as JSON definitions. .. py:data:: SERVICE_TYPE_DICT .. 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:data:: LOGGER .. py:function:: create_service(service_name: magpie.typedefs.Str, service_type: magpie.typedefs.Str, service_url: magpie.typedefs.Str, service_push: bool, service_config: Optional[magpie.typedefs.JSON], db_session: sqlalchemy.orm.session.Session) -> pyramid.httpexceptions.HTTPException Generates an instance to register a new service. .. py:function:: get_services_by_type(service_type: magpie.typedefs.Str, db_session: sqlalchemy.orm.session.Session) -> Iterable[magpie.models.Service] Obtains all services that correspond to requested service-type. .. py:function:: add_service_getcapabilities_perms(service, db_session, group_name=None) .. py:function:: filter_service_types(service_query: Optional[magpie.typedefs.Str], default_services: bool = False) -> Optional[List[magpie.typedefs.Str]] Obtains all valid case-insensitive service-type names from a filtered comma-separated list. :param service_query: query string or service type(s) comma-separated to parse. :param 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.