Esempio n. 1
0
        private async Task SendSuccess(StackDeploymentStatusRequest request)
        {
            var tokenInfo = await tokenInfoRepository.FindByRequest(request);

            if (request.SourceTopic != config.GithubTopicArn)
            {
                var outputs = await GetStackOutputs(request.StackId, tokenInfo.RoleArn);

                var response = await stepFunctionsClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                {
                    TaskToken = tokenInfo.ClientRequestToken,
                    Output    = JsonSerializer.Serialize(outputs)
                });

                logger.LogInformation($"Received send task success response: {JsonSerializer.Serialize(response)}");
                await Dequeue(tokenInfo);
            }

            await githubStatusNotifier.NotifySuccess(
                tokenInfo.GithubOwner,
                tokenInfo.GithubRepo,
                tokenInfo.GithubRef,
                request.StackName,
                tokenInfo.EnvironmentName
                );
        }
Esempio n. 2
0
        public async Task <Response> Handle(SQSEvent sqsEvent, CancellationToken cancellationToken = default)
        {
            var request        = requestFactory.CreateFromSqsEvent(sqsEvent);
            var bucket         = config.StateStore;
            var getObjResponse = await s3GetObjectFacade.TryGetObject <StateInfo>(bucket, $"{request.Pipeline}/state.json");

            var stateInfo = getObjResponse ?? new StateInfo
            {
                LastCommitTimestamp = DateTime.MinValue
            };

            var superseded      = request.CommitTimestamp < stateInfo.LastCommitTimestamp;
            var sendTaskRequest = new SendTaskSuccessRequest
            {
                TaskToken = request.Token,
                Output    = Serialize(new
                {
                    Superseded = superseded
                })
            };

            var sendTaskResponse = await stepFunctionsClient.SendTaskSuccessAsync(sendTaskRequest, cancellationToken);

            logger.LogInformation($"Got send task response: {Serialize(sendTaskResponse)}");

            if (!superseded)
            {
                var putObjectRequest = new PutObjectRequest
                {
                    BucketName  = bucket,
                    Key         = $"{request.Pipeline}/state.json",
                    ContentBody = Serialize(new StateInfo
                    {
                        LastCommitTimestamp = request.CommitTimestamp
                    })
                };

                var putObjectResponse = await s3Client.PutObjectAsync(putObjectRequest, cancellationToken);

                logger.LogInformation($"Got put object response: {Serialize(putObjectResponse)}");
            }

            return(new Response
            {
                Success = true
            });
        }
Esempio n. 3
0
        public async Task CompleteTask(SNSEvent.SNSMessage message)
        {
            if (message.Message == "available")
            {
                await stepFunctionsClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                {
                    Output    = Serialize(new { Status = message.Message }),
                    TaskToken = message.MessageAttributes["TaskToken"].Value
                });

                return;
            }

            await stepFunctionsClient.SendTaskFailureAsync(new SendTaskFailureRequest
            {
                Cause     = message.Message,
                TaskToken = message.MessageAttributes["TaskToken"].Value
            });
        }
 private Amazon.StepFunctions.Model.SendTaskSuccessResponse CallAWSServiceOperation(IAmazonStepFunctions client, Amazon.StepFunctions.Model.SendTaskSuccessRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Step Functions", "SendTaskSuccess");
     try
     {
         #if DESKTOP
         return(client.SendTaskSuccess(request));
         #elif CORECLR
         return(client.SendTaskSuccessAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Esempio n. 5
0
        public async Task <ApplicationLoadBalancerResponse> Handle(ApplicationLoadBalancerRequest request, CancellationToken cancellationToken = default)
        {
            var action       = request.QueryStringParameters["action"];
            var pipeline     = request.QueryStringParameters["pipeline"];
            var tokenHash    = request.QueryStringParameters["token"];
            var key          = $"{pipeline}/approvals/{tokenHash}";
            var bucket       = config.StateStore;
            var approvalInfo = await s3GetObjectFacade.GetObject <ApprovalInfo>(bucket, key);

            var sendTaskResponse = await stepFunctionsClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
            {
                TaskToken = approvalInfo.Token,
                Output    = Serialize(new
                {
                    Action = action,
                })
            });

            logger.LogInformation($"Send task success response: {Serialize(sendTaskResponse)}");

            var deleteResponse = await s3Client.DeleteObjectAsync(bucket, key);

            logger.LogInformation($"Received delete response: {Serialize(deleteResponse)}");

            var body = action == "approve" ? "approved" : "rejected";

            return(new ApplicationLoadBalancerResponse
            {
                StatusCode = 200,
                StatusDescription = "200 OK",
                Headers = new Dictionary <string, string> {
                    ["content-type"] = "text/plain"
                },
                Body = body,
                IsBase64Encoded = false,
            });
        }
Esempio n. 6
0
        private async Task CancelPreviousApproval(S3Object location)
        {
            var approvalInfo = await s3GetObjectFacade.GetObject <ApprovalInfo>(location.BucketName, location.Key);

            try
            {
                var sendTaskCancelResponse = await stepFunctionsClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                {
                    TaskToken = approvalInfo.Token,
                    Output    = Serialize(new
                    {
                        Action = "reject"
                    })
                });

                logger.LogDebug($"Cancellation response: {Serialize(sendTaskCancelResponse)}");
            }
            catch (TaskTimedOutException) { }
            catch (TaskDoesNotExistException) { }

            var deleteResponse = await s3Client.DeleteObjectAsync(location.BucketName, location.Key);

            logger.LogDebug($"Delete approval object response: {Serialize(deleteResponse)}");
        }
Esempio n. 7
0
        public async Task <Response> Handle(SQSEvent sqsEvent, CancellationToken cancellationToken = default)
        {
            var request         = requestFactory.CreateFromSqsEvent(sqsEvent);
            var owner           = request.CommitInfo.GithubOwner;
            var repository      = request.CommitInfo.GithubRepository;
            var sha             = request.CommitInfo.GithubRef;
            var stackName       = request.StackName;
            var environmentName = request.EnvironmentName;

            try
            {
                var notificationArn = Environment.GetEnvironmentVariable(notificationArnKey);
                var template        = await s3Util.GetZipEntryInObject(request.ZipLocation, request.TemplateFileName);

                var stackConfig = await GetConfig(request);

                var token = await tokenGenerator.Generate(sqsEvent, request);

                await statusNotifier.NotifyPending(owner, repository, sha, stackName, environmentName);

                await stackDeployer.Deploy(new DeployStackContext
                {
                    StackName          = request.StackName,
                    Template           = template,
                    RoleArn            = request.RoleArn,
                    NotificationArn    = config.NotificationArn,
                    Parameters         = MergeParameters(stackConfig?.Parameters, request.ParameterOverrides),
                    Tags               = stackConfig?.Tags,
                    StackPolicyBody    = stackConfig?.StackPolicy?.Value,
                    ClientRequestToken = token,
                    Capabilities       = request.Capabilities,
                });
            }
            catch (NoUpdatesException)
            {
                var outputs = await GetStackOutputs(request.StackName, request.RoleArn);

                var response = await stepFunctionsClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                {
                    TaskToken = request.Token,
                    Output    = JsonSerializer.Serialize(outputs)
                });

                await statusNotifier.NotifySuccess(owner, repository, sha, stackName, environmentName);

                return(new Response
                {
                    Success = true
                });
            }
            catch (Exception e)
            {
                var response = await stepFunctionsClient.SendTaskFailureAsync(new SendTaskFailureRequest
                {
                    TaskToken = request.Token,
                    Cause     = e.Message
                });

                await statusNotifier.NotifyFailure(owner, repository, sha, stackName, environmentName);

                return(new Response
                {
                    Success = true
                });
            }

            throw new Exception();
        }