/// <summary> /// Check if the resource name is available /// </summary> public async Task <YHttpResponse <JObject> > CheckResourceNameIsAvailableAsync(string resourceName, string provider, string type, string apiversion, CancellationToken cancellationToken = default) { if (resourceName == null) { throw new ArgumentNullException(nameof(resourceName)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } if (provider == null) { throw new ArgumentNullException(nameof(type)); } if (string.IsNullOrEmpty(this.options?.SubscriptionId)) { throw new ArgumentNullException("SubscriptionId"); } var parameters = new YResource { Name = resourceName, Type = type }; var fullPath = new Uri($"https://management.azure.com/providers/{provider}/checkNameAvailability?api-version={apiversion}"); var accessToken = await authProvider.GetAccessTokenForAppManagementAsync(); var result = await this.requestHandler.ProcessRequestAsync <JObject>(fullPath, parameters, HttpMethod.Post, accessToken, default, cancellationToken);
public async Task <ActionResult <YResource> > CreateDataBricksWorkspaceAsync(Guid engineId, [FromBody] YDataBricksPayload payload) { payload.Location.EnsureLocation(); var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false); if (engine == null) { throw new Exception("Engine does not exists"); } var resourceGroupName = engine.ResourceGroupName; var workspaceName = engine.ClusterName; var managedResourceGroupId = string.IsNullOrEmpty(payload.ManagedResourceGroupId) ? $"dataBricks-{resourceGroupName}" : payload.ManagedResourceGroupId; if (managedResourceGroupId == resourceGroupName) { throw new Exception($"The managed resource group can not have the same name as resource group name"); } // Create Databricks payload var resourceRequest = new YResource { Location = payload.Location, Properties = new Dictionary <string, object>() { { "managedResourceGroupId", $"/subscriptions/{this.options.SubscriptionId}/resourceGroups/{managedResourceGroupId}" } } }; var resourceResponse = await this.resourceClient.StartCreateOrUpdateAsync (resourceGroupName, "Microsoft.Databricks", "", "workspaces", workspaceName, DataBricksApiVersion, resourceRequest); var provisioningState = resourceResponse.Value.Properties["provisioningState"].ToString(); if (provisioningState == "Accepted" || provisioningState == "Succeeded") { engine = await this.engineProvider.GetEngineAsync(payload.EngineId); await this.engineProvider.SaveEngineAsync(engine); } return(resourceResponse.Value); }
public async Task <ActionResult <YResource> > CreateStorageAsync(Guid engineId, [FromBody] YStoragePayload payload) { payload.Location.EnsureLocation(); var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false); if (engine == null) { throw new Exception("Engine does not exists"); } if (string.IsNullOrEmpty(engine.ResourceGroupName)) { throw new Exception("Resource group name does not exists"); } if (string.IsNullOrEmpty(engine.StorageName)) { throw new Exception("Storage name does not exists"); } // Create Azure Key Vault payload var resourceRequest = new YResource { Location = engine.Location, Sku = new YSku { Name = "Standard_GRS" }, Kind = "StorageV2", Properties = new Dictionary <string, object> { { "isHnsEnabled", true }, { "accessTier", "Hot" }, } }; var resourceResponse = await this.resourceClient.StartCreateOrUpdateAsync (engine.ResourceGroupName, "Microsoft.Storage", "", "storageAccounts", engine.StorageName, StorageApiVersion, resourceRequest); return(resourceResponse.Value); }
public async Task <YResource> CreateResourceGroupAsync(string name, [FromBody] YResourceGroupPayload payload) { payload.Location.EnsureLocation(); name.EnsureStringIsLetterOrDigit(); var check = await this.client.CheckResourceNameIsValidAsync(name, "Microsoft.Resources/subscriptions/resourcegroups"); if (check.Value.Status != "Allowed") { throw new Exception($"Name {name} is not allowed"); } var resourceRequest = new YResource { Location = payload.Location, Tags = payload.Tags }; var resourceResponse = await this.client.CreateOrUpdateAsync(name, ApiVersion, resourceRequest); return(resourceResponse.Value); }
public async Task <ActionResult <YResource> > CreateKeyVaultAsync(Guid engineId, [FromBody] YKeyVaultPayload payload) { payload.Location.EnsureLocation(); var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false); if (engine == null) { throw new Exception("Engine does not exists"); } if (string.IsNullOrEmpty(engine.ResourceGroupName)) { throw new Exception("Resource group name does not exists"); } if (string.IsNullOrEmpty(engine.KeyVaultName)) { throw new Exception("Keyvault name does not exists"); } // Create Azure Key Vault payload var resourceRequest = new YResource { Location = engine.Location, Properties = new Dictionary <string, object> { { "tenantId", this.options.TenantId }, { "sku", new JObject { { "family", "A" }, { "name", "Standard" } } }, { "networkAcls", new JObject { { "defaultAction", "Allow" }, { "bypass", "AzureServices" } } }, { "enablePurgeProtection", "true" }, { "enableSoftDelete", "true" }, { "accessPolicies", new JArray { new JObject { { "tenantId", this.options.TenantId }, { "objectId", this.options.ClientObjectId }, { "permissions", new JObject { { "keys", new JArray { "get", "list", "create", "update", "delete", "backup", "restore", "recover", "purge" } }, { "secrets", new JArray { "get", "list", "set", "delete", "backup", "restore", "recover", "purge" } }, { "certificates", new JArray { "get", "list", "create", "update", "delete", "recover", "purge" } } } } } } } } }; var resourceResponse = await this.resourceClient.StartCreateOrUpdateAsync (engine.ResourceGroupName, "Microsoft.KeyVault", "", "vaults", engine.KeyVaultName, KeyVaultApiVersion, resourceRequest); return(resourceResponse.Value); }