繁体   English   中英

Azure DataLake Gen1 python SDK 用于删除目录上的递归 Acl

[英]Azure DataLake Gen1 python SDK for removing recursive Acl on directories

我想在 AzureData lake Gen1 中递归删除 acl。

我可以看到 Gen2 的客户端 API。

但我找不到 gen1 的任何客户端 Apis。

可以使用 python 吗?

以下代码来自微软官方文档This is for DataLake Gen2

def remove_permission_recursively(is_default_scope):

    try:
        file_system_client = service_client.get_file_system_client(file_system="my-container")

        directory_client = file_system_client.get_directory_client("my-parent-directory")

        acl = 'user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

        if is_default_scope:
           acl = 'default:user:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

        directory_client.remove_access_control_recursive(acl=acl)

    except Exception as e:
     print(e)

我们有 Python SDK 在 Azure Data Lake Storage Gen1 上执行文件系统操作。

这里我们需要安装以下模块:

pip install azure-mgmt-resource
pip install azure-mgmt-datalake-store
pip install azure-datalake-store

我们有关于此的 Microsoft 文档来解释我们如何使用 DLS Gen1 处理 Azure 上的文件系统操作。

此外,我们还有以下方法可以帮助我们处理 ACL:

remove_acl(self, path)
remove_acl_entries(self, path, acl_spec, recursive=False, number_of_sub_process=None)
remove_default_acl(self, path)

为了以递归方式使用它们,我们有一个 Boolean 类型的参数,我们可以在其中指定我们是否可以递归地删除 ACL。

有关这些方法的更多详细信息,请参阅 GitHub azure-datalake-store-python文档

以下是 remove_acl_entries() 的 function 的详细信息:

def remove_acl_entries(self, path, acl_spec, recursive=False, number_of_sub_process=None):
        """
        Remove existing, named, Access Control List (ACL) entries on a file or folder.
        If the entry does not exist already it is ignored.
        Default entries cannot be removed this way, please use remove_default_acl for that.
        Unnamed entries cannot be removed in this way, please use remove_acl for that.

        Note: this is by default not recursive, and applies only to the file or folder specified.

        Parameters
        ----------
        path: str
            Location to remove the ACL entries.
        acl_spec: str
            The ACL specification to remove from the ACL at the path in the format (note that the permission portion is missing)
            '[default:]user|group|other:[entity id or UPN],[default:]user|group|other:[entity id or UPN],...'
        recursive: bool
            Specifies whether to remove ACLs recursively or not
        """
        if recursive:
            multi_processor_change_acl(adl=self, path=path, method_name="rem_acl", acl_spec=acl_spec,
                                       number_of_sub_process=number_of_sub_process)
        else:
            self._acl_call('REMOVEACLENTRIES', path, acl_spec, invalidate_cache=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM