Example #1
0
        public async Task UpdateAccountIdentityFromNoneToSystem()
        {
            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts();

            string accountName = await CreateValidAccountNameAsync(namePrefix);

            var            param    = GetDefaultStorageAccountParameters(sku: new StorageSku(StorageSkuName.StandardLRS));
            StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, param)).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, false);
            Assert.Null(account1.Data.Identity);

            PatchableStorageAccountData parameters = new PatchableStorageAccountData()
            {
                Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned)
            };

            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(ManagedServiceIdentityType.SystemAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.IsEmpty(account1.Data.Identity.UserAssignedIdentities);
            Assert.NotNull(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.TenantId);

            // validate
            StorageAccount account2 = await storageAccountCollection.GetAsync(accountName);

            Assert.AreEqual(ManagedServiceIdentityType.SystemAssigned, account2.Data.Identity.ManagedServiceIdentityType);
            Assert.IsEmpty(account2.Data.Identity.UserAssignedIdentities);
            Assert.NotNull(account2.Data.Identity.PrincipalId);
            Assert.NotNull(account2.Data.Identity.TenantId);
        }
        public async Task BlobContainerSoftDelete()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            BlobServiceData properties = _blobService.Data;

            //enable container softdelete
            properties.ContainerDeleteRetentionPolicy         = new DeleteRetentionPolicy();
            properties.ContainerDeleteRetentionPolicy.Enabled = true;
            properties.ContainerDeleteRetentionPolicy.Days    = 30;
            _blobService = (await _blobService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value;

            //create two blob containers and delete 1
            string containerName1            = Recording.GenerateAssetName("testblob1");
            string containerName2            = Recording.GenerateAssetName("testblob2");
            BlobContainerResource container1 = (await _blobContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, containerName1, new BlobContainerData())).Value;
            BlobContainerResource container2 = (await _blobContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, containerName2, new BlobContainerData())).Value;
            await container2.DeleteAsync(WaitUntil.Completed);

            //list delete included
            List <BlobContainerResource> blobContainers = await _blobContainerCollection.GetAllAsync(include : ListContainersInclude.Deleted).ToEnumerableAsync();

            Assert.AreEqual(2, blobContainers.Count);
            foreach (BlobContainerResource con in blobContainers)
            {
                if (con.Data.Name == containerName1)
                {
                    Assert.IsFalse(con.Data.Deleted);
                }
                else
                {
                    Assert.IsTrue(con.Data.Deleted);
                    Assert.NotNull(con.Data.RemainingRetentionDays);
                }
            }
            //list without delete included
            blobContainers = await _blobContainerCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(1, blobContainers.Count);

            //disable container softdelete
            properties = _blobService.Data;
            properties.ContainerDeleteRetentionPolicy = new DeleteRetentionPolicy();
            properties.DeleteRetentionPolicy.Enabled  = false;
            _blobService = (await _blobService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value;
            properties   = _blobService.Data;
            Assert.IsFalse(properties.ContainerDeleteRetentionPolicy.Enabled);
        }
        public async Task ExtendImmutabilityPolicy()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };

            _storageAccount = await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            // create a blob container
            string                containerName = Recording.GenerateAssetName("testblob");
            BlobContainerData     data          = new BlobContainerData();
            BlobContainerResource container     = (await _blobContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, containerName, new BlobContainerData())).Value;

            //create immutability policy
            ImmutabilityPolicyData immutabilityPolicyModel = new ImmutabilityPolicyData()
            {
                ImmutabilityPeriodSinceCreationInDays = 3
            };
            ImmutabilityPolicyResource immutabilityPolicy = (await container.GetImmutabilityPolicy().CreateOrUpdateAsync(WaitUntil.Completed, data: immutabilityPolicyModel)).Value;

            //validate
            Assert.NotNull(immutabilityPolicy.Data.Id);
            Assert.NotNull(immutabilityPolicy.Data.ResourceType);
            Assert.NotNull(immutabilityPolicy.Data.Name);
            Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays);
            Assert.AreEqual(ImmutabilityPolicyState.Unlocked, immutabilityPolicy.Data.State);

            //lock immutability policy
            immutabilityPolicy = await container.GetImmutabilityPolicy().LockImmutabilityPolicyAsync(ifMatch: immutabilityPolicy.Data.Etag);

            Assert.NotNull(immutabilityPolicy.Data.Id);
            Assert.NotNull(immutabilityPolicy.Data.ResourceType);
            Assert.NotNull(immutabilityPolicy.Data.Name);
            Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays);
            Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State);

            //extend immutability policy
            immutabilityPolicyModel = new ImmutabilityPolicyData()
            {
                ImmutabilityPeriodSinceCreationInDays = 100
            };
            immutabilityPolicy = await container.GetImmutabilityPolicy().ExtendImmutabilityPolicyAsync(ifMatch: immutabilityPolicy.Data.Etag, data: immutabilityPolicyModel);

            Assert.NotNull(immutabilityPolicy.Data.Id);
            Assert.NotNull(immutabilityPolicy.Data.ResourceType);
            Assert.NotNull(immutabilityPolicy.Data.Name);
            Assert.AreEqual(100, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays);
            Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State);
            await container.DeleteAsync(WaitUntil.Completed);
        }
Example #4
0
        public async Task CreateDeleteListFileShareSnapshot()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            // Enable share soft delete in service properties
            _fileService = await _fileService.GetAsync();

            FileServiceData properties = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value;

            //create 2 file share and delete 1
            string    fileShareName1 = Recording.GenerateAssetName("testfileshare1");
            string    fileShareName2 = Recording.GenerateAssetName("testfileshare2");
            FileShare share1         = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData())).Value;
            FileShare share2         = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName2, new FileShareData())).Value;
            await share2.DeleteAsync(WaitUntil.Completed);

            //create 2 share snapshots
            FileShare shareSnapshot1 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData(), expand: "snapshots")).Value;
            FileShare shareSnapshot2 = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName1, new FileShareData(), expand: "snapshots")).Value;

            //get single share snapshot
            FileShare shareSnapshot = await _fileShareCollection.GetAsync(fileShareName1, "stats", shareSnapshot1.Data.SnapshotTime.Value.UtcDateTime.ToString("o"));

            Assert.AreEqual(shareSnapshot.Data.SnapshotTime, shareSnapshot1.Data.SnapshotTime);

            //list share with snapshot
            List <FileShare> fileShares = await _fileShareCollection.GetAllAsync(expand : "snapshots").ToEnumerableAsync();

            Assert.AreEqual(3, fileShares.Count);

            //delete share snapshot
            await shareSnapshot.DeleteAsync(WaitUntil.Completed);

            // List share with deleted
            fileShares = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync();

            Assert.AreEqual(2, fileShares.Count);
        }
Example #5
0
        public async Task UpdateAccountIdentityFromTwoUsersToOneUser()
        {
            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts();

            string accountName = await CreateValidAccountNameAsync(namePrefix);

            var identity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned);
            var userAssignedIdentity1 = await CreateUserAssignedIdentityAsync();

            identity.UserAssignedIdentities.Add(userAssignedIdentity1.Id, new UserAssignedIdentity());
            var userAssignedIdentity2 = await CreateUserAssignedIdentityAsync();

            identity.UserAssignedIdentities.Add(userAssignedIdentity2.Id, new UserAssignedIdentity());
            var            param    = GetDefaultStorageAccountParameters(sku: new StorageSku(StorageSkuName.StandardLRS), identity: identity);
            StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, param)).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, false);
            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 2);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id].PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id].PrincipalId);

            account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id] = null;
            PatchableStorageAccountData parameters = new PatchableStorageAccountData()
            {
                Identity = account1.Data.Identity
            };

            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.Null(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id]);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id].PrincipalId);

            // validate
            StorageAccount account2 = await storageAccountCollection.GetAsync(accountName);

            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.IsFalse(account1.Data.Identity.UserAssignedIdentities.ContainsKey(userAssignedIdentity1.Id));
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id].PrincipalId);
        }
Example #6
0
        public async Task UpdateAccountIdentityFromUserToTwoUsers()
        {
            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts();

            string accountName = await CreateValidAccountNameAsync(namePrefix);

            var identity             = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned);
            var userAssignedIdentity = await CreateUserAssignedIdentityAsync();

            identity.UserAssignedIdentities.Add(userAssignedIdentity.Id, new UserAssignedIdentity());
            var            param    = GetDefaultStorageAccountParameters(sku: new StorageSku(StorageSkuName.StandardLRS), identity: identity);
            StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, param)).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, false);
            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id].PrincipalId);

            // With JSON Merge Patch, we only need to put the identity to add in the dictionary for update operation.
            var identity2             = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned);
            var userAssignedIdentity2 = await CreateUserAssignedIdentityAsync();

            identity2.UserAssignedIdentities.Add(userAssignedIdentity2.Id, new UserAssignedIdentity());
            PatchableStorageAccountData parameters = new PatchableStorageAccountData()
            {
                Identity = identity2
            };

            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 2);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id].PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id].PrincipalId);

            // validate
            StorageAccount account2 = await storageAccountCollection.GetAsync(accountName);

            Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account2.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account2.Data.Identity.UserAssignedIdentities.Count, 2);
            Assert.Null(account2.Data.Identity.PrincipalId);
            Assert.NotNull(account2.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id].PrincipalId);
            Assert.NotNull(account2.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id].PrincipalId);
        }
        public async Task BlobContainersVLW()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };

            _storageAccount = await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            //enable blob versioning
            BlobServiceData properties = _blobService.Data;

            properties.IsVersioningEnabled = true;
            _blobService = (await _blobService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value;
            Assert.IsTrue(properties.IsVersioningEnabled);

            //create container with VLW
            string            containerName1 = Recording.GenerateAssetName("testblob1");
            BlobContainerData parameters1    = new BlobContainerData()
            {
                ImmutableStorageWithVersioning = new ImmutableStorageWithVersioning()
                {
                    Enabled = true
                }
            };
            BlobContainerResource container1 = (await _blobContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, containerName1, parameters1)).Value;

            Assert.IsTrue(container1.Data.ImmutableStorageWithVersioning.Enabled);
            Assert.IsNull(container1.Data.ImmutableStorageWithVersioning.MigrationState);

            //update container to enabled  Immutability Policy
            string                containerName2 = Recording.GenerateAssetName("testblob2");
            BlobContainerData     parameters2    = new BlobContainerData();
            BlobContainerResource container2     = (await _blobContainerCollection.CreateOrUpdateAsync(WaitUntil.Completed, containerName2, parameters2)).Value;
            await container2.GetImmutabilityPolicy().CreateOrUpdateAsync(WaitUntil.Completed, data: new ImmutabilityPolicyData()
            {
                ImmutabilityPeriodSinceCreationInDays = 1
            });

            await container2.ObjectLevelWormAsync(WaitUntil.Completed);

            container2 = await container2.GetAsync();

            Assert.IsTrue(container2.Data.ImmutableStorageWithVersioning.Enabled);
            Assert.AreEqual("Completed", container2.Data.ImmutableStorageWithVersioning.MigrationState);
        }
        public async Task PITR()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };

            _storageAccount = await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            BlobServiceData properties = _blobService.Data;

            properties.DeleteRetentionPolicy         = new DeleteRetentionPolicy();
            properties.DeleteRetentionPolicy.Enabled = true;
            properties.DeleteRetentionPolicy.Days    = 30;
            properties.ChangeFeed          = new ChangeFeed();
            properties.ChangeFeed.Enabled  = true;
            properties.IsVersioningEnabled = true;
            properties.RestorePolicy       = new RestorePolicyProperties(true)
            {
                Days = 5
            };

            _blobService = (await _blobService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value;

            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(10000);
            }

            //create restore ranges
            List <Models.BlobRestoreRange> ranges = new List <Models.BlobRestoreRange>();

            ranges.Add(new Models.BlobRestoreRange("", "container1/blob1"));
            ranges.Add(new Models.BlobRestoreRange("container1/blob2", "container2/blob3"));
            ranges.Add(new Models.BlobRestoreRange("container3/blob3", ""));

            //start restore
            Models.BlobRestoreParameters     parameters       = new Models.BlobRestoreParameters(Recording.Now.AddSeconds(-1).ToUniversalTime(), ranges);
            ArmOperation <BlobRestoreStatus> restoreOperation = _storageAccount.RestoreBlobRanges(WaitUntil.Started, parameters);

            //wait for restore completion
            Models.BlobRestoreStatus restoreStatus = await restoreOperation.WaitForCompletionAsync();

            Assert.IsTrue(restoreStatus.Status == BlobRestoreProgressStatus.Complete || restoreStatus.Status == BlobRestoreProgressStatus.InProgress);
        }
Example #9
0
        public async Task FileShareAccessPolicy()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            //create share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share         = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData())).Value;

            // Prepare signedIdentifiers to set
            List <SignedIdentifier> sigs    = new List <SignedIdentifier>();
            DateTimeOffset          datenow = Recording.Now;
            DateTimeOffset          start1  = datenow.ToUniversalTime();
            DateTimeOffset          end1    = datenow.AddHours(2).ToUniversalTime();
            DateTimeOffset          start2  = datenow.AddMinutes(1).ToUniversalTime();
            DateTimeOffset          end2    = datenow.AddMinutes(40).ToUniversalTime();
            var updateParameters2           = new FileShareData();
            SignedIdentifier sig1           = new SignedIdentifier("testSig1",
                                                                   new AccessPolicy(startTime: start1,
                                                                                    expiryTime: end1,
                                                                                    permission: "rw"));
            SignedIdentifier sig2 = new SignedIdentifier("testSig2",
                                                         new AccessPolicy(startTime: start2,
                                                                          expiryTime: end2,
                                                                          permission: "rwdl"));

            updateParameters2.SignedIdentifiers.Add(sig1);
            updateParameters2.SignedIdentifiers.Add(sig2);

            // Update share
            share = await share.UpdateAsync(updateParameters2);

            Assert.AreEqual(2, share.Data.SignedIdentifiers.Count);
            Assert.AreEqual("testSig1", share.Data.SignedIdentifiers[0].Id);
            Assert.AreEqual("rw", share.Data.SignedIdentifiers[0].AccessPolicy.Permission);
        }
        public async Task CreateGetDeleteObjectReplicationPolicy()
        {
            //create 2 storage accounts
            string accountName1 = await CreateValidAccountNameAsync("teststoragemgmt");

            string accountName2 = await CreateValidAccountNameAsync("teststoragemgmt");

            StorageAccountCreateParameters createParameters = GetDefaultStorageAccountParameters(kind: StorageKind.StorageV2);
            StorageAccountResource         sourceAccount    = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName1, createParameters)).Value;
            StorageAccountResource         destAccount      = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName2, createParameters)).Value;

            //update 2 accounts properties
            var updateparameter = new PatchableStorageAccountData
            {
                AllowCrossTenantReplication = true,
                EnableHttpsTrafficOnly      = true
            };

            destAccount = await destAccount.UpdateAsync(updateparameter);

            sourceAccount = await sourceAccount.UpdateAsync(updateparameter);

            BlobServiceResource blobService1 = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection1 = blobService1.GetBlobContainers();
            BlobServiceResource     blobService2             = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection2 = blobService2.GetBlobContainers();

            //enable changefeed and versoning
            blobService1.Data.IsVersioningEnabled = true;
            await blobService1.CreateOrUpdateAsync(WaitUntil.Completed, blobService1.Data);

            //create 2 pairs of source and dest blob containers
            string containerName1            = Recording.GenerateAssetName("testblob1");
            string containerName2            = Recording.GenerateAssetName("testblob2");
            string containerName3            = Recording.GenerateAssetName("testblob3");
            string containerName4            = Recording.GenerateAssetName("testblob4");
            BlobContainerResource container1 = (await blobContainerCollection1.CreateOrUpdateAsync(WaitUntil.Completed, containerName1, new BlobContainerData())).Value;
            BlobContainerResource container2 = (await blobContainerCollection2.CreateOrUpdateAsync(WaitUntil.Completed, containerName2, new BlobContainerData())).Value;
            BlobContainerResource container3 = (await blobContainerCollection1.CreateOrUpdateAsync(WaitUntil.Completed, containerName3, new BlobContainerData())).Value;
            BlobContainerResource container4 = (await blobContainerCollection2.CreateOrUpdateAsync(WaitUntil.Completed, containerName4, new BlobContainerData())).Value;

            //prepare rules and policy
            ObjectReplicationPolicyData parameter = new ObjectReplicationPolicyData()
            {
                SourceAccount      = sourceAccount.Id.Name,
                DestinationAccount = destAccount.Id.Name
            };
            List <string> prefix = new List <string>();

            prefix.Add("aa");
            prefix.Add("bc d");
            prefix.Add("123");
            string minCreationTime = "2021-03-19T16:06:00Z";
            List <ObjectReplicationPolicyRule> rules = new List <ObjectReplicationPolicyRule>();

            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName1, containerName2)
            {
                Filters = new ObjectReplicationPolicyFilter(prefix, minCreationTime),
            }
                );
            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName3, containerName4)
                );

            //create policy
            ObjectReplicationPolicyCollection objectReplicationPolicyCollection = destAccount.GetObjectReplicationPolicies();
            ObjectReplicationPolicyResource   objectReplicationPolicy           = (await objectReplicationPolicyCollection.CreateOrUpdateAsync(WaitUntil.Completed, "default", parameter)).Value;

            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //get policy
            List <ObjectReplicationPolicyResource> policies = await objectReplicationPolicyCollection.GetAllAsync().ToEnumerableAsync();

            objectReplicationPolicy = policies[0];
            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //delete policy
            await objectReplicationPolicy.DeleteAsync(WaitUntil.Completed);
        }
Example #11
0
        public async Task FileShareLease()
        {
            //update storage account to v2
            PatchableStorageAccountData updateParameters = new PatchableStorageAccountData()
            {
                Kind = StorageKind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            //create base share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share         = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData())).Value;

            //create share snapshots
            FileShare shareSnapshot = (await _fileShareCollection.CreateOrUpdateAsync(WaitUntil.Completed, fileShareName, new FileShareData(), "snapshots")).Value;

            // Acquire lease share
            string             proposedLeaseID1 = "ca761232-ed42-11ce-bacd-00aa0057b223";
            string             proposedLeaseID2 = "dd761232-ed42-11ce-bacd-00aa0057b444";
            LeaseShareResponse leaseResponse;

            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Acquire)
            {
                LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            share = await share.GetAsync();

            Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration);
            Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState);
            Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus);

            //renew lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Renew)
            {
                LeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            // change lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Change)
            {
                LeaseId = proposedLeaseID1, ProposedLeaseId = proposedLeaseID2
            });

            Assert.AreEqual(proposedLeaseID2, leaseResponse.LeaseId);

            //break lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Break)
            {
                BreakPeriod = 20
            });

            Assert.AreEqual("20", leaseResponse.LeaseTimeSeconds);

            //release lease share
            leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Release)
            {
                LeaseId = proposedLeaseID2
            });

            Assert.IsNull(leaseResponse.LeaseId);

            //lease share snapshot
            leaseResponse = await share.LeaseAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o"),
                                                   parameters : new LeaseShareRequest(LeaseShareAction.Acquire)
            {
                LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1
            });

            Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId);

            shareSnapshot = await shareSnapshot.GetAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o"));

            Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration);
            Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState);
            Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus);

            bool DeleteFail = false;

            // try delete with include = none
            try
            {
                await share.DeleteAsync(WaitUntil.Completed, include : "none");
            }
            catch (RequestFailedException e) when(e.Status == 409)
            {
                DeleteFail = true;
            }
            Assert.IsTrue(DeleteFail, "Delete should fail with include = none");

            DeleteFail = false;
            // try delete with include = snapshots
            try
            {
                await share.DeleteAsync(WaitUntil.Completed, include : "snapshots");
            }
            catch (RequestFailedException e) when(e.Status == 409)
            {
                DeleteFail = true;
            }
            Assert.IsTrue(DeleteFail, "Delete should fail with include = snapshots");

            //delete with include = leased-snapshots
            await share.DeleteAsync(WaitUntil.Completed, include : "leased-snapshots");
        }