コード例 #1
0
        /// <summary>
        /// Creates a new Batch account
        /// </summary>
        /// <param name="parameters">The parameters defining the Batch account to create.</param>
        /// <returns>A BatchAccountContext object representing the new account</returns>
        public virtual BatchAccountContext CreateAccount(AccountCreateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(parameters.Tags, validate: true);

            AutoStorageBaseProperties autoStorage = (string.IsNullOrEmpty(parameters.AutoStorageAccountId)) ? null : new AutoStorageBaseProperties
            {
                StorageAccountId = parameters.AutoStorageAccountId
            };

            KeyVaultReference keyVaultRef = null;

            if (!string.IsNullOrEmpty(parameters.KeyVaultId) || !string.IsNullOrEmpty(parameters.KeyVaultUrl))
            {
                keyVaultRef = new KeyVaultReference(parameters.KeyVaultId, parameters.KeyVaultUrl);
            }

            var response = BatchManagementClient.BatchAccount.Create(parameters.ResourceGroup, parameters.BatchAccount, new BatchAccountCreateParameters()
            {
                Location            = parameters.Location,
                Tags                = tagDictionary,
                AutoStorage         = autoStorage,
                PoolAllocationMode  = parameters.PoolAllocationMode,
                KeyVaultReference   = keyVaultRef,
                PublicNetworkAccess = parameters.PublicNetworkAccess
            });

            var context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(response, this.azureContext);

            return(context);
        }
コード例 #2
0
        private static void ResolveKeyVaultReferences(HostBuilderContext context, IConfigurationBuilder builder)
        {
            var config   = builder.Build();
            var resolved = new Dictionary <string, string>();

            foreach (var pair in config.AsEnumerable())
            {
                var keyVaultReference = KeyVaultReference.TryParse(pair.Value);
                if (keyVaultReference != null)
                {
                    resolved[pair.Key] = keyVaultHelper !.GetSecretAsync(keyVaultReference).Result;
                }
            }

            if (resolved.Any())
            {
                builder.AddInMemoryCollection(resolved);
            }
        }
コード例 #3
0
        public void BatchAccountContextFromResourceTest()
        {
            string             account         = "account";
            string             tenantUrlEnding = "batch-test.windows-int.net";
            string             endpoint        = string.Format("{0}.{1}", account, tenantUrlEnding);
            string             subscription    = "00000000-0000-0000-0000-000000000000";
            string             resourceGroup   = "resourceGroup";
            string             id             = string.Format("id/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Batch/batchAccounts/abc", subscription, resourceGroup);
            PoolAllocationMode allocationMode = PoolAllocationMode.UserSubscription;
            KeyVaultReference  keyVault       = new KeyVaultReference(
                string.Format("/subscriptions{0}/resourceGroups/{1}/providers/Microsoft.KeyVault/vaults/foo", subscription, resourceGroup),
                "https://foo.vaults.azure.com");

            BatchAccount resource = new BatchAccount(
                dedicatedCoreQuota: BatchTestHelpers.DefaultQuotaCount,
                lowPriorityCoreQuota: BatchTestHelpers.DefaultQuotaCount,
                poolQuota: BatchTestHelpers.DefaultQuotaCount,
                activeJobAndJobScheduleQuota: BatchTestHelpers.DefaultQuotaCount,
                accountEndpoint: endpoint,
                id: id,
                type: "type",
                location: "location",
                provisioningState: ProvisioningState.Succeeded,
                poolAllocationMode: allocationMode,
                keyVaultReference: keyVault);

            BatchAccountContext context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(resource, null);

            Assert.Equal(resource.Id, context.Id);
            Assert.Equal(resource.AccountEndpoint, context.AccountEndpoint);
            Assert.Equal(resource.Location, context.Location);
            Assert.Equal(resource.ProvisioningState.ToString(), context.State);
            Assert.Equal(account, context.AccountName);
            Assert.Equal(string.Format("https://{0}", endpoint), context.TaskTenantUrl);
            Assert.Equal(subscription, context.Subscription);
            Assert.Equal(resourceGroup, context.ResourceGroupName);
            Assert.Equal(allocationMode, context.PoolAllocationMode);
            Assert.Equal(keyVault.Id, context.KeyVaultReference.Id);
            Assert.Equal(keyVault.Url, context.KeyVaultReference.Url);
        }