magpie.api.management.resource.resource_views ============================================= .. py:module:: magpie.api.management.resource.resource_views Attributes ---------- .. autoapisummary:: magpie.api.management.resource.resource_views.SERVICE_TYPE_DICT Classes ------- .. autoapisummary:: magpie.api.management.resource.resource_views.PermissionType Functions --------- .. autoapisummary:: magpie.api.management.resource.resource_views.get_services_by_type magpie.api.management.resource.resource_views.format_permissions magpie.api.management.resource.resource_views.magpie_register_permissions_from_config magpie.api.management.resource.resource_views.sync_services_phoenix magpie.api.management.resource.resource_views.get_resource_child_allowed magpie.api.management.resource.resource_views.get_resources_view magpie.api.management.resource.resource_views.get_resource_handler magpie.api.management.resource.resource_views.get_resource_view magpie.api.management.resource.resource_views.create_resource_view magpie.api.management.resource.resource_views.delete_resource_view magpie.api.management.resource.resource_views.update_resource magpie.api.management.resource.resource_views.get_resource_permissions_view magpie.api.management.resource.resource_views.get_resource_types_view magpie.api.management.resource.resource_views.update_permissions Module Contents --------------- .. 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:class:: PermissionType Bases: :py:obj:`magpie.utils.ExtendedEnum` Applicable types of :term:`Permission` according to context. .. py:attribute:: ACCESS :value: 'access' .. py:attribute:: ALLOWED :value: 'allowed' .. py:attribute:: APPLIED :value: 'applied' .. py:attribute:: DIRECT :value: 'direct' .. py:attribute:: INHERITED :value: 'inherited' .. py:attribute:: EFFECTIVE :value: 'effective' .. py:attribute:: OWNED :value: 'owned' .. py:function:: format_permissions(permissions: Optional[Collection[magpie.typedefs.AnyPermissionType]], permission_type: Optional[PermissionType] = None, force_unique: bool = True) -> Dict[magpie.typedefs.Str, Union[List[magpie.typedefs.Str], magpie.typedefs.PermissionDict, magpie.typedefs.Str]] Obtains the formatted permission representations after validation that each of their name is a known member of :class:`Permission` enum, and optionally with modifiers as defined by :class:`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 :paramref:`force_unique` is specified to allow it. If no or empty :paramref:`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 :attr:`Access.DENY` did not exist). Only detailed and explicit JSON representations are provided in the ``permissions`` list. When :paramref:`permission_type` is equal to :attr:`PermissionType.ALLOWED`, the collection of every applicable :class:`PermissionSet` is automatically generated by expanding all combinations of :class:`Access` and :class:`Scope` with every provided :class:`Permission` name in :paramref:`permissions`. This allows more concise definition of allowed permissions under :class:`magpie.services.Services` and their children :term:`Resource` by only defining :class:`Permission` names without manually listing all variations of :class:`PermissionSet`. For other :paramref:`permission_type` values, which represent :term:`Applied Permission` only explicitly provided :paramref:`permissions` are returned, to effectively return the collection of *active* permissions. :param permissions: multiple permissions of any implementation and type, to be rendered both as names and JSON. :param permission_type: indication of the represented permissions to be formatted, for informative indication. :param 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. .. py:function:: magpie_register_permissions_from_config(permissions_config: Union[magpie.typedefs.Str, magpie.typedefs.PermissionsConfig], settings: Optional[magpie.typedefs.AnySettingsContainer] = None, db_session: Optional[sqlalchemy.orm.session.Session] = None, raise_errors: bool = False) -> None Applies `permissions` specified in configuration(s) defined as file, directory with files or literal configuration. :param permissions_config: file/dir path to `permissions` config or JSON/YAML equivalent pre-loaded. :param 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. :param db_session: db session to use instead of requests to directly create/remove permissions with config. :param raise_errors: raises errors related to permissions, instead of just logging the info. .. seealso:: `magpie/config/permissions.cfg` for specific parameters and operational details. .. 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_resource_child_allowed(resource: magpie.typedefs.ServiceOrResourceType) -> bool Verifies if the specified resource allows nesting children resources under it considering its specific type. Makes sure to obtain the specific :class:`Service` or :class:`Resource` implementation to verify children support. If this is not accomplished, the default attribute of base :class:`Service` or :class:`Resource` would erroneously indicate that children are allowed. :param resource: Item for which to verify if children resources are allowed. :return: Whether the resource can nest more resources or not. .. py:function:: get_resources_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType List all registered resources. .. py:function:: get_resource_handler(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Obtains the resource specified by the request with all applicable parameter validation and handling. .. py:function:: get_resource_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Get resource information. .. py:function:: create_resource_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Register a new resource. .. py:function:: delete_resource_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Unregister a resource. .. py:function:: update_resource(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Update a resource information. .. py:function:: get_resource_permissions_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType List all applicable permissions for a resource. .. py:function:: get_resource_types_view(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType List all applicable children resource types under another resource within a service hierarchy. .. py:function:: update_permissions(request: magpie.typedefs.AnyRequestType) -> magpie.typedefs.AnyResponseType Update the requested permissions and create missing related resources if necessary.