/
manual-approval-action.ts
80 lines (70 loc) · 2.46 KB
/
manual-approval-action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as sns from '@aws-cdk/aws-sns';
import * as subs from '@aws-cdk/aws-sns-subscriptions';
import * as cdk from '@aws-cdk/core';
import { Action } from './action';
/**
* Construction properties of the {@link ManualApprovalAction}.
*/
export interface ManualApprovalActionProps extends codepipeline.CommonAwsActionProps {
/**
* Optional SNS topic to send notifications to when an approval is pending.
*/
readonly notificationTopic?: sns.ITopic;
/**
* A list of email addresses to subscribe to notifications when this Action is pending approval.
* If this has been provided, but not `notificationTopic`,
* a new Topic will be created.
*/
readonly notifyEmails?: string[];
/**
* Any additional information that you want to include in the notification email message.
*/
readonly additionalInformation?: string;
}
/**
* Manual approval action.
*/
export class ManualApprovalAction extends Action {
/**
* The SNS Topic passed when constructing the Action.
* If no Topic was passed, but `notifyEmails` were provided,
* a new Topic will be created.
*/
private _notificationTopic?: sns.ITopic;
private readonly props: ManualApprovalActionProps;
constructor(props: ManualApprovalActionProps) {
super({
...props,
category: codepipeline.ActionCategory.APPROVAL,
provider: 'Manual',
artifactBounds: { minInputs: 0, maxInputs: 0, minOutputs: 0, maxOutputs: 0 },
});
this.props = props;
}
public get notificationTopic(): sns.ITopic | undefined {
return this._notificationTopic;
}
protected bound(scope: cdk.Construct, _stage: codepipeline.IStage, options: codepipeline.ActionBindOptions):
codepipeline.ActionConfig {
if (this.props.notificationTopic) {
this._notificationTopic = this.props.notificationTopic;
} else if ((this.props.notifyEmails || []).length > 0) {
this._notificationTopic = new sns.Topic(scope, 'TopicResource');
}
if (this._notificationTopic) {
this._notificationTopic.grantPublish(options.role);
for (const notifyEmail of this.props.notifyEmails || []) {
this._notificationTopic.addSubscription(new subs.EmailSubscription(notifyEmail));
}
}
return {
configuration: this._notificationTopic
? {
NotificationArn: this._notificationTopic.topicArn,
CustomData: this.props.additionalInformation,
}
: undefined,
};
}
}