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

fix(core): tags not working for cognito user pools #4225

Merged
merged 24 commits into from
Jan 3, 2020

Conversation

moofish32
Copy link
Contributor

@moofish32 moofish32 commented Sep 24, 2019

Cognito user pool tags do not use the property name Tags. In order to support properties without the name Tags the code needs to support arbitrary names for the tags field. I moved all references to Tags into the schema package such that codegen does not share any of the knowledge about special names for tag fields.

  • moved all knowledge about tag names into the schema package and
    included UserPoolTags as taggable name
  • refactored codegen to use new schema package to identify tag
    properties
  • TagManager now supports additional optional TagManagerOptions to control the naming of the tag property field and enable future extensions without breaking changes

Fixes #3882


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

 * moved all knowledge about tag names into the schema package and
 included UserPoolTags as taggable name
 * refactored codegen to use new schema package to identify tag
 properties

BREAKING CHANGE:
 * TagManager constructor now takes a property object instead of
 individual agruments: new TagManager(props: TagManagerProps) instead of new cdk.TagManager(cdk.TagType.STANDARD, resourceType, initialTags);

Fixes aws#3882
@mergify
Copy link
Contributor

mergify bot commented Sep 24, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

UserPoolTags: "",
};

export type TagPropertyName = keyof typeof tagPropertyNames;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there are reasons I can't do this, but it was the cleanest way to check a literal type. I suppose I could go enum?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is JSII complaining about this?

export type TagPropertyName = 'Tags' | 'UserPoolTags';

If that's the case, I can see a slightly cleaner way that doesn't require instantiating an "unused" const:

interface TagProperty {
  Tags: never;
  UserPoolTags: never;
}

export type TagPropertyName = keyof TagProperty;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jsii didn't complain locally -- figured the full suite would tell me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant complaining about my first snippet:

export type TagPropertyName = 'Tags' | 'UserPoolTags';

Sorry if I wasn't clear. And if you don't get errors building the cognito package, you should be good. 👍

@moofish32 moofish32 changed the title fix(core): Support tags for Cognito User Pools fix(core): support tags for cognito user pools Sep 24, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@moofish32
Copy link
Contributor Author

is my fail just the breaking change? If so I can revert to avoid the break to one of the options identified above.

err  - INITIALIZER @aws-cdk/core.TagManager.<initializer>: argument tagType, takes @aws-cdk/core.TagManagerProps (formerly @aws-cdk/core.TagType): @aws-cdk/core.TagType is an enum different from @aws-cdk/core.TagManagerProps [incompatible-argument:@aws-cdk/core.TagManager.<initializer>]
err  - INITIALIZER @aws-cdk/core.TagManager.<initializer>: argument resourceTypeName, not accepted anymore. [removed-argument:@aws-cdk/core.TagManager.<initializer>]
err  - INITIALIZER @aws-cdk/core.TagManager.<initializer>: argument tagStructure, not accepted anymore. [removed-argument:@aws-cdk/core.TagManager.<initializer>]
@aws-cdk/custom-resources... OK.
@aws-cdk/cx-api... OK.
@aws-cdk/region-info... OK.
Some packages seem to have undergone breaking API changes. Please avoid.```

@nmussy
Copy link
Contributor

nmussy commented Sep 24, 2019 via email

eladb
eladb previously requested changes Sep 25, 2019
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

In the PR description please include information on what was the issue and the root cause that motivated this change

packages/@aws-cdk/cfnspec/lib/schema/resource-type.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/tag-manager.ts Show resolved Hide resolved
@mergify mergify bot dismissed eladb’s stale review September 25, 2019 20:34

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@moofish32
Copy link
Contributor Author

Where do I open the v2 issue or did I miss a document telling me about this?

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@eladb
Copy link
Contributor

eladb commented Oct 27, 2019

Hey @moofish32 what's up? How are you?

@moofish32
Copy link
Contributor Author

@eladb - I refactored to make this backwards compatible. I think I'm ready for one more review I have a couple of clean up comments against my self. I'm still not sure how I should handle a breaking change in the constructor.

I went to an optional additional parameter:

constructor(tagType: TagType, resourceTypeName: string, tagStructure?: any, options?: TagManagerOptions)

Going forward it seems like it would make more sense to move the constructor to:

export interface TagManagerOptions {
  /**
   * The initial CloudFormation tags
   *
   * If the user set tags on the lower level Cfn* object this are passed here to
   * ensure they are set on the final contruct. Based on the TagType these are
   * validated and parsed.
   */
  readonly cfnTags?: any;
  /**
   * The name of the property in CloudFormation for these tags
   *
   * Normally this is Tags, but Cognito UserPool uses UserPoolTags
   * @default tags
   */
  readonly tagPropertyName?: string;
}


constructor(tagType: TagType, resourceTypeName: string, options?: TagManagerOptions)

Based on the V2 issue, how to deprecate a constructor.

eladb
eladb previously requested changes Oct 29, 2019
packages/@aws-cdk/core/lib/tag-manager.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/test/test.tag-manager.ts Outdated Show resolved Hide resolved
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

eladb
eladb previously requested changes Dec 31, 2019
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

remove asCfnProperty and move logic to CfnResource

@mergify mergify bot dismissed eladb’s stale review January 2, 2020 00:03

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@eladb eladb changed the title fix(core): support tags for cognito user pools fix(core): tags not working for cognito user pools Jan 2, 2020
eladb
eladb previously approved these changes Jan 2, 2020
tagsProp[this.tags.tagPropertyName] = this.tags.renderTags();
return deepMerge(this._cfnProperties || {}, tagsProp);
}
return this._cfnProperties;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return this._cfnProperties;
return this._cfnProperties || {};

@mergify mergify bot dismissed eladb’s stale review January 2, 2020 06:31

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@moofish32
Copy link
Contributor Author

I believe I'm complete for all comments, let me know if I need to update branch or take any other action.

@mergify
Copy link
Contributor

mergify bot commented Jan 3, 2020

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Jan 3, 2020

Thank you for contributing! Your pull request is now being automatically merged.

@mergify mergify bot merged commit a67f0ef into aws:master Jan 3, 2020
@moofish32 moofish32 deleted the f-add-userpool-tags branch January 6, 2020 21:56
@nmussy
Copy link
Contributor

nmussy commented Apr 16, 2024 via email

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.

Tags not applied to Cognito UserPools
4 participants