Skip to content
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

Merged
merged 18 commits into from
Sep 1, 2020

Conversation

luckily
Copy link
Contributor

@luckily luckily commented Aug 14, 2020

I am ready for the first run.

Support L2 construct for SlackChannelConfiguration of chatbot.

  1. add L2 construct
  2. add unit tests
  3. add integration test
  4. update package.json

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

1. add L2 construct
2. add unit tests
3. add integration test
4. update package.json
@mergify
Copy link
Contributor

mergify bot commented Aug 14, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@luckily luckily changed the title feat: Support L2 construct for SlackChannelConfiguration of chatbot. feat(aws-chatbot): Support L2 construct for SlackChannelConfiguration of chatbot. Aug 14, 2020
Copy link
Contributor

@skinny85 skinny85 left a 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

/**
* Represents a Slack channel configuration
*/
export interface ISlackChannelConfiguration extends cdk.IResource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say, I don't love the name SlackChannelConfiguration. Yes, I understand that the L1 is called like that, but I feel like we can do better.

How does everyone feel about SlackIntegration? @luckily @humanzz @Stacy-D ?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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?

@mergify mergify bot dismissed skinny85’s stale review August 15, 2020 14:51

Pull request has been modified.

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 = (() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinny85 how about it?

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.
@luckily
Copy link
Contributor Author

luckily commented Aug 18, 2020

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, SlackIntegration is also great, but probably SlackIntegration is more suitable for L3 construct or patterns.

It decided by aws-cdk team.

skinny85
skinny85 previously approved these changes Aug 19, 2020
Copy link
Contributor

@skinny85 skinny85 left a 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!

@mergify
Copy link
Contributor

mergify bot commented Aug 19, 2020

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).

@skinny85
Copy link
Contributor

@luckily I think some additional linter rules were added that made the build fail. Can you update from origin/master, and fix the problems?

@mergify mergify bot dismissed skinny85’s stale review August 20, 2020 04:50

Pull request has been modified.

@luckily
Copy link
Contributor Author

luckily commented Aug 20, 2020

@skinny85 The problem already fixed.

Copy link
Contributor

@bryan-hunter bryan-hunter left a 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 = (() => {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@skinny85 skinny85 Sep 1, 2020

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);
     }

Copy link
Contributor

@skinny85 skinny85 Sep 1, 2020

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jogold @skinny85
I adjusted.

Copy link
Contributor

@skinny85 skinny85 left a 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 !

@mergify
Copy link
Contributor

mergify bot commented Sep 1, 2020

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).

@mergify
Copy link
Contributor

mergify bot commented Sep 1, 2020

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: d2cac48
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 05f5e62 into aws:master Sep 1, 2020
shivlaks added a commit that referenced this pull request Oct 15, 2020
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.
mergify bot pushed a commit that referenced this pull request Oct 15, 2020
…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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-chatbot] L2 support for SlackChannelConfiguration
8 participants