-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(aws-chatbot): Support L2 construct for SlackChannelConfiguration of chatbot. #9702
Conversation
1. add L2 construct 2. add unit tests 3. add integration test 4. update package.json
Title does not follow the guidelines of Conventional Commits. Please adjust title before merge. |
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome @luckily , thanks so much for the contribution!
I have some comments, mainly around simplifying and removing some things from this PR, but in general looks great!
Thanks,
Adam
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
/** | ||
* Represents a Slack channel configuration | ||
*/ | ||
export interface ISlackChannelConfiguration extends cdk.IResource { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, the shorter is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter is nicer... but wouldn't that break consistency in naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter is nicer... but wouldn't that break consistency in naming?
Do you mean consistency with CloudFormation?
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-chatbot/test/slack-channel-configuration.test.ts
Outdated
Show resolved
Hide resolved
1. change default `loggingLevel` from `LoggingLevel.NONE` to `undefined`. 2. extract `new cdk.Stack()` to a `beforeEach()`. 3. change from `toMatch` to `haveResourceLike` for unit test asserting method. 4. add a test case to increase code coverage.
1. remove all prefix of @aws-cdk/assert 2. test case `import` move to import-slack-channel-configuration.test
1. rename configurationName to slackChannelConfigurationName for keep it consistent with slackChannelConfigurationArn. 2. adjust method chain for better way. 3. use `props.notificationTopics?.map(topic => topic.topicArn)` is better. 4. add a test case.
* The ArnComponents API will return `slack-channel/my-slack` | ||
* So i need to handle that to gets a correct name.`my-slack` | ||
*/ | ||
readonly slackChannelConfigurationName = (() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skinny85 how about it?
packages/@aws-cdk/aws-chatbot/lib/slack-channel-configuration.ts
Outdated
Show resolved
Hide resolved
1. change addToPrincipalPolicy of method name to addToRolePolicy for consistency 2. addXPermissions() change to use this.addToRolePolicy() for avoiding throw error. 3. ISlackChannelConfiguration extend iam.IGrantable and implementing. 4. add test case for addXPermissions() methods of imported slack channel configuration.
Hi @skinny85, @humanzz and @Stacy-D Thanks for your feedbacks. I already resolved some problems by your feedbacks, but we still have issue about the naming, my opinion is consistency is important in large project, It decided by aws-cdk team. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This is a great start for this module @luckily . Thanks for the contribution!
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
@luckily I think some additional linter rules were added that made the build fail. Can you update from |
@skinny85 The problem already fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
* The ArnComponents API will return `slack-channel/my-slack` | ||
* So i need to handle that to gets a correct name.`my-slack` | ||
*/ | ||
readonly slackChannelConfigurationName = (() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readonly get slackChannelConfigurationName()
instead of an IIFE here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jogold
This way will not throw error when fromSlackChannelConfigurationArn static method called.
Would you want to throw error in slackChannelConfigurationName(assessor getter) of SlackChannelConfiguration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure @jogold meant this:
public get slackChannelConfigurationName(): string {
const re = /^slack-channel\//;
const resourceName = cdk.Stack.of(scope).parseArn(slackChannelConfigurationArn).resourceName as string;
if (!re.test(resourceName)) {
throw new Error('The ARN of a Slack integration must be in the form: arn:aws:chatbot:accountId:chat-configuration/slack-channel/slackChannelName');
}
return resourceName.substring('slack-channel/'.length);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, something like this:
public static fromSlackChannelConfigurationArn(scope: cdk.Construct, id: string, slackChannelConfigurationArn: string): ISlackChannelConfiguration {
const resourceName = cdk.Stack.of(scope).parseArn(slackChannelConfigurationArn).resourceName as string;
if (!resourceName) {
throw new Error('The ARN of a Slack integration must be in the form: arn:aws:chatbot:accountId:chat-configuration/slack-channel/slackChannelName');
}
class Import extends SlackChannelConfigurationBase {
readonly slackChannelConfigurationArn = slackChannelConfigurationArn;
readonly role?: iam.IRole = undefined;
readonly grantPrincipal: iam.IPrincipal;
/*
* For example: arn:aws:chatbot::1234567890:chat-configuration/slack-channel/my-slack
* The ArnComponents API will return `slack-channel/my-slack`
* So i need to handle that to gets a correct name.`my-slack`
*/
readonly slackChannelConfigurationName = resourceName.substring('slack-channel/'.length);;
// ...
}
return new Import(scope, id);
}
would be even better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. adjust error description. 2. remove the IIFE way.
Merge branch 'master' into feat/aws-chatbot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the great contribution @luckily !
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
L2 constructs were introduced last month in #9702 for slack channel configuration. marking the module as experimental to reflect that the module is no longer cfn-only.
…n-only (#10880) L2 constructs were introduced last month in #9702 for slack channel configuration. marking the module as experimental to reflect that the module is no longer cfn-only. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
I am ready for the first run.
Support L2 construct for SlackChannelConfiguration of chatbot.
Resolves: #9679
cc @skinny85
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license