Skip to content

Commit

Permalink
feat(aws-codepipeline): support notifications on the ManualApprovalAc…
Browse files Browse the repository at this point in the history
…tion.

Fixes aws#1222
  • Loading branch information
skinny85 committed Dec 15, 2018
1 parent d20938c commit 6f96888
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 36 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
import actions = require('@aws-cdk/aws-codepipeline-api');
import sns = require('@aws-cdk/aws-sns');
import cdk = require('@aws-cdk/cdk');

// tslint:disable-next-line:no-empty-interface
export interface ManualApprovalActionProps extends actions.CommonActionProps,
actions.CommonActionConstructProps {
/**
* Optional SNS topic to send notifications to when an approval is pending.
*/
notificationTopic?: sns.TopicRef;

/**
* A list of email addresses to subscribe to notifications when this Action is pending approval.
* If this has been provided, then you must also provide the `notificationTopic` property.
*/
notifyEmails?: string[];

/**
* Any additional information that you want to include in the email message.
*/
additionalInformation?: string;
}

/**
* Manual approval action.
*/
export class ManualApprovalAction extends actions.Action {
public readonly notificationTopic?: sns.TopicRef;

constructor(parent: cdk.Construct, name: string, props: ManualApprovalActionProps) {
super(parent, name, {
category: actions.ActionCategory.Approval,
provider: 'Manual',
artifactBounds: { minInputs: 0, maxInputs: 0, minOutputs: 0, maxOutputs: 0 },
configuration: actionConfiguration(props),
...props,
});

this.notificationTopic = props.notificationTopic;
if (this.notificationTopic && (props.notifyEmails || []).length > 0) {
this.notificationTopic.grantPublish(props.stage.pipeline.role);
for (const notifyEmail of props.notifyEmails || []) {
this.notificationTopic.subscribeEmail(`Subscription-${notifyEmail}`, notifyEmail);
}
}
}
}

function actionConfiguration(props: ManualApprovalActionProps): any {
return props.notificationTopic
? {
NotificationArn: props.notificationTopic.topicArn,
CustomData: props.additionalInformation,
}
: undefined;
}
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"@aws-cdk/aws-codedeploy": "^0.20.0",
"@aws-cdk/aws-ecr": "^0.20.0",
"@aws-cdk/aws-lambda": "^0.20.0",
"@aws-cdk/aws-sns": "^0.20.0",
"cdk-build-tools": "^0.20.0",
"cdk-integ-tools": "^0.20.0",
"cfn2ts": "^0.20.0",
Expand All @@ -76,6 +75,7 @@
"@aws-cdk/aws-events": "^0.20.0",
"@aws-cdk/aws-iam": "^0.20.0",
"@aws-cdk/aws-s3": "^0.20.0",
"@aws-cdk/aws-sns": "^0.20.0",
"@aws-cdk/cdk": "^0.20.0"
},
"homepage": "https://github.com/awslabs/aws-cdk",
Expand All @@ -84,6 +84,7 @@
"@aws-cdk/aws-events": "^0.20.0",
"@aws-cdk/aws-iam": "^0.20.0",
"@aws-cdk/aws-s3": "^0.20.0",
"@aws-cdk/aws-sns": "^0.20.0",
"@aws-cdk/cdk": "^0.20.0"
},
"engines": {
Expand Down

0 comments on commit 6f96888

Please sign in to comment.