有人可以分享如何使用新的 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 包复制此功能(因为当前使用的包已被弃用)
使用 Azure.ResourceManager 包更新存储帐户中的 IP 规则
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");