carlin 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +378 -0
  2. package/bin/carlin +2 -0
  3. package/dist/cli.js +250 -0
  4. package/dist/config.js +10 -0
  5. package/dist/deploy/addDefaults.cloudFormation.js +138 -0
  6. package/dist/deploy/baseStack/command.js +9 -0
  7. package/dist/deploy/baseStack/config.js +30 -0
  8. package/dist/deploy/baseStack/deployBaseStack.js +61 -0
  9. package/dist/deploy/baseStack/getBaseStackResource.js +26 -0
  10. package/dist/deploy/baseStack/getBucket.template.js +44 -0
  11. package/dist/deploy/baseStack/getLambdaImageBuilder.template.js +188 -0
  12. package/dist/deploy/baseStack/getLambdaLayerBuilder.template.js +140 -0
  13. package/dist/deploy/baseStack/getVpc.template.js +169 -0
  14. package/dist/deploy/cicd/cicd.template.js +872 -0
  15. package/dist/deploy/cicd/command.js +84 -0
  16. package/dist/deploy/cicd/config.js +7 -0
  17. package/dist/deploy/cicd/deployCicd.js +114 -0
  18. package/dist/deploy/cicd/ecsTaskReportCommand.js +53 -0
  19. package/dist/deploy/cicd/getCicdStackName.js +11 -0
  20. package/dist/deploy/cicd/getTriggerPipelineObjectKey.js +12 -0
  21. package/dist/deploy/cicd/lambdas/cicdApiV1.handler.js +124 -0
  22. package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +79 -0
  23. package/dist/deploy/cicd/lambdas/executeTasks.js +91 -0
  24. package/dist/deploy/cicd/lambdas/getProcessEnvVariable.js +10 -0
  25. package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +143 -0
  26. package/dist/deploy/cicd/lambdas/index.js +11 -0
  27. package/dist/deploy/cicd/lambdas/pipelines.handler.js +154 -0
  28. package/dist/deploy/cicd/lambdas/putApprovalResultManualTask.js +52 -0
  29. package/dist/deploy/cicd/pipelines.js +52 -0
  30. package/dist/deploy/cloudFormation.core.js +286 -0
  31. package/dist/deploy/cloudFormation.js +201 -0
  32. package/dist/deploy/command.js +211 -0
  33. package/dist/deploy/lambda.js +177 -0
  34. package/dist/deploy/lambdaLayer/command.js +51 -0
  35. package/dist/deploy/lambdaLayer/deployLambdaLayer.js +142 -0
  36. package/dist/deploy/s3.js +167 -0
  37. package/dist/deploy/stackName.js +78 -0
  38. package/dist/deploy/staticApp/command.js +101 -0
  39. package/dist/deploy/staticApp/getOriginShieldRegion.js +30 -0
  40. package/dist/deploy/staticApp/staticApp.js +206 -0
  41. package/dist/deploy/staticApp/staticApp.template.js +874 -0
  42. package/dist/deploy/utils.js +31 -0
  43. package/dist/index.js +7 -0
  44. package/dist/utils/addGroupToOptions.js +11 -0
  45. package/dist/utils/buildLambdaFiles.js +99 -0
  46. package/dist/utils/cloudFormationTemplate.js +134 -0
  47. package/dist/utils/codeBuild.js +52 -0
  48. package/dist/utils/environmentVariables.js +11 -0
  49. package/dist/utils/exec.js +24 -0
  50. package/dist/utils/formatCode.js +30 -0
  51. package/dist/utils/getAwsAccountId.js +10 -0
  52. package/dist/utils/getCurrentBranch.js +35 -0
  53. package/dist/utils/getEnvironment.js +6 -0
  54. package/dist/utils/getIamPath.js +6 -0
  55. package/dist/utils/getProjectName.js +28 -0
  56. package/dist/utils/index.js +26 -0
  57. package/dist/utils/packageJson.js +46 -0
  58. package/dist/utils/readCloudFormationTemplate.js +35 -0
  59. package/dist/utils/readObjectFile.js +50 -0
  60. package/package.json +83 -0
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeTasks = exports.shConditionalCommands = void 0;
4
+ const aws_sdk_1 = require("aws-sdk");
5
+ const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
6
+ const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13' });
7
+ const compileCommands = (commands) => {
8
+ return commands.map((c) => c.replace(/;$/, '')).join(' && ');
9
+ };
10
+ const approvedStatus = 'Approved';
11
+ const rejectedStatus = 'Rejected';
12
+ const successCommands = [
13
+ `carlin cicd-ecs-task-report --status=${approvedStatus}`,
14
+ ];
15
+ const failureCommands = [
16
+ `carlin cicd-ecs-task-report --status=${rejectedStatus}`,
17
+ ];
18
+ const shConditionalCommands = ({ conditionalCommands, }) => {
19
+ const conditionalCommand = compileCommands(conditionalCommands);
20
+ const successCommand = compileCommands([
21
+ 'echo "Success Command"',
22
+ ...successCommands,
23
+ ]);
24
+ const failureCommand = compileCommands([
25
+ 'echo "Failure Command"',
26
+ ...failureCommands,
27
+ ]);
28
+ const finallyCommand = compileCommands(['echo "Finally Command"']);
29
+ return `if ${conditionalCommand}; then ${successCommand}; else ${failureCommand}; fi; ${finallyCommand}`;
30
+ };
31
+ exports.shConditionalCommands = shConditionalCommands;
32
+ const executeTasks = async ({ commands = [], cpu, memory, taskEnvironment = [], tags = [], }) => {
33
+ const command = compileCommands([
34
+ /**
35
+ * https://stackoverflow.com/questions/2853803/how-to-echo-shell-commands-as-they-are-executed/2853811
36
+ */
37
+ 'set -x',
38
+ /**
39
+ * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html
40
+ */
41
+ `export ECS_TASK_ARN=$(curl -X GET "\${ECS_CONTAINER_METADATA_URI}/task" | jq ".TaskARN")`,
42
+ ...commands,
43
+ ]);
44
+ const response = await ecs
45
+ .runTask({
46
+ taskDefinition: getProcessEnvVariable_1.getProcessEnvVariable('ECS_TASK_DEFINITION'),
47
+ cluster: getProcessEnvVariable_1.getProcessEnvVariable('ECS_CLUSTER_ARN'),
48
+ count: 1,
49
+ launchType: 'FARGATE',
50
+ networkConfiguration: {
51
+ awsvpcConfiguration: {
52
+ subnets: [
53
+ getProcessEnvVariable_1.getProcessEnvVariable('VPC_PUBLIC_SUBNET_0'),
54
+ getProcessEnvVariable_1.getProcessEnvVariable('VPC_PUBLIC_SUBNET_1'),
55
+ getProcessEnvVariable_1.getProcessEnvVariable('VPC_PUBLIC_SUBNET_2'),
56
+ ],
57
+ assignPublicIp: 'ENABLED',
58
+ securityGroups: [getProcessEnvVariable_1.getProcessEnvVariable('VPC_SECURITY_GROUP')],
59
+ },
60
+ },
61
+ overrides: {
62
+ containerOverrides: [
63
+ {
64
+ command: ['sh', '-cv', command],
65
+ name: getProcessEnvVariable_1.getProcessEnvVariable('ECS_CONTAINER_NAME'),
66
+ environment: [
67
+ {
68
+ name: 'CI',
69
+ value: 'true',
70
+ },
71
+ {
72
+ name: 'ECS_ENABLE_CONTAINER_METADATA',
73
+ value: 'true',
74
+ },
75
+ {
76
+ name: 'ECS_TASK_REPORT_HANDLER_NAME',
77
+ value: getProcessEnvVariable_1.getProcessEnvVariable('ECS_TASK_REPORT_HANDLER_NAME'),
78
+ },
79
+ ...taskEnvironment,
80
+ ],
81
+ },
82
+ ],
83
+ cpu,
84
+ memory,
85
+ },
86
+ tags,
87
+ })
88
+ .promise();
89
+ return response;
90
+ };
91
+ exports.executeTasks = executeTasks;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProcessEnvVariable = void 0;
4
+ const getProcessEnvVariable = (env) => {
5
+ if (process.env[env]) {
6
+ return process.env[env];
7
+ }
8
+ throw new Error(`process.env.${env} doesn't exist.`);
9
+ };
10
+ exports.getProcessEnvVariable = getProcessEnvVariable;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.githubWebhooksApiV1Handler = void 0;
7
+ const webhooks_1 = require("@octokit/webhooks");
8
+ const adm_zip_1 = __importDefault(require("adm-zip"));
9
+ const aws_sdk_1 = require("aws-sdk");
10
+ const getTriggerPipelineObjectKey_1 = require("../getTriggerPipelineObjectKey");
11
+ const pipelines_1 = require("../pipelines");
12
+ const executeTasks_1 = require("./executeTasks");
13
+ const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
14
+ const s3 = new aws_sdk_1.S3();
15
+ /**
16
+ * When this file is saved on S3, a CodePipeline pipeline is started.
17
+ */
18
+ const putJobDetails = async ({ pipeline, details, }) => {
19
+ const zip = new adm_zip_1.default();
20
+ const content = JSON.stringify(details);
21
+ zip.addFile(pipeline, Buffer.from(content));
22
+ return s3
23
+ .putObject({
24
+ Body: zip.toBuffer(),
25
+ Bucket: getProcessEnvVariable_1.getProcessEnvVariable('BASE_STACK_BUCKET_NAME'),
26
+ Key: getTriggerPipelineObjectKey_1.getTriggerPipelinesObjectKey(pipeline),
27
+ })
28
+ .promise();
29
+ };
30
+ const githubWebhooksApiV1Handler = async (event, context) => {
31
+ try {
32
+ /**
33
+ * Ends function immediately after callback.
34
+ */
35
+ context.callbackWaitsForEmptyEventLoop = false;
36
+ const { body, headers } = event;
37
+ if (!body) {
38
+ throw new Error("event.body doesn't exist.");
39
+ }
40
+ const xGitHubDelivery = headers['X-GitHub-Delivery'];
41
+ const xGitHubEvent = headers['X-GitHub-Event'];
42
+ const xHubSignature = headers['X-Hub-Signature-256'] || headers['X-Hub-Signature'];
43
+ if (!xGitHubDelivery) {
44
+ throw new Error("X-GitHub-Delivery doesn't exist.");
45
+ }
46
+ if (!xGitHubEvent) {
47
+ throw new Error("X-GitHub-Event doesn't exist.");
48
+ }
49
+ if (!xHubSignature) {
50
+ throw new Error("X-Hub-Signature-256 or X-Hub-Signature doesn't exist.");
51
+ }
52
+ const webhooks = new webhooks_1.Webhooks({ secret: '123' });
53
+ const pipelines = JSON.parse(process.env.PIPELINES_JSON || JSON.stringify([]));
54
+ if (pipelines.includes('pr')) {
55
+ webhooks.on([
56
+ 'pull_request.opened',
57
+ 'pull_request.reopened',
58
+ 'pull_request.ready_for_review',
59
+ 'pull_request.synchronize',
60
+ ], async ({ payload }) => {
61
+ if (payload.pull_request.draft) {
62
+ return;
63
+ }
64
+ await executeTasks_1.executeTasks({
65
+ commands: [
66
+ executeTasks_1.shConditionalCommands({
67
+ conditionalCommands: pipelines_1.getPrCommands({
68
+ branch: payload.pull_request.head.ref,
69
+ }),
70
+ }),
71
+ ],
72
+ tags: [
73
+ { key: 'Pipeline', value: 'pr' },
74
+ { key: 'PullRequest', value: payload.number.toString() },
75
+ { key: 'PullRequestTitle', value: payload.pull_request.title },
76
+ { key: 'PullRequestUrl', value: payload.pull_request.url },
77
+ { key: 'Action', value: payload.action },
78
+ { key: 'Branch', value: payload.pull_request.head.ref },
79
+ ],
80
+ });
81
+ });
82
+ webhooks.on(['pull_request.closed'], async ({ payload }) => {
83
+ /**
84
+ * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
85
+ */
86
+ await executeTasks_1.executeTasks({
87
+ cpu: '256',
88
+ memory: '512',
89
+ commands: [
90
+ executeTasks_1.shConditionalCommands({
91
+ conditionalCommands: pipelines_1.getClosedPrCommands({
92
+ branch: payload.pull_request.head.ref,
93
+ }),
94
+ }),
95
+ ],
96
+ tags: [
97
+ { key: 'Pipeline', value: 'pr' },
98
+ { key: 'PullRequest', value: payload.number.toString() },
99
+ { key: 'PullRequestTitle', value: payload.pull_request.title },
100
+ { key: 'PullRequestUrl', value: payload.pull_request.url },
101
+ { key: 'Action', value: payload.action },
102
+ { key: 'Branch', value: payload.pull_request.head.ref },
103
+ ],
104
+ });
105
+ });
106
+ }
107
+ if (pipelines.includes('main')) {
108
+ webhooks.on('push', async (details) => {
109
+ if (details.payload.ref === 'refs/heads/main') {
110
+ await putJobDetails({ pipeline: 'main', details });
111
+ }
112
+ });
113
+ }
114
+ if (pipelines.includes('tag')) {
115
+ webhooks.on('push', async (details) => {
116
+ if (details.payload.ref.startsWith('refs/tags/')) {
117
+ await putJobDetails({ pipeline: 'tag', details });
118
+ }
119
+ });
120
+ }
121
+ webhooks.onError((onErrorEvent) => {
122
+ console.error('Webhooks on error.');
123
+ console.error(JSON.stringify(onErrorEvent, null, 2));
124
+ throw onErrorEvent;
125
+ });
126
+ /**
127
+ * Replace "receive" for "verifyAndReceive" when WebCrypto exist on Node.js
128
+ * API.
129
+ */
130
+ await webhooks.receive({
131
+ id: xGitHubDelivery,
132
+ name: xGitHubEvent,
133
+ // signature: xHubSignature,
134
+ payload: JSON.parse(body),
135
+ });
136
+ return { statusCode: 200, body: JSON.stringify({ ok: true }) };
137
+ }
138
+ catch (error) {
139
+ console.error(error);
140
+ return { statusCode: error.status || 500, body: error.message };
141
+ }
142
+ };
143
+ exports.githubWebhooksApiV1Handler = githubWebhooksApiV1Handler;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipelinesHandler = exports.githubWebhooksApiV1Handler = exports.ecsTaskReportHandler = exports.cicdApiV1Handler = void 0;
4
+ var cicdApiV1_handler_1 = require("./cicdApiV1.handler");
5
+ Object.defineProperty(exports, "cicdApiV1Handler", { enumerable: true, get: function () { return cicdApiV1_handler_1.cicdApiV1Handler; } });
6
+ var ecsTaskReport_handler_1 = require("./ecsTaskReport.handler");
7
+ Object.defineProperty(exports, "ecsTaskReportHandler", { enumerable: true, get: function () { return ecsTaskReport_handler_1.ecsTaskReportHandler; } });
8
+ var githubWebhooksApiV1_handler_1 = require("./githubWebhooksApiV1.handler");
9
+ Object.defineProperty(exports, "githubWebhooksApiV1Handler", { enumerable: true, get: function () { return githubWebhooksApiV1_handler_1.githubWebhooksApiV1Handler; } });
10
+ var pipelines_handler_1 = require("./pipelines.handler");
11
+ Object.defineProperty(exports, "pipelinesHandler", { enumerable: true, get: function () { return pipelines_handler_1.pipelinesHandler; } });
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.pipelinesHandler = exports.getJobDetails = exports.getJobDetailsFilename = void 0;
26
+ const adm_zip_1 = __importDefault(require("adm-zip"));
27
+ const aws_sdk_1 = require("aws-sdk");
28
+ const fs = __importStar(require("fs"));
29
+ const pipelines_1 = require("../pipelines");
30
+ const executeTasks_1 = require("./executeTasks");
31
+ const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
32
+ const codepipeline = new aws_sdk_1.CodePipeline();
33
+ const getUserParameters = (event) => {
34
+ const [pipeline, stage] = event['CodePipeline.job'].data.actionConfiguration.configuration.UserParameters.split('&');
35
+ return { pipeline: pipeline, stage };
36
+ };
37
+ const getJobDetailsFilename = (jobId) => `/tmp/${jobId}.zip`;
38
+ exports.getJobDetailsFilename = getJobDetailsFilename;
39
+ const getJobDetails = async (event) => {
40
+ const jobId = event['CodePipeline.job'].id;
41
+ const s3 = new aws_sdk_1.S3({
42
+ credentials: event['CodePipeline.job'].data.artifactCredentials,
43
+ });
44
+ const { bucketName, objectKey } = event['CodePipeline.job'].data.inputArtifacts[0].location.s3Location;
45
+ const { Body } = await s3
46
+ .getObject({ Bucket: bucketName, Key: objectKey })
47
+ .promise();
48
+ if (!Body) {
49
+ throw new Error('Cannot retrieve the job description (there is no input artifact).');
50
+ }
51
+ const filename = exports.getJobDetailsFilename(jobId);
52
+ await fs.promises.writeFile(filename, Body, {});
53
+ const zip = new adm_zip_1.default(filename);
54
+ const file = zip.readAsText(getUserParameters(event).pipeline);
55
+ try {
56
+ return JSON.parse(file);
57
+ }
58
+ catch (_a) {
59
+ throw new Error(`Job details is not a valid json. ${file}`);
60
+ }
61
+ };
62
+ exports.getJobDetails = getJobDetails;
63
+ const pipelinesHandler = async (event) => {
64
+ var _a, _b;
65
+ const jobId = event['CodePipeline.job'].id;
66
+ let pipelineName;
67
+ try {
68
+ const { pipeline } = getUserParameters(event);
69
+ const gitHubJobDetails = await exports.getJobDetails(event);
70
+ const { jobDetails } = await codepipeline
71
+ .getJobDetails({ jobId })
72
+ .promise();
73
+ pipelineName = (_b = (_a = jobDetails === null || jobDetails === void 0 ? void 0 : jobDetails.data) === null || _a === void 0 ? void 0 : _a.pipelineContext) === null || _b === void 0 ? void 0 : _b.pipelineName;
74
+ const executeTasksInput = (() => {
75
+ const tags = [
76
+ {
77
+ key: 'Pipeline',
78
+ value: pipeline,
79
+ },
80
+ {
81
+ key: 'AfterCommit',
82
+ value: gitHubJobDetails.payload.after,
83
+ },
84
+ ];
85
+ const taskEnvironment = [];
86
+ if (pipelineName) {
87
+ tags.push({
88
+ key: 'PipelineName',
89
+ value: pipelineName,
90
+ });
91
+ taskEnvironment.push({
92
+ name: 'PIPELINE_NAME',
93
+ value: pipelineName,
94
+ });
95
+ }
96
+ if (pipeline === 'main') {
97
+ return {
98
+ commands: [
99
+ executeTasks_1.shConditionalCommands({
100
+ conditionalCommands: pipelines_1.getMainCommands(),
101
+ }),
102
+ ],
103
+ tags,
104
+ taskEnvironment,
105
+ };
106
+ }
107
+ if (pipeline === 'tag') {
108
+ const tag = gitHubJobDetails.payload.ref.split('/')[2];
109
+ return {
110
+ commands: [
111
+ executeTasks_1.shConditionalCommands({
112
+ conditionalCommands: pipelines_1.getTagCommands({ tag }),
113
+ }),
114
+ ],
115
+ tags: [
116
+ ...tags,
117
+ {
118
+ key: 'Tag',
119
+ value: tag,
120
+ },
121
+ ],
122
+ taskEnvironment,
123
+ };
124
+ }
125
+ return undefined;
126
+ })();
127
+ if (!executeTasksInput) {
128
+ throw new Error('executeTasksInputUndefined');
129
+ }
130
+ await executeTasks_1.executeTasks(executeTasksInput);
131
+ await codepipeline.putJobSuccessResult({ jobId }).promise();
132
+ }
133
+ catch (error) {
134
+ if (pipelineName) {
135
+ await putApprovalResultManualTask_1.putApprovalResultManualTask({
136
+ pipelineName,
137
+ /**
138
+ * https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_ApprovalResult.html
139
+ */
140
+ result: { status: 'Rejected', summary: error.message.slice(0, 511) },
141
+ });
142
+ }
143
+ await codepipeline
144
+ .putJobFailureResult({
145
+ jobId,
146
+ failureDetails: {
147
+ type: 'JobFailed',
148
+ message: error.message.slice(0, 4999),
149
+ },
150
+ })
151
+ .promise();
152
+ }
153
+ };
154
+ exports.pipelinesHandler = pipelinesHandler;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.putApprovalResultManualTask = void 0;
4
+ const aws_sdk_1 = require("aws-sdk");
5
+ const config_1 = require("../config");
6
+ const codepipeline = new aws_sdk_1.CodePipeline();
7
+ const FIVE_SECONDS = 5 * 1000;
8
+ const getApprovalActionToken = ({ actionName, stageName, pipelineName, }) => new Promise((resolve, reject) => {
9
+ setTimeout(() => {
10
+ codepipeline.getPipelineState({ name: pipelineName }, async (err, { stageStates = [] }) => {
11
+ var _a;
12
+ if (err) {
13
+ return reject(err);
14
+ }
15
+ const approvalStageState = stageStates.find((s) => s.stageName === stageName);
16
+ if (!approvalStageState) {
17
+ throw new Error('ApprovalStageStateIsUndefined');
18
+ }
19
+ const approvalActionState = (_a = approvalStageState.actionStates) === null || _a === void 0 ? void 0 : _a.find((a) => a.actionName === actionName);
20
+ if (!approvalActionState) {
21
+ throw new Error('ApprovalActionStateIsUndefined');
22
+ }
23
+ const { latestExecution } = approvalActionState;
24
+ if (latestExecution && latestExecution.status === 'InProgress') {
25
+ return resolve(latestExecution.token);
26
+ }
27
+ try {
28
+ return resolve(await getApprovalActionToken({
29
+ actionName,
30
+ stageName,
31
+ pipelineName,
32
+ }));
33
+ }
34
+ catch (error) {
35
+ return reject(error);
36
+ }
37
+ });
38
+ }, FIVE_SECONDS);
39
+ });
40
+ const putApprovalResultManualTask = async ({ pipelineName, result, }) => {
41
+ const actionName = config_1.PIPELINE_ECS_TASK_EXECUTION_MANUAL_APPROVAL_ACTION_NAME;
42
+ const stageName = config_1.PIPELINE_ECS_TASK_EXECUTION_STAGE_NAME;
43
+ const token = await getApprovalActionToken({
44
+ actionName,
45
+ stageName,
46
+ pipelineName,
47
+ });
48
+ await codepipeline
49
+ .putApprovalResult({ pipelineName, stageName, actionName, result, token })
50
+ .promise();
51
+ };
52
+ exports.putApprovalResultManualTask = putApprovalResultManualTask;