如何使用新的 Azure.ResourceManager 包更新存储帐户中的 IP 规则?

问题描述 投票:0回答:1

有人可以分享如何使用新的 Azure.ResourceManager 包更新存储帐户中的 IP 规则的示例代码吗?

我必须将代码从旧的 Microsoft.Azure.Management.Storage.Fluent 包迁移到这个新包,但一直无法弄清楚。任何线索将不胜感激!

这就是使用旧包的当前代码的样子:

IAuthenticated azureActiveDirectroyClient = Microsoft.Azure.Management.Fluent.Azure.Configure().WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic).Authenticate(GetCredentials(<some_configuration>));
var subscriptionId = <subscription_id>;
var subscription = azureActiveDirectroyClient.WithSubscription(subscriptionId);
var storageAccount = await subscription.StorageAccounts.GetByResourceGroupAsync(<resource_grp_name>, <storage_account_name>).ConfigureAwait(false);

await storageAccount.Update().WithAccessFromAzureServices().WithAccessFromSelectedNetworks().WithAccessFromIpAddressRange(<some_ip_address_range>).ApplyAsync().ConfigureAwait(false);
await storageAccount.Update().WithAccessFromAzureServices().WithAccessFromSelectedNetworks().WithAccessFromIpAddress(<some_ip_address>).ApplyAsync().ConfigureAwait(false);
                        

我需要使用 Azure.ResourceManager 包复制此功能(因为当前使用的包已被弃用)

c# azure azure-sdk-.net azure-storage-account
1个回答
0
投票

使用 Azure.ResourceManager 包更新存储帐户中的 IP 规则

  • 使用此参考通过 C# 管理存储帐户的网络规则。

  • 安装版本 4.5 或从 SO更改 Visual Studio 2019 中的 C# 版本。

  Utilities.Log("Creating a Virtual network and subnet with storage service subnet access enabled:");

  INetwork network = azure.Networks.Define(networkName)
          .WithRegion(Region.USEast)
          .WithNewResourceGroup(rgName)
          .WithAddressSpace("10.0.0.0/28")
          .DefineSubnet(subnetName)
              .WithAddressPrefix("10.0.0.8/29")
              .WithAccessFromService(ServiceEndpointType.MicrosoftStorage)
              .Attach()
          .Create();

  Utilities.Log("Created a Virtual network with subnet:");
  Utilities.PrintVirtualNetwork(network);

  
  // Create a storage account with access to it allowed only from a specific subnet

  var subnetId = $"{network.Id}/subnets/{subnetName}";

  Utilities.Log($"Creating a storage account with access allowed only from the subnet{subnetId}");

  IStorageAccount storageAccount = azure.StorageAccounts.Define(storageAccountName)
          .WithRegion(Region.USEast)
          .WithExistingResourceGroup(rgName)
          .WithAccessFromSelectedNetworks()
          .WithAccessFromNetworkSubnet(subnetId)
          .Create();

  Utilities.Log("Created storage account:");
  Utilities.PrintStorageAccount(storageAccount);



  // Create a public IP address

  Utilities.Log("Creating a Public IP address");
  • 有关其他详细信息,请参阅管理网络规则的 Azure 存储帐户使用 C#
© www.soinside.com 2019 - 2024. All rights reserved.