public async Task HandleAsync(CapabilityRegisteredEvent capabilityRegisteredEvent) { var capabilityName = capabilityRegisteredEvent.CapabilityName.ToLower(); var configmapRoleName = capabilityName; await _configMapService.AddRole( roleName : configmapRoleName, roleArn : capabilityRegisteredEvent.RoleArn ); var namespaceName = capabilityName; await _namespaceRepository.CreateNamespace( namespaceName : namespaceName, roleName : configmapRoleName ); var namespaceRoleName = await _roleRepository .CreateNamespaceFullAccessRole(namespaceName); await _roleBindingRepository.BindNamespaceRoleToGroup( namespaceName : namespaceName, role : namespaceRoleName, group : capabilityName ); }
public async Task <ActionResult> AddNamespace([FromBody] AddNamespaceRequest addNamespaceRequest) { if (!_addNamespaceRequestValidator.TryValidateAddNamespaceRequest(addNamespaceRequest, out string validationError)) { Log.Warning($"Add namespace called with invalid input. Validation error: {validationError}"); return(BadRequest(validationError)); } try { await _namespaceRepository.CreateNamespace( addNamespaceRequest.NamespaceName, addNamespaceRequest.RoleName ); await _roleRepository .CreateNamespaceFullAccessRole(addNamespaceRequest.NamespaceName); return(Ok()); } catch (Exception ex) { Log.Error($"An error occured trying to create the namespace: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, $"An error occured trying to create the namespace: {ex.Message}")); } }