magpie.api.management.resource.resource_utils
¶
Module Contents¶
Functions¶
|
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 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. |
|
|
|
-
magpie.api.management.resource.resource_utils.
check_valid_service_or_resource_permission
(permission_name: Union[Str, Permission], service_or_resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session) → Optional[Permission][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, resource_type, db_session)[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_name
does 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_name
conflict with another existing resource
-
magpie.api.management.resource.resource_utils.
crop_tree_with_permission
(children: magpie.typedefs.ChildrenResourceNodes, resource_id_list: List[int]) → Tuple[ChildrenResourceNodes, List[int]][source]¶ Recursively prunes all children resources from the tree hierarchy except listed ones matched by ID.
Input
children
is 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
resource
field within startup permissions configuration file.
-
magpie.api.management.resource.resource_utils.
get_service_or_resource_types
(service_or_resource: magpie.typedefs.ServiceOrResourceType) → Tuple[Type[ServiceInterface], Str][source]¶ Obtain the service or resource class and a corresponding
"service"
or"resource"
type identifier.
-
magpie.api.management.resource.resource_utils.
get_resource_children
(resource: magpie.typedefs.ServiceOrResourceType, db_session: sqlalchemy.orm.session.Session, tree_service_builder: Optional[ResourceTreeService] = None) → magpie.typedefs.ChildrenResourceNodes[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 – service that build the tree (default:
RESOURCE_TREE_SERVICE
)
- 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[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) → Optional[models.Service][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) → Optional[models.Service][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
-
magpie.api.management.resource.resource_utils.
create_resource
(resource_name: magpie.typedefs.Str, resource_display_name: Optional[Str], resource_type: magpie.typedefs.Str, parent_id: int, db_session: sqlalchemy.orm.session.Session) → pyramid.httpexceptions.HTTPException[source]¶