Source code for magpie.permissions

from magpie.utils import ExtendedEnumMeta
from six import with_metaclass
from enum import Enum
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from magpie.definitions.typedefs import Iterable, List, Optional, Str, AnyPermissionType  # noqa: F401


[docs]class Permission(with_metaclass(ExtendedEnumMeta, Enum)): # file/dir permissions
[docs] READ = u"read"
[docs] READ_MATCH = u"read-match"
[docs] WRITE = u"write"
[docs] WRITE_MATCH = u"write-match"
[docs] ACCESS = u"access"
# WPS permissions
[docs] GET_CAPABILITIES = u"getcapabilities"
[docs] GET_MAP = u"getmap"
[docs] GET_FEATURE_INFO = u"getfeatureinfo"
[docs] GET_LEGEND_GRAPHIC = u"getlegendgraphic"
[docs] GET_METADATA = u"getmetadata"
[docs] GET_FEATURE = u"getfeature"
[docs] DESCRIBE_FEATURE_TYPE = u"describefeaturetype"
[docs] DESCRIBE_PROCESS = u"describeprocess"
[docs] EXECUTE = u"execute"
[docs] LOCK_FEATURE = u"lockfeature"
[docs] TRANSACTION = u"transaction"
[docs]def convert_permission(permission): # type: (AnyPermissionType) -> Optional[Permission] """ Converts any permission representation to the ``Permission`` enum. If the permission cannot be matched to one of the enum's value, ``None`` is returned instead. """ if permission in Permission: return permission return Permission.get(getattr(permission, "perm_name", None) or permission)
[docs]def format_permissions(permissions): # type: (Iterable[AnyPermissionType]) -> List[Str] """ Obtains the formatted permission representation after validation that it is a member of ``Permission`` enum. The returned list is sorted alphabetically and cleaned of any duplicate entries. """ perms = [] for p in permissions: p_enum = convert_permission(p) if p_enum: perms.append(p_enum) return list(sorted(set([p.value for p in perms]))) # remove any duplicates entries