Azure Python SDK-验证到斑点存储

发布于 2025-01-26 01:26:37 字数 441 浏览 3 评论 0原文

我想使用Python SDK操纵(删除)用ADL(容器)中的文件和文件夹来操纵(删除)。我有2个问题:

  1. 用于此目的的数百个Azure SDK中的哪个?
  2. 如何使用AAD代币进行身份验证?我真的更喜欢以这种方式进行身份验证,或者也使用凭据来委托(用户名,密码,租户)

我已经看过:

  • azure.storage.filedatalake
  • azure.storage.storage.storage.storage.storage.blob

和使用

  • azure.Identities.Identientientientiention.tokencredentials,tokencrecredentials,azurecrecrecrecrecrecrecrecrecredentials

I would like to manipulate (delete) with files and folders in my ADLS (container) using Python SDK. I have 2 issues:

  1. Which of the hundreds of Azure SDKs to use for this purpose?
  2. How to authenticate using AAD token? I really prefer authenticating this way, or also using credentials for service principal (username, password, tenant)

I already looked at:

  • azure.storage.filedatalake
  • azure.storage.blob

and authentication using

  • azure.identity - TokenCredentials, AzureCliCredential

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵山崖 2025-02-02 01:26:37

用于此目的的数百个Azure SDK中的哪个?

考虑到ADLS Gen2是在Blob存储顶部构建的,您可以同时使用azure.storake.filedatalakeazure.storage.storage.storage.blob,但是建议是使用> azure.storage.filedatalake由于该SDK是为ADLS Gen2设计的。

如何使用AAD代币进行身份验证?我真的更喜欢身份验证
这样,或者还使用凭据来服务本金(用户名,
密码,租户)

请参考 <<<<<<<<<<代码>使用Azure Active Directory 授权访问BLOB,涉及如何使用Azure AD连接到Azure存储。这里要记住的关键是,任何用户(甚至服务原理)都使用Azure AD凭据连接到Azure Storage,都必须分配用户Azure Storage数据操作权限,例如BLOB数据贡献者。

完成此操作后,只需创建一个凭据对象,然后使用该凭据对象连接到Azure存储。

例如,查看下面的代码示例,该示例取自 此处

from azure.identity import ClientSecretCredential
   token_credential = ClientSecretCredential(
       self.active_directory_tenant_id,
       self.active_directory_application_id,
       self.active_directory_application_secret,
   )
   datalake_service_client = DataLakeServiceClient("https://{}.dfs.core.windows.net".format(self.account_name),
                                                   credential=token_credential)

Which of the hundreds of Azure SDKs to use for this purpose?

Considering ADLS Gen2 is built on top of Blob Storage, you can use both azure.storage.filedatalake or azure.storage.blob however the recommendation would be to use azure.storage.filedatalake as this SDK is designed for ADLS Gen2.

How to authenticate using AAD token? I really prefer authenticating
this way, or also using credentials for service principal (username,
password, tenant)

Please refer to Authorize access to blobs using Azure Active Directory regarding how to connect to Azure Storage using Azure AD. The key thing to remember here is that whatever user (even Service Principal) is connecting to Azure Storage using Azure AD credentials, that user must be assigned Azure Storage Data Operations permissions e.g. Blob Data Contributor.

Once you have done that, simply create a credential object and then use that credential object to connect to Azure Storage.

For example, take a look at the code sample below which is taken from here:

from azure.identity import ClientSecretCredential
   token_credential = ClientSecretCredential(
       self.active_directory_tenant_id,
       self.active_directory_application_id,
       self.active_directory_application_secret,
   )
   datalake_service_client = DataLakeServiceClient("https://{}.dfs.core.windows.net".format(self.account_name),
                                                   credential=token_credential)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文