magpie.api.management.resource.resource_utils¶
Attributes¶
Classes¶
Applicable Permission values (names) under certain Service and Resource. |
Functions¶
|
Formats a Resource information into JSON. |
|
Syncs Magpie services by pushing updates to Phoenix. |
|
Retrieve the specific service class from the provided database service entry. |
Checks if a permission is valid to be applied to a specific service or a resource under a root service. |
|
|
Checks if a new Resource can be contained under a parent Resource given the requested type and the corresponding |
|
Verify that resource will be unique amongst other resources at the same target position. |
Recursively prunes all children resources from the tree hierarchy except listed ones matched by ID. |
|
|
Obtains the full path representation of the specified resource ID from the root service it resides under using all |
Obtain the service or resource class and a corresponding |
|
|
Obtains the parent resource nodes of the input service or resource. |
Obtains the children resource node structure of the input service or resource. |
|
Obtains the applicable permissions on the service or resource, accordingly to what was provided. |
|
Retrieves the service-specialized resource corresponding to the top-level resource in the tree hierarchy. |
|
Retrieves the service-specialized resource corresponding to the top-level resource in the tree hierarchy. |
|
Obtain the root service implementation. |
|
|
|
|
Module Contents¶
- magpie.api.management.resource.resource_utils.format_resource(resource: magpie.models.Resource, permissions: Collection[magpie.typedefs.AnyPermissionType] | None = None, permission_type: magpie.permissions.PermissionType | None = None, basic_info: bool = False, dotted: bool = False) magpie.typedefs.JSON[source]¶
Formats a Resource information into JSON.
- Parameters:
resource – Resource 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.basic_info – If
True, return only sufficient details to identify the resource, without any additionalpermissionsdetail, nor hierarchicalresourceinformation is returned.dotted – Employ a dot (
.) instead of underscore (_) to separate Resource from its basic information.
- class magpie.api.management.resource.resource_utils.Permission[source]¶
Bases:
magpie.utils.ExtendedEnumApplicable 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.resource.resource_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.Serviceby default, or a dictionary of{svc-name: {<service-info>}}JSON objects containing each service’s information ifservices_ad_dictsisTrue.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.resource.resource_utils.service_factory(service: magpie.models.Service, request: pyramid.request.Request) ServiceInterface[source]¶
Retrieve the specific service class from the provided database service entry.
- magpie.api.management.resource.resource_utils.check_valid_service_or_resource_permission(permission_name: magpie.typedefs.Str | magpie.permissions.Permission, service_or_resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session) magpie.permissions.Permission | None[source]¶
Checks if a permission is valid to be applied to a specific service or a resource under a root service.
- Parameters:
permission_name – permission name to be validated
service_or_resource – resource item corresponding to either a Service or a Resource
db_session – db connection
- Returns:
valid Permission if allowed by the service/resource
- Raises:
HTTPBadRequest – if the permission is not valid for the targeted service/resource
- magpie.api.management.resource.resource_utils.check_valid_service_resource(parent_resource: magpie.typedefs.ServiceOrResourceType, resource_type: magpie.typedefs.Str, db_session: sqlalchemy.orm.session.Session) magpie.models.Service[source]¶
Checks if a new Resource can be contained under a parent Resource given the requested type and the corresponding Service under which the parent Resource is already assigned.
- Parameters:
parent_resource – Resource under which the new resource of resource_type must be placed
resource_type – desired resource type
db_session
- Returns:
root Service if all checks were successful
- magpie.api.management.resource.resource_utils.check_unique_child_resource_name(resource_name: magpie.typedefs.Str, parent_id: int, error_message: magpie.typedefs.Str, db_session: sqlalchemy.orm.session.Session) None[source]¶
Verify that resource will be unique amongst other resources at the same target position.
Verifies that the provided
resource_namedoes not already exist amongst other children resources at the level immediately under the parent, for the specified parent resource.- Returns:
nothing if no conflict detected
- Raises:
HTTPConflict – if the
resource_nameconflict with another existing resource
- magpie.api.management.resource.resource_utils.crop_tree_with_permission(children: magpie.typedefs.NestedResourceNodes, resource_id_list: List[int]) Tuple[magpie.typedefs.NestedResourceNodes, List[int]][source]¶
Recursively prunes all children resources from the tree hierarchy except listed ones matched by ID.
Input
childrenis expected to be a dictionary of resource nodes and children resources with their ID as keys:{ <res-id>: { "node": <res>, "children": { <res-id>: { "node": <res>, "children": { <...> } }, <...> }, <...> }
- Parameters:
children – full hierarchy of children resource nodes.
resource_id_list – resource IDs of nodes to preserve.
- Returns:
pruned hierarchy of resource nodes.
- magpie.api.management.resource.resource_utils.get_resource_path(resource_id: int, db_session: sqlalchemy.orm.session.Session) magpie.typedefs.Str[source]¶
Obtains the full path representation of the specified resource ID from the root service it resides under using all respective names of the intermediate resources.
For example, the following hierarchy:
<service-1> (id: 1) <resource-1> (id: 2) <resource-2> (id: 3)
Will return the following path:
/service-1/resource-1/resource-2.This is the same representation of the
resourcefield within startup permissions configuration file.
- magpie.api.management.resource.resource_utils.get_service_or_resource_types(service_or_resource: magpie.typedefs.ServiceOrResourceType) Tuple[Type[magpie.services.ServiceInterface], magpie.typedefs.Str][source]¶
Obtain the service or resource class and a corresponding
"service"or"resource"type identifier.
- magpie.api.management.resource.resource_utils.get_resource_parents(resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session, tree_service_builder: ziggurat_foundations.models.services.resource_tree.ResourceTreeService | None = None) List[magpie.typedefs.ServiceOrResourceType][source]¶
Obtains the parent resource nodes of the input service or resource.
- Parameters:
resource – Initial resource where to start building the list from.
db_session – Database connection to retrieve resources.
tree_service_builder – Utility that build the tree (default:
models.RESOURCE_TREE_SERVICE).
- Returns:
List of resources starting at input resource going all the way down to the root service.
- magpie.api.management.resource.resource_utils.get_resource_children(resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session, tree_service_builder: ziggurat_foundations.models.services.resource_tree.ResourceTreeService | None = None, limit_depth: int | None = None) magpie.typedefs.NestedResourceNodes[source]¶
Obtains the children resource node structure of the input service or resource.
- Parameters:
resource – Initial resource where to start building the tree from.
db_session – Database connection to retrieve resources.
tree_service_builder – Utility that build the tree (default:
models.RESOURCE_TREE_SERVICE).limit_depth – Maximum depth to look for children resources (very deep if not specified, could be slow).
- Returns:
{node: Resource, children: {node_id: <recursive>}}
- magpie.api.management.resource.resource_utils.get_resource_permissions(resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session) List[magpie.permissions.Permission][source]¶
Obtains the applicable permissions on the service or resource, accordingly to what was provided.
When parsing a resource, rewinds the hierarchy up to the top-most service in order to find the context under which the resource resides, and therefore which permissions this resource is allowed to have under that service.
- magpie.api.management.resource.resource_utils.get_resource_root_service(resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session) magpie.models.Service | None[source]¶
Retrieves the service-specialized resource corresponding to the top-level resource in the tree hierarchy.
See also
get_resource_root_service_by_id()for same operation but using the resource IDget_resource_root_service_impl()to retrieve the explicit service’s implementation
- magpie.api.management.resource.resource_utils.get_resource_root_service_by_id(resource_id: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session) magpie.models.Service | None[source]¶
Retrieves the service-specialized resource corresponding to the top-level resource in the tree hierarchy.
See also
get_resource_root_service()for same operation but directly using the resource
- magpie.api.management.resource.resource_utils.get_resource_root_service_impl(resource: magpie.typedefs.ServiceOrResourceType, request: pyramid.request.Request) magpie.services.ServiceInterface[source]¶
Obtain the root service implementation.
Retrieves the root-resource from the provided resource within a tree hierarchy and generates the corresponding top-level service’s implementation from the
service_factory().See also
get_resource_root_service()to retrieve only the service flavored resource model