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(servicecatalogappregistry): initial L2 construct for Application #15140

Merged
merged 16 commits into from
Jun 22, 2021

Conversation

arcrank
Copy link
Contributor

@arcrank arcrank commented Jun 16, 2021

Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing.

Testing done

  • yarn build && yarn test
  • yarn integ

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

Co-authored-by: Dillon Ponzo dponzo18@gmail.com

Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly
different ARN parsing

Testing done
------------------
* `yarn build && yarn test`
* `yarn integ`

Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@gitpod-io
Copy link

gitpod-io bot commented Jun 16, 2021

@arcrank arcrank changed the title Initial L2 construct for appregisty application feat(servicecatalogappregistry): Initial L2 construct for appregisty application Jun 16, 2021
@arcrank
Copy link
Contributor Author

arcrank commented Jun 16, 2021

Regarding ARN, the arn format is different from standard convention for this resource, however the environmentFromArn part still should work since those components of the arn, (e.g. region, account) are the same and the parsing works.

@skinny85 skinny85 self-requested a review June 16, 2021 17:38
@skinny85 skinny85 self-assigned this Jun 16, 2021
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 great! Just a few minor comments.

Addressing comments from PR

Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
@arcrank arcrank requested a review from skinny85 June 17, 2021 00:05
@mergify mergify bot dismissed skinny85’s stale review June 17, 2021 00:06

Pull request has been modified.

@peterwoodworth peterwoodworth added the @aws-cdk/aws-servicecatalog Related to AWS Service Catalog label Jun 17, 2021
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 great! A couple of super-minor issues.

packages/@aws-cdk/aws-servicecatalogappregistry/README.md Outdated Show resolved Hide resolved
* Validates length is between allowed min and max lengths.
*/
public static validateLength(resourceName: string, inputName: string, minLength: number, maxLength: number, inputString?: string): void {
if (inputString !== undefined && (inputString.length < minLength || inputString.length > maxLength)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

One important note that I forgot to include in the Portfolio PR.

If the value provided is a dynamic CloudFormation expression, like a Parameter Ref, we should skip this validation. You can figure out whether a given value is a dynamic expression using the Token.isUnresolved() method.

This needs to be verified with a unit test.

Could you also retroactively change this in the Portfolio class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. Followed convention from S3 test to make sure it doesn't throw validation error even when given an invalid value as token, which I think nicely covers the functionality.

Will make quick PR for adding this to our portfolio construct in aws-servicecatalog

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, would there be any interest/support in making some input validation apart of core?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created PR for this in servicecatalog: #15208

Aidan Crank and others added 2 commits June 18, 2021 15:14
Addressing minor formatting comments from PR review.
Added functionality to skip validation if we are passed a token for properties,
and added unit tests for those cases

Testing done
------------------
* `yarn build && yarn lint && yarn test`

Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
@mergify mergify bot dismissed skinny85’s stale review June 18, 2021 19:16

Pull request has been modified.

@arcrank arcrank requested a review from skinny85 June 18, 2021 19:25
@skinny85 skinny85 changed the title feat(servicecatalogappregistry): Initial L2 construct for appregisty application feat(servicecatalogappregistry): initial L2 construct for Application Jun 18, 2021
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.

Almost there!

*/
public static validateRegex(resourceName: string, inputName: string, regex: RegExp, inputString?: string): void {
if (!cdk.Token.isUnresolved(inputString) && inputString !== undefined && !regex.test(inputString)) {
throw new Error(`Invalid ${inputName} for resource ${resourceName}, must match regex pattern ${regex}, got: '${inputString}'`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not truncating this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't originally do it because it validates length first, but we truncate the string to 100 chars while the name can be longer, so probably would be better parity to do that hear as well. Will add

Comment on lines 71 to 77
const tokenDescription = cdk.Lazy.string({ produce: () => 'token description'.repeat(1000) });
expect(() => {
new appreg.Application(stack, 'MyApplication', {
applicationName: 'myApplication',
description: tokenDescription,
});
}).not.toThrow(/Invalid application description for resource/);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use a CloudFormation Parameter here instead of a Lazy? Using Lazy like that makes the test look weird (unrealistic).

I would also just assert on the template contents:

Suggested change
const tokenDescription = cdk.Lazy.string({ produce: () => 'token description'.repeat(1000) });
expect(() => {
new appreg.Application(stack, 'MyApplication', {
applicationName: 'myApplication',
description: tokenDescription,
});
}).not.toThrow(/Invalid application description for resource/);
const param = new cdk.CfnParameter(stack, 'Param');
new appreg.Application(stack, 'MyApplication', {
applicationName: 'myApplication',
description: param.valueAsString,
});
expect(stack).toHaveResourceLike('AWS::ServiceCatalogAppRegistry::Application', {
Description: {
Ref: 'Param',
},
});

Looks like we're missing a similar test for applicationName, BTW.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to test template for the fields, both name and description

Aidan Crank and others added 4 commits June 21, 2021 15:51
Updating unit tests to properly test that token inputs do
end up getting created in template and not just validating it throwing
a specific error

Testing done
------------------
* `yarn build && yarn lint && yarn test`

Co-authored-by Dillon Ponzo <dponzo18@gmail.com>
… into appregistry_l2_construct

merging branch
@arcrank arcrank requested a review from skinny85 June 21, 2021 19:59
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 great! 2 super minor last comments.

Co-authored-by: Adam Ruka <adamruka85@gmail.com>
@arcrank
Copy link
Contributor Author

arcrank commented Jun 21, 2021

Looks great! 2 super minor last comments.

Nice turnaround on the ARN parsing. Updated the test and messaging to match our other resources for consistency.

const arn = cdk.Stack.of(scope).splitArn(applicationArn, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME);
const applicationId = arn.resourceName;

if (!applicationId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed this to match our SC construct error check and messaging

@arcrank arcrank requested a review from skinny85 June 21, 2021 22:40
/**
* Enforces a particular physical application name.
*/
readonly applicationName: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW - you called this displayName in Portfolio. Any reason you went with a different name in Application?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual cfn term in Portfolio is DisplayName, see here. For application it is just name hence applicationName.

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't want to make this consistent across the ServiceCatalog constructs that exhibit this behavior (display name + auto-generated ID)?

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.

👍

@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2021

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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 48ffa72
  • 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 881737c into aws:master Jun 22, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2021

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

Seiya6329 pushed a commit to Seiya6329/aws-cdk that referenced this pull request Jun 22, 2021
…aws#15140)

Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing.

Testing done
------------------
* `yarn build && yarn test`
* `yarn integ`

----

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



Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
matthewsvu pushed a commit to matthewsvu/aws-cdk that referenced this pull request Jun 22, 2021
…aws#15140)

Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing.

Testing done
------------------
* `yarn build && yarn test`
* `yarn integ`

----

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



Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
@arcrank arcrank deleted the appregistry_l2_construct branch June 30, 2021 20:16
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…aws#15140)

Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing.

Testing done
------------------
* `yarn build && yarn test`
* `yarn integ`

----

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



Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-servicecatalog Related to AWS Service Catalog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants