Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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 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;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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);
                }
            }
        }
Ejemplo n.º 12
0
        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 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
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
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();
        }
Ejemplo n.º 22
0
        public async Task CreateUpdataNetworkRule()
        {
            //create storage account with network rule
            string accountName = await CreateValidAccountNameAsync(namePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountContainer        storageAccountContainer = _resourceGroup.GetStorageAccounts();
            StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters();

            parameters.NetworkRuleSet = new NetworkRuleSet(defaultAction: DefaultAction.Deny)
            {
                Bypass  = @"Logging, AzureServices",
                IpRules = { new IPRule(iPAddressOrRange: "23.45.67.89") }
            };
            StorageAccount account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value;

            VerifyAccountProperties(account1, false);

            //verify network rule
            StorageAccountData accountData = account1.Data;

            Assert.NotNull(accountData.NetworkRuleSet);
            Assert.AreEqual(@"Logging, AzureServices", accountData.NetworkRuleSet.Bypass.ToString());
            Assert.AreEqual(DefaultAction.Deny, accountData.NetworkRuleSet.DefaultAction);
            Assert.IsEmpty(accountData.NetworkRuleSet.VirtualNetworkRules);
            Assert.NotNull(accountData.NetworkRuleSet.IpRules);
            Assert.IsNotEmpty(accountData.NetworkRuleSet.IpRules);
            Assert.AreEqual("23.45.67.89", accountData.NetworkRuleSet.IpRules[0].IPAddressOrRange);
            Assert.AreEqual(DefaultAction.Allow.ToString(), accountData.NetworkRuleSet.IpRules[0].Action);

            //update network rule
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                NetworkRuleSet = new NetworkRuleSet(defaultAction: DefaultAction.Deny)
                {
                    Bypass  = @"Logging, Metrics",
                    IpRules = { new IPRule(iPAddressOrRange: "23.45.67.90"),
                                new IPRule(iPAddressOrRange: "23.45.67.91") }
                }
            };
            StorageAccount account2 = await account1.UpdateAsync(updateParameters);

            //verify updated network rule
            accountData = account2.Data;
            Assert.NotNull(accountData.NetworkRuleSet);
            Assert.AreEqual(@"Logging, Metrics", accountData.NetworkRuleSet.Bypass.ToString());
            Assert.AreEqual(DefaultAction.Deny, accountData.NetworkRuleSet.DefaultAction);
            Assert.IsEmpty(accountData.NetworkRuleSet.VirtualNetworkRules);
            Assert.NotNull(accountData.NetworkRuleSet.IpRules);
            Assert.IsNotEmpty(accountData.NetworkRuleSet.IpRules);
            Assert.AreEqual("23.45.67.90", accountData.NetworkRuleSet.IpRules[0].IPAddressOrRange);
            Assert.AreEqual(DefaultAction.Allow.ToString(), accountData.NetworkRuleSet.IpRules[0].Action);
            Assert.AreEqual("23.45.67.91", accountData.NetworkRuleSet.IpRules[1].IPAddressOrRange);
            Assert.AreEqual(DefaultAction.Allow.ToString(), accountData.NetworkRuleSet.IpRules[1].Action);

            //update network rule to allow
            updateParameters = new StorageAccountUpdateParameters()
            {
                NetworkRuleSet = new NetworkRuleSet(defaultAction: DefaultAction.Allow)
            };
            StorageAccount account3 = await account2.UpdateAsync(updateParameters);

            //verify updated network rule
            accountData = account3.Data;
            Assert.NotNull(accountData.NetworkRuleSet);
            Assert.AreEqual(@"Logging, Metrics", accountData.NetworkRuleSet.Bypass.ToString());
            Assert.AreEqual(DefaultAction.Allow, accountData.NetworkRuleSet.DefaultAction);
        }
Ejemplo n.º 23
0
        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));
        }
Ejemplo n.º 24
0
        public async Task UpdateStorageAccount()
        {
            //create storage account
            string accountName = await CreateValidAccountNameAsync(namePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts();
            StorageAccount          account1 = (await storageAccountContainer.CreateOrUpdateAsync(accountName, GetDefaultStorageAccountParameters())).Value;

            VerifyAccountProperties(account1, true);

            //update sku
            StorageAccountUpdateParameters parameters = new StorageAccountUpdateParameters()
            {
                Sku = new Sku(SkuName.StandardLRS),
            };

            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(account1.Data.Sku.Name, SkuName.StandardLRS);

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

            Assert.AreEqual(account2.Data.Sku.Name, SkuName.StandardLRS);

            //update tags
            parameters.Tags.Clear();
            parameters.Tags.Add("key3", "value3");
            parameters.Tags.Add("key4", "value4");
            parameters.Tags.Add("key5", "value5");
            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(account1.Data.Tags.Count, parameters.Tags.Count);

            //validate
            account2 = await storageAccountContainer.GetAsync(accountName);

            Assert.AreEqual(account2.Data.Tags.Count, parameters.Tags.Count);

            //update encryption
            parameters.Encryption = new Encryption(KeySource.MicrosoftStorage)
            {
                Services = new EncryptionServices {
                    Blob = new EncryptionService {
                        Enabled = true
                    }, File = new EncryptionService {
                        Enabled = true
                    }
                }
            };
            account1 = await account1.UpdateAsync(parameters);

            Assert.NotNull(account1.Data.Encryption);

            //validate
            account2 = await storageAccountContainer.GetAsync(accountName);

            Assert.NotNull(account2.Data.Encryption);
            Assert.NotNull(account2.Data.Encryption.Services.Blob);
            Assert.True(account2.Data.Encryption.Services.Blob.Enabled);
            Assert.NotNull(account2.Data.Encryption.Services.Blob.LastEnabledTime);
            Assert.NotNull(account2.Data.Encryption.Services.File);
            Assert.True(account2.Data.Encryption.Services.File.Enabled);
            Assert.NotNull(account2.Data.Encryption.Services.File.LastEnabledTime);

            //update http traffic only and validate
            parameters = new StorageAccountUpdateParameters()
            {
                EnableHttpsTrafficOnly = false
            };
            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(account1.Data.EnableHttpsTrafficOnly, false);
            account2 = await storageAccountContainer.GetAsync(accountName);

            Assert.AreEqual(account2.Data.EnableHttpsTrafficOnly, false);
            parameters = new StorageAccountUpdateParameters()
            {
                EnableHttpsTrafficOnly = true
            };
            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(account1.Data.EnableHttpsTrafficOnly, true);
            account2 = await storageAccountContainer.GetAsync(accountName);

            Assert.AreEqual(account2.Data.EnableHttpsTrafficOnly, true);
        }
Ejemplo n.º 25
0
        public async Task CreateUpdateGetDeleteBlobInventoryPolicy()
        {
            //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;
            BlobInventoryPolicyContainer blobInventoryPolicyContainer = account.GetBlobInventoryPolicies();

            //create a blob container
            string               containerName        = Recording.GenerateAssetName("testblob");
            BlobContainerData    data                 = new BlobContainerData();
            BlobServiceContainer blobServiceContainer = account.GetBlobServices();
            BlobService          blobService          = await blobServiceContainer.GetAsync("default");

            BlobContainerContainer blobContainerContainer = blobService.GetBlobContainers();
            BlobContainer          container = (await blobContainerContainer.CreateOrUpdateAsync(containerName, new BlobContainerData())).Value;

            //prepare schema fields
            string[] BlobSchemaField = new string[] { "Name", "Creation-Time", "Last-Modified", "Content-Length", "Content-MD5", "BlobType", "AccessTier", "AccessTierChangeTime",
                                                      "Snapshot", "VersionId", "IsCurrentVersion", "Metadata", "LastAccessTime" };
            string[] ContainerSchemaField = new string[] { "Name", "Last-Modified", "Metadata", "LeaseStatus", "LeaseState", "LeaseDuration", "PublicAccess", "HasImmutabilityPolicy", "HasLegalHold" };

            List <string> blobSchemaFields1 = new List <string>(BlobSchemaField);
            List <string> blobSchemaFields2 = new List <string>();

            blobSchemaFields2.Add("Name");
            List <string> containerSchemaFields1 = new List <string>(ContainerSchemaField);
            List <string> containerSchemaFields2 = new List <string>();

            containerSchemaFields2.Add("Name");

            // prepare policy objects,the type of policy rule should always be Inventory
            List <BlobInventoryPolicyRule> ruleList = new List <BlobInventoryPolicyRule>();
            BlobInventoryPolicyRule        rule1    = new BlobInventoryPolicyRule(true, "rule1", containerName,
                                                                                  new BlobInventoryPolicyDefinition(
                                                                                      filters: new BlobInventoryPolicyFilter(
                                                                                          blobTypes: new List <string>(new string[] { "blockBlob" }),
                                                                                          prefixMatch: new List <string>(new string[] { "prefix1", "prefix2" }),
                                                                                          includeBlobVersions: true,
                                                                                          includeSnapshots: true),
                                                                                      format: Format.Csv,
                                                                                      schedule: Schedule.Weekly,
                                                                                      objectType: ObjectType.Blob,
                                                                                      schemaFields: blobSchemaFields1));

            BlobInventoryPolicyRule rule2 = new BlobInventoryPolicyRule(true, "rule2", containerName,
                                                                        new BlobInventoryPolicyDefinition(
                                                                            format: Format.Csv,
                                                                            schedule: Schedule.Daily,
                                                                            objectType: ObjectType.Container,
                                                                            schemaFields: containerSchemaFields1));

            BlobInventoryPolicyRule rule3 = new BlobInventoryPolicyRule(true, "rule3", containerName,
                                                                        new BlobInventoryPolicyDefinition(
                                                                            format: Format.Parquet,
                                                                            schedule: Schedule.Weekly,
                                                                            objectType: ObjectType.Container,
                                                                            schemaFields: containerSchemaFields2));

            ruleList.Add(rule1);
            ruleList.Add(rule2);
            BlobInventoryPolicySchema policy    = new BlobInventoryPolicySchema(true, "Inventory", ruleList);
            BlobInventoryPolicyData   parameter = new BlobInventoryPolicyData()
            {
                Policy = policy
            };

            //create and get policy, the name of blob inventory policy should always be default
            BlobInventoryPolicy blobInventoryPolicy = (await blobInventoryPolicyContainer.CreateOrUpdateAsync("default", parameter)).Value;

            blobInventoryPolicy = await blobInventoryPolicyContainer.GetAsync("default");

            Assert.AreEqual(blobInventoryPolicy.Data.Policy.Rules.Count, 2);

            //update policy
            ruleList.Add(rule3);
            BlobInventoryPolicySchema policy2    = new BlobInventoryPolicySchema(true, "Inventory", ruleList);
            BlobInventoryPolicyData   parameter2 = new BlobInventoryPolicyData()
            {
                Policy = policy2
            };

            blobInventoryPolicy = (await blobInventoryPolicyContainer.CreateOrUpdateAsync("default", parameter2)).Value;
            Assert.AreEqual(blobInventoryPolicy.Data.Policy.Rules.Count, 3);

            //delete policy
            await blobInventoryPolicy.DeleteAsync();
        }