예제 #1
0
파일: Handler.cs 프로젝트: cythral/cfn
        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,
            });
        }
예제 #2
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)}");
        }