Skip to content

Commit

Permalink
chore: add notices.json validation (#627)
Browse files Browse the repository at this point in the history
Add validation to notices.json
  • Loading branch information
GavinZZ authored Sep 26, 2024
1 parent 3fc1024 commit 2cfcfbb
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 10 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ Example:
}
```

## FAQ

When adding a new notice to `notices.json`, if you see errors like `Invalid fully qualified name`
or `Invalid prefix of a qualified name`, it's likely an issue with the format of the construct
name inputed. Please read the above requirement to determine the correct construct name and
cross reference with the value defined as `constructInfo.fnq` in `tree.json`.

If the value is correct and the validator fails, it's likely there is a change in the repository,
i.e. stablizing an experimental module, introducing a new module. In the event of these, you
need to manually add to the `constrcut-info.ts` file with the correct construct name.

## License

This project is licensed under the Apache-2.0 License.
Expand Down
20 changes: 10 additions & 10 deletions data/notices.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"overview": "Previously, the BedrockInvokeModel outputPath parameter could be used to select a portion of the model output to pass to the next state. Now, the outputPath parameter is assumed to be an S3Uri where the model output should be saved. The parameter can no longer be used to select model output and pass it to the next state.",
"components": [
{
"name": "aws-cdk-lib.aws-step-functions-tasks.BedrockInvokeModel",
"name": "aws-cdk-lib.aws_stepfunctions_tasks.BedrockInvokeModel",
"version": ">=v2.150.0 <=v2.155.0"
}
],
Expand All @@ -22,7 +22,7 @@
"version": "2.116.0"
},
{
"name": "aws-cdk-lib.CustomResourceProvider",
"name": "aws-cdk-lib.custom_resources.Provider",
"version": "2.116.0"
}
],
Expand All @@ -46,7 +46,7 @@
"overview": "The names of stacks that contain special characters (such as '-') are incorrectly sanitized. This is a breaking change to the names of stacks that have already been deployed.",
"components": [
{
"name": "aws-cdk-lib/core.Stack",
"name": "aws-cdk-lib.core.Stack",
"version": ">=v2.74.0 <v2.75.1"
}
],
Expand Down Expand Up @@ -226,7 +226,7 @@
"overview": "Starting April 2023, S3 buckets configured with ACLs (used for S3 access logging and CloudFront logging) need additional configuration",
"components": [
{
"name": "aws-cdk-lib.s3.Bucket",
"name": "aws-cdk-lib.aws_s3.Bucket",
"version": "^2.0.0 <2.60.0"
},
{
Expand Down Expand Up @@ -330,7 +330,7 @@
"version": "2.97.0"
},
{
"name": "aws-cdk-lib.aws-applicationautoscaling.Schedule",
"name": "aws-cdk-lib.aws_applicationautoscaling.Schedule",
"version": "2.97.0"
},
{
Expand All @@ -350,7 +350,7 @@
"overview": "Using the `grantRead` method on `aws-cdk-lib/aws-s3.Bucket` results in an invalid action attached to the resource policy which can cause unexpected failures when interacting with the bucket.",
"components": [
{
"name": "aws-cdk-lib/aws_s3.Bucket",
"name": "aws-cdk-lib.aws_s3.Bucket",
"version": "2.101.0"
}
],
Expand Down Expand Up @@ -430,7 +430,7 @@
"overview": "All users of `aws-events-targets` who created an `events.Rule` with the `SqsQueue` target and passed an imported (eg, `fromQueueArn` or `fromQueueName`) queue to the `deadLetterQueue` prop would receive an error similar to: ```Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region.```.",
"components": [
{
"name": "aws-cdk-lib/aws_events.Rule",
"name": "aws-cdk-lib.aws_events.Rule",
"version": ">=2.110.0 <=2.115.0"
}
],
Expand All @@ -442,7 +442,7 @@
"overview": "v2.116.0 introduced the ability to create multiple event bus policies on a single event bus. To facilitate this, the logical Id was changed from \"Policy\" to the statementId. This triggers a replacement, which fails in CloudFormation because the statement ID does not change.",
"components": [
{
"name": "aws-cdk-lib/aws_events.EventBus",
"name": "aws-cdk-lib.aws_events.EventBus",
"version": ">=2.116.0 <=2.117.0"
}
],
Expand All @@ -454,7 +454,7 @@
"overview": "v2.116.0 introduced the ability to setup logging for a state machine created by the custom resource provider framework. This can lead to a deploy failure because the log group resource policy size can be exceeded.",
"components": [
{
"name": "aws-cdk-lib/custom_resources.Provider",
"name": "aws-cdk-lib.custom_resources.Provider",
"version": ">=2.116.0 <=2.121.0"
}
],
Expand Down Expand Up @@ -490,7 +490,7 @@
"overview": "Partition in policy statement for `ecs:TagResource` action in `EcsTask` was hardcoded to `aws` instead of being resolved dynamically in v2.132.0, resulting in failure to deploy in any partition except AWS with an IAM validation failure on the partition arn.",
"components": [
{
"name": "aws-cdk-lib/aws_events.Rules",
"name": "aws-cdk-lib.aws_events.Rules",
"version": "2.132.0"
}
],
Expand Down
209 changes: 209 additions & 0 deletions src/construct-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
export const CONSTRUCT_INFO = [
'aws-cdk-lib.aws_elasticsearch',
'@aws-cdk/aws-appconfig-alpha',
'aws-cdk-lib.aws_elasticbeanstalk',
'aws-cdk-lib.aws_stepfunctions_tasks',
'@aws-cdk/aws-ecr-assets',
'aws-cdk-lib.aws_applicationautoscaling',
'@aws-cdk/aws-servicecatalogappregistry',
'aws-cdk-lib.aws_chatbot',
'@aws-cdk/aws-codepipeline-actions',
'@aws-cdk/aws-sqs',
'cli',
'framework',
'aws-cdk-lib.aws_bedrock',
'aws-cdk-lib.aws_iot',
'aws-cdk-lib.aws_wafv2',
'aws-cdk-lib.aws_opensearchservice',
'@aws-cdk/aws-elasticsearch',
'aws-cdk-lib.aws_kms',
'@aws-cdk/aws-neptune',
'@aws-cdk/aws-ec2',
'aws-cdk-lib.CfnJson',
'aws-cdk-lib.aws_synthetics',
'@aws-cdk/aws-elasticloadbalancingv2',
'aws-cdk-lib.aws_sqs',
'@aws-cdk/aws-route53',
'@aws-cdk/app-staging-synthesizer-alpha',
'aws-cdk-lib.aws_directoryservice',
'@aws-cdk/aws-glue-alpha',
'aws-cdk-lib.aws_ses',
'@aws-cdk/aws-location',
'aws-cdk-lib.aws_ram',
'@aws-cdk/aws-databrew',
'@aws-cdk/aws-logs',
'@aws-cdk/aws-chatbot',
'@aws-cdk/aws-iotevents',
'@aws-cdk/aws-ssmincidents',
'aws-cdk-lib.aws_emr',
'aws-cdk-lib.aws_codecommit',
'@aws-cdk/aws-iotevents-alpha',
'@aws-cdk/aws-cloudtrail',
'@aws-cdk/aws-lambda',
'@aws-cdk/aws-iam',
'@aws-cdk/integ-tests-alpha',
'aws-cdk-lib.aws_backup',
'aws-cdk-lib.aws_appconfig',
'@aws-cdk/aws-glue',
'aws-cdk-lib.aws_kinesisfirehose',
'@aws-cdk/aws-events',
'@aws-cdk/aws-cloudwatch',
'@aws-cdk/aws-kms',
'@aws-cdk/example-construct-library',
'aws-cdk-lib.lambda_layer_awscli',
'aws-cdk-lib.aws_amplify',
'aws-cdk-lib.aws_acmpca',
'@aws-cdk/aws-ec2-alpha',
'@aws-cdk/aws-ivs-alpha',
'aws-cdk-lib.aws_ivs',
'aws-cdk-lib.aws_fsx',
'aws-cdk-lib.aws_ec2',
'@aws-cdk/aws-codepipeline',
'aws-cdk-lib.cloudformation_include',
'@aws-cdk/aws-redshift',
'@aws-cdk/lambda-layer-kubectl-v30',
'aws-cdk-lib.aws_dynamodb',
'aws-cdk-lib.aws_s3',
'@aws-cdk/aws-iot',
'aws-cdk-lib.aws_s3_assets',
'aws-cdk-lib.aws_cloud9',
'aws-cdk-lib.aws_servicecatalog',
'@aws-cdk/aws-globalaccelerator',
'@aws-cdk/aws-docdb',
'aws-cdk-lib.aws_neptune',
'@aws-cdk/aws-kinesisanalytics-flink-alpha',
'@aws-cdk/aws-lambda-go',
'aws-cdk-lib.aws_batch',
'aws-cdk-lib.aws_docdb',
'aws-cdk-lib.aws_sns',
'@aws-cdk/aws-sagemaker-alpha',
'@aws-cdk/aws-ecs',
'aws-cdk-lib.aws_iotevents',
'@aws-cdk/aws-cognito',
'@aws-cdk/aws-codebuild',
'aws-cdk-lib.aws_certificatemanager',
'aws-cdk-lib.aws_msk',
'aws-cdk-lib.aws_appmesh',
'@aws-cdk/core',
'@aws-cdk/aws-opensearchservice',
'aws-cdk-lib.aws_globalaccelerator',
'@aws-cdk/aws-apigateway',
'@aws-cdk/aws-ecr',
'aws-cdk-lib.aws_iam',
'aws-cdk-lib.lambda_layer_node_proxy_agent',
'@aws-cdk/aws-msk-alpha',
'aws-cdk-lib.aws_route53',
'@aws-cdk/aws-lambda-go-alpha',
'aws-cdk-lib.aws_redshift',
'aws-cdk-lib.aws_codepipeline',
'@aws-cdk/aws-appsync',
'@aws-cdk/aws-apigatewayv2-alpha',
'@aws-cdk/aws-codestarnotifications',
'@aws-cdk/cloudformation-include',
'@aws-cdk/aws-kinesisfirehose',
'@aws-cdk/aws-servicecatalogappregistry-alpha',
'@aws-cdk/aws-ram',
'aws-cdk-lib.aws_location',
'@aws-cdk/aws-servicecatalog',
'@aws-cdk/aws-codeguruprofiler',
'aws-cdk-lib.aws_secretsmanager',
'@aws-cdk/aws-codedeploy',
'@aws-cdk/aws-iot-alpha',
'@aws-cdk/aws-cloud9-alpha',
'aws-cdk-lib.aws_appsync',
'@aws-cdk/aws-cloudfront',
'aws-cdk-lib.aws_ecs',
'@aws-cdk/aws-ssm',
'aws-cdk-lib.aws_signer',
'@aws-cdk/aws-dynamodb',
'aws-cdk-lib.aws_elasticloadbalancing',
'aws-cdk-lib.aws_apprunner',
'aws-cdk-lib.aws_lambda_nodejs',
'@aws-cdk/aws-applicationautoscaling',
'aws-cdk-lib.aws_elasticloadbalancingv2',
'aws-cdk-lib.aws_sam',
'@aws-cdk/aws-cognito-identitypool-alpha',
'aws-cdk-lib.aws_eks',
'@aws-cdk/aws-eks',
'@aws-cdk/s3',
'@aws-cdk/pipelines',
'@aws-cdk/aws-ecs-patterns',
'@aws-cdk/aws-wafv2',
'aws-cdk-lib.core',
'aws-cdk-lib.aws_apigatewayv2',
'aws-cdk-lib.aws_cloudfront',
'@aws-cdk/aws-s3',
'@aws-cdk/lambda-layer-kubectl-v24',
'aws-cdk-lib.pipelines',
'aws-cdk-lib.aws_s3_deployment',
'@aws-cdk/aws-sns',
'aws-cdk-lib.aws_sagemaker',
'aws-cdk-lib.aws_kinesisanalytics',
'@aws-cdk/aws-sagemaker',
'aws-cdk-lib.aws_codeguruprofiler',
'aws-cdk-lib.aws_stepfunctions',
'aws-cdk-lib.aws_cloudwatch',
'aws-cdk-lib.lambda_layer_kubectl',
'aws-cdk-lib.aws_codedeploy',
'aws-cdk-lib.custom_resources',
'aws-cdk-lib.aws_config',
'@aws-cdk/aws-gamelift',
'aws-cdk-lib.aws_scheduler',
'@aws-cdk/aws-lambda-python',
'aws-cdk-lib.aws_ecr_assets',
'aws-cdk-lib.aws_apigateway',
'aws-cdk-lib.aws_redshiftserverless',
'@aws-cdk/aws-stepfunctions',
'aws-cdk-lib.aws_cognito',
'aws-cdk-lib.aws_logs',
'@aws-cdk/aws-elasticloadbalancing',
'@aws-cdk/integ-tests',
'aws-cdk-lib.aws_cloudtrail',
'aws-cdk-lib.aws_servicecatalogappregistry',
'aws-cdk-lib',
'aws-cdk-lib.aws_kinesis',
'aws-cdk-lib.aws_pipes',
'@aws-cdk/aws-certificatemanager',
'@aws-cdk/aws-codecommit',
'constructs',
'aws-cdk-lib.aws_servicediscovery',
'@aws-cdk/aws-redshift-alpha',
'@aws-cdk/aws-servicediscovery',
'aws-cdk-lib.triggers',
'@aws-cdk/aws-route53resolver',
'aws-cdk-lib.aws_cloudfront.experimental',
'@aws-cdk/aws-lambda-python-alpha',
'aws-cdk-lib.aws_rds',
'@aws-cdk/aws-apprunner',
'aws-cdk-lib.aws_efs',
'@aws-cdk/aws-ivs',
'@aws-cdk/aws-secretsmanager',
'aws-cdk-lib.aws_route53_patterns',
'@aws-cdk/aws-apprunner-alpha',
'@aws-cdk/aws-kinesisfirehose-alpha',
'aws-cdk-lib.aws_events',
'@aws-cdk/aws-s3objectlambda-alpha',
'@aws-cdk/aws-ses',
'aws-cdk-lib.aws_ecr',
'aws-cdk-lib.aws_inspector',
'@aws-cdk/aws-s3-assets',
'aws-cdk-lib.aws_ecs_patterns',
'@aws-cdk/aws-amplify-alpha',
'aws-cdk-lib.aws_s3objectlambda',
'@aws-cdk/aws-neptune-alpha',
'aws-cdk-lib.aws_ssm',
'@aws-cdk/aws-rds',
'@aws-cdk/aws-pipes-alpha',
'@aws-cdk/aws-fsx',
'aws-cdk-lib.aws_codebuild',
'@aws-cdk/aws-route53-patterns',
'aws-cdk-lib.aws_autoscaling',
'aws-cdk-lib.aws_lambda',
'@aws-cdk/aws-scheduler-alpha',
'@aws-cdk/aws-stepfunctions-tasks',
'@aws-cdk/aws-cloud9',
'@aws-cdk/aws-synthetics-alpha',
'@aws-cdk/aws-config',
'aws-cdk-lib.aws_glue',
'@aws-cdk/aws-apigatewayv2',
];
30 changes: 30 additions & 0 deletions src/notice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as semver from 'semver';
import { CONSTRUCT_INFO } from './construct-info';

const MAX_TITLE_LENGTH = 100;

Expand Down Expand Up @@ -34,6 +35,35 @@ export function validateNotice(notice: Notice): void {
if (!semver.validRange(component.version)) {
throw new Error(`Component version ${component.version} is not a valid semver range`);
}

const names = component.name.split('.');
const packageName = names[0];

if (names.length === 3) {
// Expect fully qualified name of a stable construct (e.g., `aws-cdk-lib.aws_amplify.CfnBranch`)
// Expect a prefix of a fully qualified name (e.g., `aws-cdk-lib.aws_amplify.`)
const module = names.slice(0, 2).join('.');

if (!CONSTRUCT_INFO.includes(module)) {
throw new Error(`Invalid fully qualified name of a stable construct ${component.name}.`);
}
} else if (names.length === 2 && packageName.includes('aws-cdk-lib')) {
// This is likely an error case since it require a suffix '.' at the end of the construct name.
const module = names.slice(0, 2).join('.');

if (!CONSTRUCT_INFO.includes(module)) {
throw new Error(`Invalid prefix of a qualified name ${component.name}. Missing the '.' at the end`);
}
} else if (names.length === 2 && packageName.includes('@aws-cdk')) {
// Expect a fully qualified name of an experimental construct (e.g., `@aws-cdk/aws-ecr-assets.CfnBranch`)
const module = names.slice(0, 1).join('.');

if (!CONSTRUCT_INFO.includes(module)) {
throw new Error(`Invalid fully qualified name of an experimental construct ${component.name}.`);
}
} else if (names.length == 1 && !CONSTRUCT_INFO.includes(names[0])) {
throw new Error(`Invalid component name ${component.name}.`);
}
}

if (!semver.validRange(notice.schemaVersion)) {
Expand Down
Loading

0 comments on commit 2cfcfbb

Please sign in to comment.