public async Task BlobContainerEncryptionScope()
        {
            //create encryption scope
            string scopeName1        = "testscope1";
            string scopeName2        = "testscope2";
            EncryptionScopeData data = new EncryptionScopeData()
            {
                Source = EncryptionScopeSource.MicrosoftStorage,
                State  = EncryptionScopeState.Enabled
            };
            await _storageAccount.GetEncryptionScopes().CreateOrUpdateAsync(true, scopeName1, data);

            await _storageAccount.GetEncryptionScopes().CreateOrUpdateAsync(true, scopeName2, data);

            //create container
            string        containerName = Recording.GenerateAssetName("container");
            BlobContainer blobContainer = (await _blobContainerCollection.CreateOrUpdateAsync(true, containerName, new BlobContainerData()
            {
                DefaultEncryptionScope = scopeName1, DenyEncryptionScopeOverride = false
            })).Value;

            Assert.AreEqual(scopeName1, blobContainer.Data.DefaultEncryptionScope);
            Assert.False(blobContainer.Data.DenyEncryptionScopeOverride.Value);

            //Update container not support Encryption scope
            BlobContainer blobContainer2 = (await _blobContainerCollection.CreateOrUpdateAsync(true, containerName, new BlobContainerData()
            {
                DefaultEncryptionScope = scopeName2, DenyEncryptionScopeOverride = true
            })).Value;

            Assert.AreEqual(scopeName2, blobContainer2.Data.DefaultEncryptionScope);
            Assert.True(blobContainer2.Data.DenyEncryptionScopeOverride.Value);
        }
Ejemplo n.º 2
0
        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);
        }