magpie.api.management.resource.resource_views¶
Attributes¶
Classes¶
Applicable types of Permission according to context. |
Functions¶
|
Obtains all services that correspond to requested service-type. |
|
Obtains the formatted permission representations after validation that each of their name is a known member of |
Applies permissions specified in configuration(s) defined as file, directory with files or literal configuration. |
|
|
Syncs Magpie services by pushing updates to Phoenix. |
|
Verifies if the specified resource allows nesting children resources under it considering its specific type. |
|
List all registered resources. |
|
Obtains the resource specified by the request with all applicable parameter validation and handling. |
|
Get resource information. |
|
Register a new resource. |
|
Unregister a resource. |
|
Update a resource information. |
List all applicable permissions for a resource. |
|
|
List all applicable children resource types under another resource within a service hierarchy. |
|
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.ExtendedEnumApplicable 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
Permissionenum, and optionally with modifiers as defined byPermissionSet.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_uniqueis specified to allow it. If no or emptypermissionsis provided, empty lists are returned.Note
Field
permission_namesprovides 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.: whenAccess.DENYdid not exist). Only detailed and explicit JSON representations are provided in thepermissionslist.When
permission_typeis equal toPermissionType.ALLOWED, the collection of every applicablePermissionSetis automatically generated by expanding all combinations ofAccessandScopewith every providedPermissionname inpermissions. This allows more concise definition of allowed permissions undermagpie.services.Servicesand their children Resource by only definingPermissionnames without manually listing all variations ofPermissionSet.For other
permission_typevalues, which represent Applied Permission only explicitly providedpermissionsare 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_userandmagpie.admin_passwordby 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.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_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
ServiceorResourceimplementation to verify children support. If this is not accomplished, the default attribute of baseServiceorResourcewould 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.