magpie.api.management.resource.resource_views

Attributes

SERVICE_TYPE_DICT

Classes

PermissionType

Applicable types of Permission according to context.

Functions

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

Obtains all services that correspond to requested service-type.

format_permissions(→ Dict[magpie.typedefs.Str, ...)

Obtains the formatted permission representations after validation that each of their name is a known member of

magpie_register_permissions_from_config(→ None)

Applies permissions specified in configuration(s) defined as file, directory with files or literal configuration.

sync_services_phoenix(→ bool)

Syncs Magpie services by pushing updates to Phoenix.

get_resource_child_allowed(→ bool)

Verifies if the specified resource allows nesting children resources under it considering its specific type.

get_resources_view(→ magpie.typedefs.AnyResponseType)

List all registered resources.

get_resource_handler(→ magpie.typedefs.AnyResponseType)

Obtains the resource specified by the request with all applicable parameter validation and handling.

get_resource_view(→ magpie.typedefs.AnyResponseType)

Get resource information.

create_resource_view(→ magpie.typedefs.AnyResponseType)

Register a new resource.

delete_resource_view(→ magpie.typedefs.AnyResponseType)

Unregister a resource.

update_resource(→ magpie.typedefs.AnyResponseType)

Update a resource information.

get_resource_permissions_view(...)

List all applicable permissions for a resource.

get_resource_types_view(→ magpie.typedefs.AnyResponseType)

List all applicable children resource types under another resource within a service hierarchy.

update_permissions(→ magpie.typedefs.AnyResponseType)

Update the requested permissions and create missing related resources if necessary.

Module Contents

magpie.api.management.resource.resource_views.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.

class magpie.api.management.resource.resource_views.PermissionType[source]

Bases: magpie.utils.ExtendedEnum

Applicable types of Permission according to context.

ACCESS = 'access'
ALLOWED = 'allowed'
APPLIED = 'applied'
DIRECT = 'direct'
INHERITED = 'inherited'
EFFECTIVE = 'effective'
OWNED = 'owned'
magpie.api.management.resource.resource_views.format_permissions(permissions: Collection[magpie.typedefs.AnyPermissionType] | None, permission_type: PermissionType | None = None, force_unique: bool = True) Dict[magpie.typedefs.Str, List[magpie.typedefs.Str] | magpie.typedefs.PermissionDict | magpie.typedefs.Str][source]

Obtains the formatted permission representations after validation that each of their name is a known member of Permission enum, and optionally with modifiers as defined by PermissionSet.

The returned lists are sorted alphabetically by permission name, and then in order of resolution priority (from highest to lowest) for each subset or corresponding name.

The permissions are cleaned from any duplicate entries, unless force_unique is specified to allow it. If no or empty permissions is provided, empty lists are returned.

Note

Field permission_names provides both the older implicit permission names and the newer explicit name representation. For this reason, there will be semantically “duplicate” permissions in that list, but there will not be any literal string duplicates. Implicit names are immediately followed by their explicit name, unless implicit names do not apply for the given permission (e.g.: when Access.DENY did not exist). Only detailed and explicit JSON representations are provided in the permissions list.

When permission_type is equal to PermissionType.ALLOWED, the collection of every applicable PermissionSet is automatically generated by expanding all combinations of Access and Scope with every provided Permission name in permissions. This allows more concise definition of allowed permissions under magpie.services.Services and their children Resource by only defining Permission names without manually listing all variations of PermissionSet.

For other permission_type values, which represent Applied Permission only explicitly provided permissions are returned, to effectively return the collection of active permissions.

Parameters:
  • permissions – multiple permissions of any implementation and type, to be rendered both as names and JSON.

  • permission_type – indication of the represented permissions to be formatted, for informative indication.

  • force_unique – whether to remove duplicate entries by association of name, access and scope or not.

Returns:

JSON with the permissions listed as implicit+explicit names, as permission set objects, and their type.

magpie.api.management.resource.resource_views.magpie_register_permissions_from_config(permissions_config: magpie.typedefs.Str | magpie.typedefs.PermissionsConfig, settings: magpie.typedefs.AnySettingsContainer | None = None, db_session: sqlalchemy.orm.session.Session | None = None, raise_errors: bool = False) None[source]

Applies permissions specified in configuration(s) defined as file, directory with files or literal configuration.

Parameters:
  • permissions_config – file/dir path to permissions config or JSON/YAML equivalent pre-loaded.

  • settings – Magpie settings to resolve an instance session when using requests instead of DB session. Will look for magpie.url, magpie.admin_user and magpie.admin_password by default, or any corresponding environment variable resolution if omitted in the settings.

  • db_session – db session to use instead of requests to directly create/remove permissions with config.

  • raise_errors – raises errors related to permissions, instead of just logging the info.

See also

magpie/config/permissions.cfg for specific parameters and operational details.

magpie.api.management.resource.resource_views.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.resource.resource_views.SERVICE_TYPE_DICT[source]
magpie.api.management.resource.resource_views.get_resource_child_allowed(resource: magpie.typedefs.ServiceOrResourceType) bool[source]

Verifies if the specified resource allows nesting children resources under it considering its specific type.

Makes sure to obtain the specific Service or Resource implementation to verify children support. If this is not accomplished, the default attribute of base Service or Resource would erroneously indicate that children are allowed.

Parameters:

resource – Item for which to verify if children resources are allowed.

Returns:

Whether the resource can nest more resources or not.

magpie.api.management.resource.resource_views.get_resources_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

List all registered resources.

magpie.api.management.resource.resource_views.get_resource_handler(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Obtains the resource specified by the request with all applicable parameter validation and handling.

magpie.api.management.resource.resource_views.get_resource_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Get resource information.

magpie.api.management.resource.resource_views.create_resource_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Register a new resource.

magpie.api.management.resource.resource_views.delete_resource_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Unregister a resource.

magpie.api.management.resource.resource_views.update_resource(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Update a resource information.

magpie.api.management.resource.resource_views.get_resource_permissions_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

List all applicable permissions for a resource.

magpie.api.management.resource.resource_views.get_resource_types_view(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

List all applicable children resource types under another resource within a service hierarchy.

magpie.api.management.resource.resource_views.update_permissions(request: magpie.typedefs.AnyRequestType) magpie.typedefs.AnyResponseType[source]

Update the requested permissions and create missing related resources if necessary.