|
1 | 1 | import {Construct} from "constructs" |
2 | 2 | import {LambdaFunction} from "../constructs/LambdaFunction" |
3 | | -import {ManagedPolicy} from "aws-cdk-lib/aws-iam" |
| 3 | +import {ManagedPolicy, PolicyStatement, Role} from "aws-cdk-lib/aws-iam" |
4 | 4 | import {StringParameter} from "aws-cdk-lib/aws-ssm" |
5 | 5 | import {Secret} from "aws-cdk-lib/aws-secretsmanager" |
6 | 6 | import {TableV2} from "aws-cdk-lib/aws-dynamodb" |
@@ -35,6 +35,8 @@ export interface FunctionsProps { |
35 | 35 | readonly slackBotSigningSecret: Secret |
36 | 36 | readonly slackBotStateTable: TableV2 |
37 | 37 | readonly promptName: string |
| 38 | + readonly isPullRequest: boolean |
| 39 | + readonly mainSlackBotLambdaExecutionRoleArn : string |
38 | 40 | } |
39 | 41 |
|
40 | 42 | export class Functions extends Construct { |
@@ -74,6 +76,30 @@ export class Functions extends Construct { |
74 | 76 | props.slackBotTokenSecret.grantRead(slackBotLambda.function) |
75 | 77 | props.slackBotSigningSecret.grantRead(slackBotLambda.function) |
76 | 78 |
|
| 79 | + if (props.isPullRequest) { |
| 80 | + const mainSlackBotLambdaExecutionRole = Role.fromRoleArn( |
| 81 | + this, |
| 82 | + "mainRoleArn", |
| 83 | + props.mainSlackBotLambdaExecutionRoleArn, { |
| 84 | + mutable: true |
| 85 | + }) |
| 86 | + |
| 87 | + const executeSlackBotPolicy = new ManagedPolicy(this, "ExecuteSlackBotPolicy", { |
| 88 | + description: "foo", |
| 89 | + statements: [ |
| 90 | + new PolicyStatement({ |
| 91 | + actions: [ |
| 92 | + "lambda:invokeFunction" |
| 93 | + ], |
| 94 | + resources: [ |
| 95 | + slackBotLambda.function.functionArn |
| 96 | + ] |
| 97 | + }) |
| 98 | + ] |
| 99 | + }) |
| 100 | + mainSlackBotLambdaExecutionRole.addManagedPolicy(executeSlackBotPolicy) |
| 101 | + } |
| 102 | + |
77 | 103 | // Lambda function to sync knowledge base on S3 events |
78 | 104 | const syncKnowledgeBaseFunction = new LambdaFunction(this, "SyncKnowledgeBaseFunction", { |
79 | 105 | stackName: props.stackName, |
|
0 commit comments