public IActionResult Create([RegularExpression(@"^(Datalake|Blob)$")] string resourceType) { _logger.LogTrace($"HomeController.Create (GET) for {resourceType} entered."); try { var creationVm = new ResourceToCreateViewModel { TryWithoutPrivilegedBackend = false, ResourceName = "", FriendlyType = resourceType, Location = "", ResourceSku = MszCool.Samples.PodIdentityDemo.ResourcesRepository.Sku.Standard }; // For a Datalake in this example a filesystem name and folder name can be passed in. if (resourceType == "Datalake") { creationVm.ResourcePropertiesForCreation = new Dictionary <string, string> { { "Filesystem", "demofs" }, { "Folder", "default" } }; } return(View(creationVm)); } finally { _logger.LogTrace($"HomeController.Create (GET) for {resourceType} completed."); } }
public async Task <IActionResult> Create([Bind] ResourceToCreateViewModel creationInfo) { _logger.LogTrace($"HomeController.Create (POST) with {creationInfo.ResourceName} entered."); try { if (ModelState.IsValid) { // Trying without the privileged backend service should demonstrate the value of the concept of // creating privileged, private microservices for control plane operations of an PaaS/SaaS platform // that needs to provision resources when dynamically provisioning customer instances / tenants for their offering. if (creationInfo.TryWithoutPrivilegedBackend) { _logger.LogInformation($"HomeController.Create (POST) trying to create resource of type {creationInfo.FriendlyType} without backend-service."); switch (creationInfo.FriendlyType) { case "Datalake": await _storageRepo.CreateAsync( creationInfo.ResourceName, creationInfo.Location, StorageType.Datalake, creationInfo.ResourceSku, _frontendSettings.SecurityConfig.ClientId, creationInfo.ResourcePropertiesForCreation["Filesystem"], creationInfo.ResourcePropertiesForCreation["Folder"]); break; case "Blob": await _storageRepo.CreateAsync( creationInfo.ResourceName, creationInfo.Location, StorageType.Blob, creationInfo.ResourceSku); break; default: throw new System.ArgumentException("Invalid resource type passed in. Please check valid types for this sample!"); } ; _logger.LogInformation($"HomeController.Create (POST) created resource of type {creationInfo.FriendlyType} without backend-service, SUCCESSFULLY."); } else { _logger.LogInformation($"HomeController.Create (POST) trying to create resource of type {creationInfo.FriendlyType} WITH gRPC backend-service."); // Call the privileged backend service. In a setup in which the managed identity of this frontend web app // has reader permissions, only (which should be the case), only by calling the privileged backend service // the resource creation operations should succeed. #pragma warning disable CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. var requestMessage = new ResourceCreationRequest { Name = creationInfo.ResourceName, Location = creationInfo.Location, Sku = creationInfo.ResourceSku switch // This here caused CS8524 - probably a compiler bug? { ResourcesRepository.Sku.Basic => SupportedSkus.Basic, ResourcesRepository.Sku.Standard => SupportedSkus.Standard, ResourcesRepository.Sku.Premium => SupportedSkus.Premium }, ResType = creationInfo.FriendlyType switch { "Datalake" => SupportedResourceTypes.Datalake, "Blob" => SupportedResourceTypes.Storage, _ => SupportedResourceTypes.Generic } };