Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a1bf823

Browse files
badmintoncryermazyu36
authored andcommittedJun 22, 2024
feat(chatbot): configure userRoleRequired for the SlackChannelConfiguration (aws#30420)
### Issue # (if applicable) Closes aws#30403. ### Reason for this change `chatbot.SlackChannelConfiguration` does not support for configuring `userRoleRequired` prop. ### Description of changes Add `userRoleRequired` to `SlackChannelConfigurationProps` ### Description of how you validated changes Add both unit and integ tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9a47ad5 commit a1bf823

12 files changed

+507
-0
lines changed
 

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/ChatbotInteg.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"Resources": {
3+
"MySlackChannelConfigurationRole1D3F23AE": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "chatbot.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
}
18+
}
19+
},
20+
"MySlackChannelA8E0B56C": {
21+
"Type": "AWS::Chatbot::SlackChannelConfiguration",
22+
"Properties": {
23+
"ConfigurationName": "test-channel",
24+
"IamRoleArn": {
25+
"Fn::GetAtt": [
26+
"MySlackChannelConfigurationRole1D3F23AE",
27+
"Arn"
28+
]
29+
},
30+
"SlackChannelId": "C07639U21PW",
31+
"SlackWorkspaceId": "T075XU2GKBP",
32+
"UserRoleRequired": true
33+
}
34+
}
35+
},
36+
"Parameters": {
37+
"BootstrapVersion": {
38+
"Type": "AWS::SSM::Parameter::Value<String>",
39+
"Default": "/cdk-bootstrap/hnb659fds/version",
40+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
41+
}
42+
},
43+
"Rules": {
44+
"CheckBootstrapVersion": {
45+
"Assertions": [
46+
{
47+
"Assert": {
48+
"Fn::Not": [
49+
{
50+
"Fn::Contains": [
51+
[
52+
"1",
53+
"2",
54+
"3",
55+
"4",
56+
"5"
57+
],
58+
{
59+
"Ref": "BootstrapVersion"
60+
}
61+
]
62+
}
63+
]
64+
},
65+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
66+
}
67+
]
68+
}
69+
}
70+
}

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/integchatbotuserrolerequiredDefaultTestDeployAssert995C2DD6.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/integchatbotuserrolerequiredDefaultTestDeployAssert995C2DD6.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-chatbot/test/integ.chatbot-user-role-required.js.snapshot/manifest.json

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as chatbot from 'aws-cdk-lib/aws-chatbot';
3+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
4+
5+
const app = new cdk.App();
6+
const testStack = new cdk.Stack(app, 'ChatbotInteg');
7+
new chatbot.SlackChannelConfiguration(testStack, 'MySlackChannel', {
8+
slackChannelConfigurationName: 'test-channel',
9+
slackWorkspaceId: 'T075XU2GKBP',
10+
slackChannelId: 'C07639U21PW',
11+
userRoleRequired: true,
12+
});
13+
14+
new IntegTest(app, 'integ-chatbot-user-role-required', {
15+
testCases: [testStack],
16+
});

‎packages/aws-cdk-lib/aws-chatbot/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,20 @@ correct log retention period (never expire, by default).
4747

4848
By default slack channel will use `AdministratorAccess` managed policy as guardrail policy.
4949
The `guardrailPolicies` property can be used to set a different set of managed policies.
50+
51+
## User Role Requirement
52+
53+
Administrators can [require user roles](https://docs.aws.amazon.com/chatbot/latest/adminguide/understanding-permissions.html#user-role-requirement) for all current channel members and channels and all channels created in the future by enabling a user role requirement.
54+
55+
You can configure this feature by setting the `userRoleRequired` property.
56+
57+
```ts
58+
import * as chatbot from 'aws-cdk-lib/aws-chatbot';
59+
60+
const slackChannel = new chatbot.SlackChannelConfiguration(this, 'MySlackChannel', {
61+
slackChannelConfigurationName: 'YOUR_CHANNEL_NAME',
62+
slackWorkspaceId: 'YOUR_SLACK_WORKSPACE_ID',
63+
slackChannelId: 'YOUR_SLACK_CHANNEL_ID',
64+
userRoleRequired: true,
65+
});
66+
```

‎packages/aws-cdk-lib/aws-chatbot/lib/slack-channel-configuration.ts

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export interface SlackChannelConfigurationProps {
8787
* @default - The AWS managed 'AdministratorAccess' policy is applied as a default if this is not set.
8888
*/
8989
readonly guardrailPolicies?: iam.IManagedPolicy[];
90+
91+
/**
92+
* Enables use of a user role requirement in your chat configuration.
93+
*
94+
* @default false
95+
*/
96+
readonly userRoleRequired?: boolean;
9097
}
9198

9299
/**
@@ -300,6 +307,7 @@ export class SlackChannelConfiguration extends SlackChannelConfigurationBase {
300307
snsTopicArns: cdk.Lazy.list({ produce: () => this.notificationTopics.map(topic => topic.topicArn) }, { omitEmpty: true } ),
301308
loggingLevel: props.loggingLevel?.toString(),
302309
guardrailPolicies: cdk.Lazy.list({ produce: () => props.guardrailPolicies?.map(policy => policy.managedPolicyArn) }, { omitEmpty: true } ),
310+
userRoleRequired: props.userRoleRequired,
303311
});
304312

305313
// Log retention

‎packages/aws-cdk-lib/aws-chatbot/test/slack-channel-configuration.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ describe('SlackChannelConfiguration', () => {
175175
});
176176
});
177177

178+
test('specifying user role required', () => {
179+
new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', {
180+
slackWorkspaceId: 'ABC123',
181+
slackChannelId: 'DEF456',
182+
slackChannelConfigurationName: 'ConfigurationName',
183+
userRoleRequired: true,
184+
});
185+
186+
Template.fromStack(stack).hasResourceProperties('AWS::Chatbot::SlackChannelConfiguration', {
187+
UserRoleRequired: true,
188+
});
189+
});
190+
178191
test('getting configuration metric', () => {
179192
const slackChannel = new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', {
180193
slackWorkspaceId: 'ABC123',

0 commit comments

Comments
 (0)
Please sign in to comment.