コード例 #1
0
        public async Task <IActionResult> DeployDemo([FromBody] DeployToClusterRequest request)
        {
            var cluster = await this.mediator.Send(new EnsureClusterWithIdCommand(DataContext.DemoClusterId));

            var authenticatedUser = User?.Identity?.Name != null ?
                                    await this.mediator.Send(new EnsureUserForIdentityCommand(User)) :
                                    null;

            return(await HandleDeploymentAsync(
                       request,
                       authenticatedUser?.Id,
                       clusterId : cluster.Id));
        }
コード例 #2
0
        public async Task <IActionResult> Deploy(Guid?clusterId, [FromBody] DeployToClusterRequest request)
        {
            var user = await this.mediator.Send(new EnsureUserForIdentityCommand(User));

            return(await HandleDeploymentAsync(request, user.Id, clusterId));
        }
コード例 #3
0
 public async Task <IActionResult> Deploy([FromBody] DeployToClusterRequest request)
 {
     return(await Deploy(clusterId : null, request));
 }
コード例 #4
0
        private async Task <IActionResult> HandleDeploymentAsync(
            DeployToClusterRequest request,
            Guid?userId,
            Guid?clusterId)
        {
            try
            {
                var repositoryName     = userId == null ? "demo" : userId.Value.ToString();
                var repositoryResponse = await this.mediator.Send(new EnsureRepositoryWithNameCommand(repositoryName)
                {
                    UserId = userId
                });

                var login = await this.mediator.Send(new GetRepositoryLoginForUserQuery(repositoryResponse.ReadUser));

                if (request.Files != null)
                {
                    ConvertWindowsPathSeparatorsToUnixInFileRequests(request.Files);
                }

                var job = await this.mediator.Send(new DeployToClusterCommand(
                                                       request.DockerComposeYmlFilePaths)
                {
                    ClusterId      = clusterId,
                    UserId         = userId,
                    Files          = request.Files,
                    Authentication = new []
                    {
                        new DockerAuthenticationArguments(
                            login.Username,
                            login.Password)
                        {
                            RegistryHostName = repositoryResponse.HostName
                        }
                    }
                });

                return(Ok(this.mapper.Map <DeployToClusterResponse>(job)));
            }
            catch (NotAuthorizedToAccessClusterException)
            {
                return(ValidationProblem(new ValidationProblemDetails()
                {
                    Type = "NOT_AUTHORIZED"
                }));
            }
            catch (ClusterNotFoundException)
            {
                return(ValidationProblem(new ValidationProblemDetails()
                {
                    Type = "CLUSTER_NOT_FOUND"
                }));
            }
            catch (ClusterQueryTooBroadException)
            {
                return(ValidationProblem(new ValidationProblemDetails()
                {
                    Type = "TOO_BROAD"
                }));
            }
        }