forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-codepipeline): support notifications on the ManualApprovalAc…
…tion. Fixes aws#1222
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
37 changes: 36 additions & 1 deletion
37
packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters