【问题标题】:Azure DataLake Gen1 python SDK for removing recursive Acl on directories用于删除目录上的递归 Acl 的 Azure DataLake Gen1 python SDK
【发布时间】:2021-09-30 13:24:15
【问题描述】:

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

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

但我找不到任何适用于 gen1 的客户端 API。

可以用python吗?

以下代码来自Microsoft Official docs 这是为 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 azure


    【解决方案1】:

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

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

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

    我们有这方面的 Microsoft 文档来解释我们如何处理 Azure with DLS Gen1 上的文件系统操作。

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

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

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

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

    下面是remove_acl_entries()的详细函数:

    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)
    

    【讨论】:

    • 嗨@SaiKarri -MT你能帮我设置acl_spec属性吗?我的意思是组和组ID的一些虚拟示例
    • 您好,对于 acl_spec 属性:要从 ACL 中删除的 ACL 规范,格式为(注意缺少权限部分) '[default:]user|group|other:[entity id or UPN],[default:]user|group|other:[entity id or UPN],...'
    • 你也可以导入所有需要的模块,可以直接使用remove_acl_entries(path, acl_spec, recursive=False, number_of_sub_process=None)..看看(@987654323 @) 为每个参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 2020-08-09
    • 2018-10-15
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多