public async Task ListServiceSAS() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; string canonicalizedResourceParameter = "/blob/" + accountName + "/music"; ServiceSasParameters serviceSasParameters = new ServiceSasParameters(canonicalizedResource: canonicalizedResourceParameter) { Resource = "c", Permissions = "rdwlacup", Protocols = HttpProtocol.HttpsHttp, SharedAccessStartTime = Recording.UtcNow, SharedAccessExpiryTime = Recording.UtcNow.AddHours(1), KeyToSign = "key1" }; Response <ListServiceSasResponse> result = await account.GetServiceSASAsync(serviceSasParameters); ServiceSasParameters resultCredentials = ParseServiceSASToken(result.Value.ServiceSasToken, canonicalizedResourceParameter); Assert.AreEqual(serviceSasParameters.Resource, resultCredentials.Resource); Assert.AreEqual(serviceSasParameters.Permissions, resultCredentials.Permissions); Assert.AreEqual(serviceSasParameters.Protocols, resultCredentials.Protocols); Assert.NotNull(serviceSasParameters.SharedAccessStartTime); Assert.NotNull(serviceSasParameters.SharedAccessExpiryTime); }
public async Task GetAllStorageAccounts() { //create two storage accounts string accountName1 = await CreateValidAccountNameAsync(namePrefix); string accountName2 = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName1, GetDefaultStorageAccountParameters())).Value; StorageAccount account2 = (await storageAccountContainer.CreateOrUpdateAsync(accountName2, GetDefaultStorageAccountParameters())).Value; //validate two storage accounts int count = 0; StorageAccount account3 = null; StorageAccount account4 = null; await foreach (StorageAccount account in storageAccountContainer.GetAllAsync()) { count++; if (account.Id.Name == accountName1) { account3 = account; } if (account.Id.Name == accountName2) { account4 = account; } } Assert.AreEqual(count, 2); VerifyAccountProperties(account3, true); VerifyAccountProperties(account4, true); }
public async Task CreateDeleteStorageAccount() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value; Assert.AreEqual(accountName, account1.Id.Name); VerifyAccountProperties(account1, true); AssertStorageAccountEqual(account1, await account1.GetAsync()); //validate if created successfully StorageAccount account2 = await storageAccountContainer.GetAsync(accountName); VerifyAccountProperties(account2, true); AssertStorageAccountEqual(account1, account2); StorageAccount account3 = await storageAccountContainer.GetIfExistsAsync(accountName + "1"); Assert.IsNull(account3); Assert.IsTrue(await storageAccountContainer.CheckIfExistsAsync(accountName)); Assert.IsFalse(await storageAccountContainer.CheckIfExistsAsync(accountName + "1")); //delete storage account await account1.DeleteAsync(); //validate if deleted successfully Assert.IsFalse(await storageAccountContainer.CheckIfExistsAsync(accountName)); StorageAccount account4 = await storageAccountContainer.GetIfExistsAsync(accountName); Assert.IsNull(account4); }
public async Task ListStorageAccountSAS() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; AccountSasParameters accountSasParameters = new AccountSasParameters(services: "b", resourceTypes: "sco", permissions: "rl", sharedAccessExpiryTime: Recording.UtcNow.AddHours(1)) { Protocols = HttpProtocol.HttpsHttp, SharedAccessStartTime = Recording.UtcNow, KeyToSign = "key1" }; Response <ListAccountSasResponse> result = await account.GetAccountSASAsync(accountSasParameters); AccountSasParameters resultCredentials = ParseAccountSASToken(result.Value.AccountSasToken); Assert.AreEqual(accountSasParameters.Services, resultCredentials.Services); Assert.AreEqual(accountSasParameters.ResourceTypes, resultCredentials.ResourceTypes); Assert.AreEqual(accountSasParameters.Permissions, resultCredentials.Permissions); Assert.AreEqual(accountSasParameters.Protocols, resultCredentials.Protocols); Assert.NotNull(accountSasParameters.SharedAccessStartTime); Assert.NotNull(accountSasParameters.SharedAccessExpiryTime); }
public async Task CreateStorageAccountWithAccessTier() { //create storage account with accesstier hot string accountName1 = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.BlobStorage); parameters.AccessTier = AccessTier.Hot; StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName1, parameters)).Value; //validate VerifyAccountProperties(account, false); Assert.AreEqual(AccessTier.Hot, account.Data.AccessTier); Assert.AreEqual(Kind.BlobStorage, account.Data.Kind); //create storage account with accesstier cool string accountName2 = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); parameters.AccessTier = AccessTier.Cool; account = (await storageAccountContainer.CreateOrUpdateAsync(accountName2, parameters)).Value; //validate VerifyAccountProperties(account, false); Assert.AreEqual(AccessTier.Cool, account.Data.AccessTier); Assert.AreEqual(Kind.BlobStorage, account.Data.Kind); }
public async Task createStorageAccountAndGetFileShareContainer() { ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = armClient.DefaultSubscription; string rgName = "myRgName"; Location location = Location.WestUS2; ResourceGroupCreateOrUpdateOperation operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = operation.Value; this.resourceGroup = resourceGroup; Sku sku = new Sku(SkuName.StandardGRS); Kind kind = Kind.Storage; string locationStr = "westus2"; StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(sku, kind, locationStr); StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); string accountName = "myAccount"; StorageAccountCreateOperation accountCreateOperation = await accountContainer.CreateOrUpdateAsync(accountName, parameters); storageAccount = await accountCreateOperation.WaitForCompletionAsync(); #region Snippet:Managing_FileShares_GetFileService FileServiceContainer fileServiceContainer = storageAccount.GetFileServices(); FileService fileService = await fileServiceContainer.GetAsync("default"); #endregion this.fileService = fileService; }
public async Task StorageAccountRegenerateKey() { Sanitizer.AddJsonPathSanitizer("$.keys.[*].value"); //create storage account and get keys string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value; VerifyAccountProperties(account1, true); StorageAccountListKeysResult keys = await account1.GetKeysAsync(); Assert.NotNull(keys); StorageAccountKey key2 = keys.Keys.First( t => StringComparer.OrdinalIgnoreCase.Equals(t.KeyName, "key2")); Assert.NotNull(key2); //regenerate key and verify the key's change StorageAccountRegenerateKeyParameters keyParameters = new StorageAccountRegenerateKeyParameters("key2"); StorageAccountListKeysResult regenKeys = await account1.RegenerateKeyAsync(keyParameters); StorageAccountKey regenKey2 = regenKeys.Keys.First( t => StringComparer.OrdinalIgnoreCase.Equals(t.KeyName, "key2")); Assert.NotNull(regenKey2); //validate the key is different from origin one if (Mode != RecordedTestMode.Playback) { Assert.AreNotEqual(key2.Value, regenKey2.Value); } }
public async Task CreateLargeFileShareOnStorageAccount() { //create storage account and enable large share string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); Sku sku = new Sku(SkuName.StandardLRS); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: sku, kind: Kind.StorageV2); parameters.LargeFileSharesState = LargeFileSharesState.Enabled; StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; VerifyAccountProperties(account1, false); //create file share with share quota 5200, which is allowed in large file shares string fileShareName = Recording.GenerateAssetName("testfileshare"); FileService fileService = await account1.GetFileServices().GetAsync("default"); FileShareContainer shareContainer = fileService.GetFileShares(); FileShareData shareData = new FileShareData(); shareData.ShareQuota = 5200; FileShareCreateOperation fileShareCreateOperation = await shareContainer.CreateOrUpdateAsync(fileShareName, shareData); FileShare share = await fileShareCreateOperation.WaitForCompletionAsync(); Assert.AreEqual(share.Data.ShareQuota, shareData.ShareQuota); }
public async Task Get() { #region Snippet:Managing_StorageAccounts_GetStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); Console.WriteLine(storageAccount.Id.Name); #endregion }
public async Task Delete() { #region Snippet:Managing_StorageAccounts_DeleteStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); await storageAccount.DeleteAsync(); #endregion }
public async Task AddTag() { #region Snippet:Managing_StorageAccounts_AddTagStorageAccount StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetAsync("myAccount"); // add a tag on this storage account await storageAccount.AddTagAsync("key", "value"); #endregion }
public async Task list() { #region Snippet:Managing_StorageAccounts_ListStorageAccounts StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); AsyncPageable <StorageAccount> response = accountContainer.GetAllAsync(); await foreach (StorageAccount storageAccount in response) { Console.WriteLine(storageAccount.Id.Name); } #endregion }
public async Task ClearStorageAccount() { if (_resourceGroup != null) { StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); await foreach (StorageAccount account in storageAccountContainer.GetAllAsync()) { await account.DeleteAsync(); } _resourceGroup = null; _storageAccount = null; } }
public async Task StorageAccountRevokeUserDelegationKeys() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //revoke user delegation keys await account.RevokeUserDelegationKeysAsync(); }
public async Task CreateStorageAccountAndGetQueueContainer() { _resourceGroup = await CreateResourceGroupAsync(); string accountName = await CreateValidAccountNameAsync("teststoragemgmt"); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); _storageAccount = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value; _queueServiceContainer = _storageAccount.GetQueueServices(); _queueService = await _queueServiceContainer.GetAsync("default"); _storageQueueContainer = _queueService.GetStorageQueues(); }
public async Task ClearStorageAccounts() { //remove all storage accounts under current resource group if (_resourceGroup != null) { StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); List <StorageAccount> storageAccountList = await storageAccountContainer.GetAllAsync().ToEnumerableAsync(); foreach (StorageAccount account in storageAccountList) { await account.DeleteAsync(); } _resourceGroup = null; } }
public void CreateStorageAccount() { #endif string accountName = "myaccount"; string resourceGroupName = "myResourceGroup"; ArmClient client = new ArmClient(new DefaultAzureCredential()); ResourceGroup resourceGroup = client.DefaultSubscription.GetResourceGroups().Get(resourceGroupName); StorageAccountContainer storageAccountContainer = resourceGroup.GetStorageAccounts(); Sku sku = new Sku(SkuName.PremiumLRS); StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(new Sku(SkuName.StandardGRS), Kind.Storage, Location.WestUS); parameters.Tags.Add("key1", "value1"); parameters.Tags.Add("key2", "value2"); StorageAccount account = storageAccountContainer.CreateOrUpdate(accountName, parameters).Value; #endregion }
public async Task CreateStorageAccountWithEncrpytion() { //create storage account with encryption settings string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); parameters.Encryption = new Encryption(KeySource.MicrosoftStorage) { Services = new EncryptionServices { Blob = new EncryptionService { Enabled = true }, File = new EncryptionService { Enabled = true } } }; StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; VerifyAccountProperties(account, true); //verify encryption settings Assert.NotNull(account.Data.Encryption); Assert.NotNull(account.Data.Encryption.Services.Blob); Assert.True(account.Data.Encryption.Services.Blob.Enabled); Assert.NotNull(account.Data.Encryption.Services.Blob.LastEnabledTime); Assert.NotNull(account.Data.Encryption.Services.File); Assert.NotNull(account.Data.Encryption.Services.File.Enabled); Assert.NotNull(account.Data.Encryption.Services.File.LastEnabledTime); if (null != account.Data.Encryption.Services.Table) { if (account.Data.Encryption.Services.Table.Enabled.HasValue) { Assert.False(account.Data.Encryption.Services.Table.LastEnabledTime.HasValue); } } if (null != account.Data.Encryption.Services.Queue) { if (account.Data.Encryption.Services.Queue.Enabled.HasValue) { Assert.False(account.Data.Encryption.Services.Queue.LastEnabledTime.HasValue); } } }
public async Task CreateOrUpdate() { #region Snippet:Managing_StorageAccounts_CreateStorageAccount //first we need to define the StorageAccountCreateParameters Sku sku = new Sku(SkuName.StandardGRS); Kind kind = Kind.Storage; string location = "westus2"; StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(sku, kind, location); //now we can create a storage account with defined account name and parameters StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); string accountName = "myAccount"; StorageAccountCreateOperation accountCreateOperation = await accountContainer.CreateOrUpdateAsync(accountName, parameters); StorageAccount storageAccount = accountCreateOperation.Value; #endregion }
public async Task GetIfExist() { #region Snippet:Managing_StorageAccounts_GetStorageAccountIfExists StorageAccountContainer accountContainer = resourceGroup.GetStorageAccounts(); StorageAccount storageAccount = await accountContainer.GetIfExistsAsync("foo"); if (storageAccount != null) { Console.WriteLine(storageAccount.Id.Name); } if (await accountContainer.CheckIfExistsAsync("bar")) { Console.WriteLine("storage account 'bar' exists"); } #endregion }
public async Task ListStorageAccountAvailableLocations() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //get available locations IEnumerable <Location> locationList = await account.GetAvailableLocationsAsync(); Assert.NotNull(locationList); }
public async Task GetAllPrivateLinkResources() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //get all private link resources Response <IReadOnlyList <PrivateLinkResource> > privateLinkResources = await account.GetPrivateLinkResourcesAsync(); Assert.NotNull(privateLinkResources.Value); }
public async Task GetAllPrivateEndPointConnections() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; PrivateEndpointConnectionContainer privateEndpointConnectionContainer = account.GetPrivateEndpointConnections(); //get all private endpoint connections List <PrivateEndpointConnection> privateEndpointConnections = await privateEndpointConnectionContainer.GetAllAsync().ToEnumerableAsync(); Assert.NotNull(privateEndpointConnections); }
public async Task CreateStorageAccountWithEnableNfsV3() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); parameters.EnableNfsV3 = false; StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //validate VerifyAccountProperties(account, false); Assert.NotNull(account.Data.PrimaryEndpoints.Web); Assert.AreEqual(Kind.StorageV2, account.Data.Kind); Assert.False(account.Data.EnableNfsV3); }
public async Task CreateUpdateGetEncryptionScope() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; EncryptionScopeContainer encryptionScopeContainer = account.GetEncryptionScopes(); //create encryption scope EncryptionScopeData parameter = new EncryptionScopeData() { Source = EncryptionScopeSource.MicrosoftStorage, State = EncryptionScopeState.Enabled, RequireInfrastructureEncryption = false }; EncryptionScope encryptionScope = (await encryptionScopeContainer.CreateOrUpdateAsync("scope", parameter)).Value; Assert.AreEqual("scope", encryptionScope.Id.Name); Assert.AreEqual(EncryptionScopeState.Enabled, encryptionScope.Data.State); Assert.AreEqual(EncryptionScopeSource.MicrosoftStorage, encryptionScope.Data.Source); //patch encryption scope encryptionScope.Data.State = EncryptionScopeState.Disabled; encryptionScope = await encryptionScope.PatchAsync(encryptionScope.Data); Assert.AreEqual(encryptionScope.Data.State, EncryptionScopeState.Disabled); //get all encryption scopes List <EncryptionScope> encryptionScopes = await encryptionScopeContainer.GetAllAsync().ToEnumerableAsync(); encryptionScope = encryptionScopes.First(); Assert.AreEqual("scope", encryptionScope.Id.Name); Assert.AreEqual(EncryptionScopeState.Disabled, encryptionScope.Data.State); Assert.AreEqual(EncryptionScopeSource.MicrosoftStorage, encryptionScope.Data.Source); }
public async Task CreateStorageAccountWithFileStorage() { //create storage account with file storage string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); Sku sku = new Sku(SkuName.PremiumLRS); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: sku, kind: Kind.FileStorage); StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //validate VerifyAccountProperties(account1, false); Assert.AreEqual(Kind.FileStorage, account1.Data.Kind); Assert.AreEqual(SkuName.PremiumLRS, account1.Data.Sku.Name); //this storage account should only have endpoints on file Assert.IsNull(account1.Data.PrimaryEndpoints.Blob); Assert.IsNull(account1.Data.PrimaryEndpoints.Dfs); Assert.NotNull(account1.Data.PrimaryEndpoints.File); Assert.IsNull(account1.Data.PrimaryEndpoints.Table); Assert.IsNull(account1.Data.PrimaryEndpoints.Queue); }
public async Task GetStorageAccountLastSyncTime() { //create storage account string accountName1 = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); Sku sku = new Sku(SkuName.StandardRagrs); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: sku, kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName1, parameters)).Value; Assert.AreEqual(SkuName.StandardRagrs, account.Data.Sku.Name); Assert.Null(account.Data.GeoReplicationStats); //expand account = await account.GetAsync(StorageAccountExpand.GeoReplicationStats); Assert.NotNull(account.Data.GeoReplicationStats); Assert.NotNull(account.Data.GeoReplicationStats.Status); Assert.NotNull(account.Data.GeoReplicationStats.LastSyncTime); Assert.NotNull(account.Data.GeoReplicationStats.CanFailover); }
public async Task AddRemoveTag() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //add tag to this storage account account = await account.AddTagAsync("key", "value"); //verify the tag is added successfully Assert.AreEqual(account.Data.Tags.Count, 1); //remove tag account = await account.RemoveTagAsync("key"); //verify the tag is removed successfully Assert.AreEqual(account.Data.Tags.Count, 0); }
public async Task SetGetDeleteManagementPolicy() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; ManagementPolicyContainer managementPolicyContainer = account.GetManagementPolicies(); //Enable LAT BlobServiceContainer blobServiceContainer = account.GetBlobServices(); BlobService blobService = await blobServiceContainer.GetAsync("Default"); blobService.Data.LastAccessTimeTrackingPolicy = new LastAccessTimeTrackingPolicy(true); _ = await blobService.SetServicePropertiesAsync(blobService.Data); // create ManagementPolicy to set, the type of policy rule should always be Lifecycle List <ManagementPolicyRule> rules = new List <ManagementPolicyRule>(); ManagementPolicyAction action = new ManagementPolicyAction() { BaseBlob = new ManagementPolicyBaseBlob() { Delete = new DateAfterModification(1000, null) } }; ManagementPolicyDefinition definition1 = new ManagementPolicyDefinition(action) { Filters = new ManagementPolicyFilter(blobTypes: new List <string>() { "blockBlob", "appendBlob" }), }; ManagementPolicyRule rule1 = new ManagementPolicyRule("rule1", "Lifecycle", definition1); rules.Add(rule1); ManagementPolicyDefinition definition2 = new ManagementPolicyDefinition(action) { Filters = new ManagementPolicyFilter(blobTypes: new List <string>() { "appendBlob" }), }; ManagementPolicyRule rule2 = new ManagementPolicyRule("rule2", "Lifecycle", definition2); rules.Add(rule2); ManagementPolicyDefinition definition3 = new ManagementPolicyDefinition(action) { Filters = new ManagementPolicyFilter(blobTypes: new List <string>() { "blockBlob" }), }; ManagementPolicyRule rule3 = new ManagementPolicyRule("rule3", "Lifecycle", definition3); rules.Add(rule3); ManagementPolicyData parameter = new ManagementPolicyData() { Policy = new ManagementPolicySchema(rules) }; //set management policy, the policy name should always be default ManagementPolicy managementPolicy = (await managementPolicyContainer.CreateOrUpdateAsync("default", parameter)).Value; Assert.NotNull(managementPolicy); Assert.AreEqual(managementPolicy.Data.Policy.Rules.Count, 3); //delete namagement policy await managementPolicy.DeleteAsync(); }
public async Task EventCreateGetUpdateDelete() { var location = await GetLocation(); var resourceGroupName = Recording.GenerateAssetName(Helper.ResourceGroupPrefix); ResourceGroup resourceGroup = (await ArmClient.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(resourceGroupName, new ResourceGroupData(location))).Value; // Prepare Storage Account var accountName = Recording.GenerateAssetName("sdktestaccount"); var storageAccountCreateParameters = new StorageAccountCreateParameters( new ResourceManager.Storage.Models.Sku("Standard_LRS"), Kind.StorageV2, "eastus2" ) { AccessTier = AccessTier.Hot }; StorageAccountContainer storageAccountContainer = resourceGroup.GetStorageAccounts(); await storageAccountContainer.CreateOrUpdateAsync(accountName, storageAccountCreateParameters); // Create NameSpace var namespaceName = Recording.GenerateAssetName(Helper.NamespacePrefix); var createNamespaceResponse = await NamespacesOperations.StartCreateOrUpdateAsync(resourceGroupName, namespaceName, new EHNamespace() { Location = location } ); var np = (await WaitForCompletionAsync(createNamespaceResponse)).Value; Assert.NotNull(createNamespaceResponse); Assert.AreEqual(np.Name, namespaceName); DelayInTest(5); // Create Eventhub var eventhubName = Recording.GenerateAssetName(Helper.EventHubPrefix); var createEventhubResponse = await EventHubsOperations.CreateOrUpdateAsync(resourceGroupName, namespaceName, eventhubName, new Eventhub() { MessageRetentionInDays = 4, PartitionCount = 4, Status = EntityStatus.Active, CaptureDescription = new CaptureDescription() { Enabled = true, Encoding = EncodingCaptureDescription.Avro, IntervalInSeconds = 120, SizeLimitInBytes = 10485763, Destination = new Destination() { Name = "EventHubArchive.AzureBlockBlob", BlobContainer = "container", ArchiveNameFormat = "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}", StorageAccountResourceId = "/subscriptions/" + SubscriptionId + "/resourcegroups/" + resourceGroupName + "/providers/Microsoft.Storage/storageAccounts/" + accountName }, SkipEmptyArchives = true } }); Assert.NotNull(createEventhubResponse); Assert.AreEqual(createEventhubResponse.Value.Name, eventhubName); Assert.True(createEventhubResponse.Value.CaptureDescription.SkipEmptyArchives); //Get the created EventHub var getEventHubResponse = await EventHubsOperations.GetAsync(resourceGroupName, namespaceName, eventhubName); Assert.NotNull(getEventHubResponse.Value); Assert.AreEqual(EntityStatus.Active, getEventHubResponse.Value.Status); Assert.AreEqual(getEventHubResponse.Value.Name, eventhubName); //Get all Event Hubs for a given NameSpace var getListEventHubResponse = EventHubsOperations.ListByNamespaceAsync(resourceGroupName, namespaceName); var list = await getListEventHubResponse.ToEnumerableAsync(); Assert.NotNull(getListEventHubResponse); Assert.True(list.Count() >= 1); // Update the EventHub getEventHubResponse.Value.CaptureDescription.IntervalInSeconds = 130; getEventHubResponse.Value.CaptureDescription.SizeLimitInBytes = 10485900; getEventHubResponse.Value.MessageRetentionInDays = 5; //TODO time exception var UpdateEventHubResponse = (await EventHubsOperations.CreateOrUpdateAsync(resourceGroupName, namespaceName, eventhubName, getEventHubResponse.Value)).Value; Assert.NotNull(UpdateEventHubResponse); // Get the updated EventHub and verify the properties var getEventResponse = await EventHubsOperations.GetAsync(resourceGroupName, namespaceName, eventhubName); Assert.NotNull(getEventResponse); Assert.AreEqual(EntityStatus.Active, getEventResponse.Value.Status); Assert.AreEqual(5, getEventResponse.Value.MessageRetentionInDays); // Delete the Evnet Hub var deleteEventResponse = await EventHubsOperations.DeleteAsync(resourceGroupName, namespaceName, eventhubName); // Delete namespace and check for the NotFound exception var deleteNamespaceResponse = await WaitForCompletionAsync(await NamespacesOperations.StartDeleteAsync(resourceGroupName, namespaceName)); }