1 回答
TA贡献1853条经验 获得超9个赞
详细步骤请参考这篇文章。
注意:
1.对于account name
,不要使用后缀.azuredatalakestore.net
2.对于身份验证,我使用服务到服务身份验证。它将使用 TENANT_id(AAD 中的目录 id)、CLIENTID(AAD 中的应用程序 id)和 secret_key,您可以按照本文获取它们。
3.安装官方文档中提到的以下版本包(你可以使用其他版本,但需要做一些小改动):
Microsoft.Azure.Management.DataLake.Store - This tutorial uses v2.1.3-preview.
Microsoft.Rest.ClientRuntime.Azure.Authentication - This tutorial uses v2.2.12.
示例代码:
class Program
{
private static DataLakeStoreAccountManagementClient _adlsClient;
private static string _adlsAccountName;
private static string _resourceGroupName;
private static string _location;
private static string _subId;
static void Main(string[] args)
{
_adlsAccountName = "test333";
_resourceGroupName = "ivanrg";
_location = "East US 2";
_subId = "xxxx";
string TENANT = "xxxx";
string CLIENTID = "xxxx";
System.Uri ARM_TOKEN_AUDIENCE = new System.Uri(@"https://management.core.windows.net/");
System.Uri ADL_TOKEN_AUDIENCE = new System.Uri(@"https://datalake.azure.net/");
string secret_key = "xxxx";
var armCreds = GetCreds_SPI_SecretKey(TENANT, ARM_TOKEN_AUDIENCE, CLIENTID, secret_key);
// Create client objects and set the subscription ID
_adlsClient = new DataLakeStoreAccountManagementClient(armCreds) { SubscriptionId = _subId };
// Create Data Lake Storage Gen1 account
var adlsParameters = new DataLakeStoreAccount(location: _location);
_adlsClient.Account.Create(_resourceGroupName, _adlsAccountName, adlsParameters);
Console.WriteLine("--completed--");
Console.ReadLine();
}
private static ServiceClientCredentials GetCreds_SPI_SecretKey(string tenant, Uri tokenAudience, string clientId, string secretKey)
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
var serviceSettings = ActiveDirectoryServiceSettings.Azure;
serviceSettings.TokenAudience = tokenAudience;
var creds = ApplicationTokenProvider.LoginSilentAsync(
tenant,
clientId,
secretKey,
serviceSettings).GetAwaiter().GetResult();
return creds;
}
}
在 azure 门户中检查新创建的帐户:
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报