From a357bdef775ad30d726090150d496bcb24d576be Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Thu, 27 Sep 2018 15:24:38 +0300 Subject: [PATCH 1/3] style: change indentation from 4 spaces to 2 spaces (#790) We decided to conform to the industry standard [1] which uses 2 spaces for JavaScript and TypeScript. Fixes #761 [1]: https://github.com/basarat/typescript-book/blob/master/docs/styleguide/styleguide.md#spaces --- .../advanced-usage/index.ts | 276 +- .../bucket-import-export/index.ts | 40 +- .../chat-app/cognito-chat-room-pool.ts | 58 +- .../chat-app/dynamodb-posts-table.ts | 16 +- .../cdk-examples-typescript/chat-app/index.ts | 140 +- .../cloudformation/index.ts | 12 +- .../custom-resource/index.ts | 128 +- examples/cdk-examples-typescript/ec2/index.ts | 74 +- .../hello-cdk/index.ts | 18 +- .../neptune-demo/index.ts | 38 +- .../cdk-examples-typescript/sns-sqs/index.ts | 64 +- .../use-vpc-from-another-stack/index.ts | 28 +- .../@aws-cdk/applet-js/bin/cdk-applet-js.ts | 106 +- .../applet-js/test/strip-stacktrace.ts | 32 +- .../@aws-cdk/applet-js/test/test-applet.ts | 30 +- packages/@aws-cdk/assert/lib/assertion.ts | 32 +- .../assert/lib/assertions/and-assertion.ts | 22 +- .../assert/lib/assertions/count-resources.ts | 40 +- .../@aws-cdk/assert/lib/assertions/exist.ts | 18 +- .../assert/lib/assertions/have-resource.ts | 138 +- .../assert/lib/assertions/have-type.ts | 24 +- .../assert/lib/assertions/match-template.ts | 102 +- .../lib/assertions/negated-assertion.ts | 20 +- packages/@aws-cdk/assert/lib/expect.ts | 40 +- packages/@aws-cdk/assert/lib/index.ts | 2 +- packages/@aws-cdk/assert/lib/inspector.ts | 86 +- .../@aws-cdk/assert/test/test.assertions.ts | 236 +- packages/@aws-cdk/assets/lib/asset.ts | 322 +- packages/@aws-cdk/assets/lib/index.ts | 2 +- .../assets/test/integ.assets.directory.lit.ts | 20 +- .../assets/test/integ.assets.file.lit.ts | 20 +- .../test/integ.assets.permissions.lit.ts | 20 +- .../assets/test/integ.assets.refs.lit.ts | 26 +- packages/@aws-cdk/assets/test/test.asset.ts | 214 +- .../aws-amazonmq/test/test.amazonmq.ts | 8 +- .../@aws-cdk/aws-apigateway/lib/deployment.ts | 262 +- .../aws-apigateway/lib/integration.ts | 416 +- .../aws-apigateway/lib/integrations/aws.ts | 120 +- .../aws-apigateway/lib/integrations/http.ts | 58 +- .../aws-apigateway/lib/integrations/lambda.ts | 90 +- .../aws-apigateway/lib/integrations/mock.ts | 12 +- .../@aws-cdk/aws-apigateway/lib/method.ts | 326 +- .../@aws-cdk/aws-apigateway/lib/resource.ts | 248 +- .../aws-apigateway/lib/restapi-ref.ts | 66 +- .../@aws-cdk/aws-apigateway/lib/restapi.ts | 640 +- packages/@aws-cdk/aws-apigateway/lib/stage.ts | 402 +- packages/@aws-cdk/aws-apigateway/lib/util.ts | 94 +- .../test/integ.restapi.books.ts | 94 +- .../test/integ.restapi.defaults.ts | 2 +- .../aws-apigateway/test/integ.restapi.ts | 98 +- .../aws-apigateway/test/test.deployment.ts | 332 +- .../@aws-cdk/aws-apigateway/test/test.http.ts | 102 +- .../aws-apigateway/test/test.lambda.ts | 438 +- .../aws-apigateway/test/test.method.ts | 518 +- .../aws-apigateway/test/test.restapi.ts | 1254 +- .../aws-apigateway/test/test.stage.ts | 478 +- .../@aws-cdk/aws-apigateway/test/test.util.ts | 108 +- .../test/test.applicationautoscaling.ts | 8 +- .../@aws-cdk/aws-appsync/test/test.appsync.ts | 8 +- .../@aws-cdk/aws-athena/test/test.athena.ts | 8 +- .../aws-autoscaling/lib/auto-scaling-group.ts | 890 +- .../test/integ.asg-w-classic-loadbalancer.ts | 18 +- .../aws-autoscaling/test/integ.asg-w-elbv2.ts | 20 +- .../test/test.auto-scaling-group.ts | 576 +- .../test/test.autoscalingplans.ts | 8 +- .../@aws-cdk/aws-batch/test/test.batch.ts | 8 +- .../@aws-cdk/aws-budgets/test/test.budgets.ts | 8 +- .../lib/certificate-ref.ts | 48 +- .../aws-certificatemanager/lib/certificate.ts | 100 +- .../lib/public-suffixes.ts | 12788 ++++++++-------- .../aws-certificatemanager/lib/util.ts | 18 +- .../test/test.certificate.ts | 98 +- .../test/test.certificatemanager.ts | 8 +- .../aws-certificatemanager/test/test.util.ts | 18 +- .../@aws-cdk/aws-cloud9/test/test.cloud9.ts | 8 +- .../aws-cloudformation/lib/custom-resource.ts | 86 +- .../lib/pipeline-actions.ts | 438 +- .../test/integ.trivial-lambda-resource.ts | 82 +- .../test/test.cloudformation.ts | 8 +- .../aws-cloudformation/test/test.resource.ts | 174 +- .../aws-cloudfront/lib/web_distribution.ts | 854 +- .../test/integ.cloudfront-custom.ts | 26 +- .../aws-cloudfront/test/integ.cloudfront.ts | 16 +- .../aws-cloudfront/test/test.basic.ts | 442 +- packages/@aws-cdk/aws-cloudtrail/lib/index.ts | 370 +- .../aws-cloudtrail/test/test.cloudtrail.ts | 156 +- packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts | 498 +- .../@aws-cdk/aws-cloudwatch/lib/dashboard.ts | 96 +- packages/@aws-cdk/aws-cloudwatch/lib/graph.ts | 484 +- .../@aws-cdk/aws-cloudwatch/lib/layout.ts | 206 +- .../@aws-cdk/aws-cloudwatch/lib/metric.ts | 634 +- packages/@aws-cdk/aws-cloudwatch/lib/text.ts | 74 +- .../aws-cloudwatch/lib/util.statistic.ts | 68 +- .../@aws-cdk/aws-cloudwatch/lib/widget.ts | 74 +- .../test/integ.alarm-and-dashboard.ts | 28 +- .../aws-cloudwatch/test/test.alarm.ts | 202 +- .../aws-cloudwatch/test/test.dashboard.ts | 230 +- .../aws-cloudwatch/test/test.graphs.ts | 396 +- .../aws-cloudwatch/test/test.layout.ts | 132 +- .../aws-cloudwatch/test/test.metrics.ts | 44 +- .../@aws-cdk/aws-codebuild/lib/artifacts.ts | 138 +- .../aws-codebuild/lib/pipeline-actions.ts | 80 +- .../aws-codebuild/lib/pipeline-project.ts | 14 +- .../@aws-cdk/aws-codebuild/lib/project.ts | 1466 +- packages/@aws-cdk/aws-codebuild/lib/source.ts | 200 +- .../aws-codebuild/test/integ.caching.ts | 18 +- .../test/integ.project-bucket.ts | 8 +- .../test/integ.project-events.ts | 18 +- .../aws-codebuild/test/integ.project-shell.ts | 2 +- .../aws-codebuild/test/test.codebuild.ts | 1532 +- .../aws-codebuild/test/test.project.ts | 134 +- .../aws-codecommit/lib/pipeline-action.ts | 86 +- .../@aws-cdk/aws-codecommit/lib/repository.ts | 544 +- .../aws-codecommit/test/test.codecommit.ts | 88 +- .../aws-codedeploy/lib/application.ts | 108 +- .../aws-codedeploy/lib/deployment-config.ts | 202 +- .../aws-codedeploy/lib/deployment-group.ts | 366 +- .../aws-codedeploy/lib/pipeline-action.ts | 134 +- .../test/test.deployment-config.ts | 104 +- .../test/test.deployment-group.ts | 130 +- .../aws-codepipeline-api/lib/action.ts | 438 +- .../aws-codepipeline-api/lib/artifact.ts | 100 +- .../aws-codepipeline-api/lib/build-action.ts | 64 +- .../aws-codepipeline-api/lib/deploy-action.ts | 30 +- .../aws-codepipeline-api/lib/source-action.ts | 84 +- .../aws-codepipeline-api/lib/validation.ts | 32 +- .../lib/github-source-action.ts | 102 +- .../lib/manual-approval-action.ts | 16 +- .../@aws-cdk/aws-codepipeline/lib/pipeline.ts | 572 +- .../@aws-cdk/aws-codepipeline/lib/stage.ts | 252 +- .../test/integ.cfn-template-from-repo.lit.ts | 26 +- .../test/integ.lambda-pipeline.expected.json | 2 +- .../test/integ.lambda-pipeline.ts | 28 +- .../test/integ.pipeline-cfn.ts | 22 +- .../test/integ.pipeline-code-commit-build.ts | 12 +- .../test/integ.pipeline-code-commit.ts | 4 +- .../test/integ.pipeline-code-deploy.ts | 26 +- .../test/integ.pipeline-events.ts | 26 +- .../aws-codepipeline/test/test.action.ts | 164 +- .../test.cloudformation-pipeline-actions.ts | 640 +- .../test/test.general-validation.ts | 118 +- .../aws-codepipeline/test/test.pipeline.ts | 644 +- .../aws-codepipeline/test/test.stages.ts | 278 +- .../@aws-cdk/aws-cognito/test/test.cognito.ts | 8 +- .../@aws-cdk/aws-config/test/test.config.ts | 8 +- .../test/test.datapipeline.ts | 8 +- packages/@aws-cdk/aws-dax/test/test.dax.ts | 8 +- .../test/test.directoryservice.ts | 8 +- packages/@aws-cdk/aws-dms/test/test.dms.ts | 8 +- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 536 +- .../aws-dynamodb/test/integ.dynamodb.ts | 8 +- .../aws-dynamodb/test/test.dynamodb.ts | 2482 +-- packages/@aws-cdk/aws-ec2/lib/connections.ts | 292 +- .../@aws-cdk/aws-ec2/lib/instance-types.ts | 416 +- .../@aws-cdk/aws-ec2/lib/machine-image.ts | 316 +- packages/@aws-cdk/aws-ec2/lib/network-util.ts | 476 +- .../aws-ec2/lib/security-group-rule.ts | 332 +- .../@aws-cdk/aws-ec2/lib/security-group.ts | 498 +- packages/@aws-cdk/aws-ec2/lib/util.ts | 208 +- packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts | 556 +- packages/@aws-cdk/aws-ec2/lib/vpc.ts | 952 +- .../@aws-cdk/aws-ec2/test/test.connections.ts | 174 +- .../aws-ec2/test/test.network-utils.ts | 354 +- packages/@aws-cdk/aws-ec2/test/test.vpc.ts | 908 +- packages/@aws-cdk/aws-ecr/lib/lifecycle.ts | 138 +- .../@aws-cdk/aws-ecr/lib/repository-ref.ts | 92 +- packages/@aws-cdk/aws-ecr/lib/repository.ts | 310 +- packages/@aws-cdk/aws-ecr/test/integ.basic.ts | 4 +- .../@aws-cdk/aws-ecr/test/test.repository.ts | 364 +- packages/@aws-cdk/aws-ecs/test/test.ecs.ts | 8 +- packages/@aws-cdk/aws-efs/test/test.efs.ts | 8 +- packages/@aws-cdk/aws-eks/test/test.eks.ts | 8 +- .../aws-elasticache/test/test.elasticache.ts | 8 +- .../test/test.elasticbeanstalk.ts | 8 +- .../aws-elasticloadbalancing/lib/index.ts | 2 +- .../lib/load-balancer.ts | 622 +- .../test/integ.elb.ts | 24 +- .../test/test.loadbalancer.ts | 166 +- .../alb/application-listener-certificate.ts | 46 +- .../lib/alb/application-listener-rule.ts | 222 +- .../lib/alb/application-listener.ts | 922 +- .../lib/alb/application-load-balancer.ts | 342 +- .../lib/alb/application-target-group.ts | 284 +- .../aws-elasticloadbalancingv2/lib/index.ts | 2 +- .../lib/nlb/network-listener.ts | 296 +- .../lib/nlb/network-load-balancer.ts | 156 +- .../lib/nlb/network-target-group.ts | 98 +- .../lib/shared/base-listener.ts | 54 +- .../lib/shared/base-load-balancer.ts | 246 +- .../lib/shared/base-target-group.ts | 496 +- .../lib/shared/enums.ts | 136 +- .../lib/shared/imported.ts | 18 +- .../lib/shared/load-balancer-targets.ts | 162 +- .../lib/shared/util.ts | 64 +- .../test/alb/test.listener.ts | 602 +- .../test/alb/test.load-balancer.ts | 238 +- .../test/alb/test.security-groups.ts | 440 +- .../test/helpers.ts | 36 +- .../test/integ.alb.ts | 20 +- .../test/integ.nlb.ts | 12 +- .../test/nlb/test.listener.ts | 212 +- .../test/nlb/test.load-balancer.ts | 118 +- .../test/test.elasticsearch.ts | 8 +- packages/@aws-cdk/aws-emr/test/test.emr.ts | 8 +- .../@aws-cdk/aws-events/lib/event-pattern.ts | 120 +- .../@aws-cdk/aws-events/lib/input-options.ts | 84 +- packages/@aws-cdk/aws-events/lib/rule-ref.ts | 62 +- packages/@aws-cdk/aws-events/lib/rule.ts | 370 +- packages/@aws-cdk/aws-events/lib/target.ts | 82 +- packages/@aws-cdk/aws-events/lib/util.ts | 62 +- .../@aws-cdk/aws-events/test/test.rule.ts | 668 +- .../@aws-cdk/aws-events/test/test.util.ts | 100 +- .../aws-gamelift/test/test.gamelift.ts | 8 +- packages/@aws-cdk/aws-glue/test/test.glue.ts | 8 +- .../aws-guardduty/test/test.guardduty.ts | 8 +- packages/@aws-cdk/aws-iam/lib/group.ts | 188 +- .../@aws-cdk/aws-iam/lib/managed-policy.ts | 30 +- packages/@aws-cdk/aws-iam/lib/policy.ts | 296 +- packages/@aws-cdk/aws-iam/lib/role.ts | 296 +- packages/@aws-cdk/aws-iam/lib/user.ts | 270 +- packages/@aws-cdk/aws-iam/lib/util.ts | 42 +- packages/@aws-cdk/aws-iam/test/integ.role.ts | 2 +- packages/@aws-cdk/aws-iam/test/integ.user.ts | 6 +- .../aws-iam/test/integ.users-and-groups.ts | 6 +- packages/@aws-cdk/aws-iam/test/test.group.ts | 54 +- .../aws-iam/test/test.managed-policy.ts | 42 +- packages/@aws-cdk/aws-iam/test/test.policy.ts | 540 +- packages/@aws-cdk/aws-iam/test/test.role.ts | 320 +- packages/@aws-cdk/aws-iam/test/test.user.ts | 54 +- .../aws-inspector/test/test.inspector.ts | 8 +- packages/@aws-cdk/aws-iot/test/test.iot.ts | 8 +- .../aws-iot1click/test/test.iot1click.ts | 8 +- packages/@aws-cdk/aws-kinesis/lib/stream.ts | 634 +- .../@aws-cdk/aws-kinesis/test/test.stream.ts | 1880 +-- .../test/test.subscriptiondestination.ts | 124 +- .../test/test.kinesisanalytics.ts | 8 +- .../test/test.kinesisfirehose.ts | 8 +- packages/@aws-cdk/aws-kms/lib/alias.ts | 68 +- packages/@aws-cdk/aws-kms/lib/key.ts | 294 +- packages/@aws-cdk/aws-kms/test/integ.key.ts | 6 +- packages/@aws-cdk/aws-kms/test/test.alias.ts | 156 +- packages/@aws-cdk/aws-kms/test/test.key.ts | 694 +- packages/@aws-cdk/aws-lambda/lib/alias.ts | 254 +- packages/@aws-cdk/aws-lambda/lib/code.ts | 208 +- packages/@aws-cdk/aws-lambda/lib/inline.ts | 182 +- .../@aws-cdk/aws-lambda/lib/lambda-ref.ts | 706 +- .../@aws-cdk/aws-lambda/lib/lambda-version.ts | 72 +- packages/@aws-cdk/aws-lambda/lib/lambda.ts | 654 +- .../@aws-cdk/aws-lambda/lib/permission.ts | 88 +- .../aws-lambda/lib/pipeline-action.ts | 128 +- packages/@aws-cdk/aws-lambda/lib/runtime.ts | 72 +- .../aws-lambda/lib/singleton-lambda.ts | 88 +- .../aws-lambda/test/integ.assets.file.ts | 22 +- .../aws-lambda/test/integ.assets.lit.ts | 22 +- .../test/integ.bucket-notifications.ts | 12 +- .../@aws-cdk/aws-lambda/test/integ.events.ts | 12 +- .../@aws-cdk/aws-lambda/test/integ.inline.ts | 44 +- .../@aws-cdk/aws-lambda/test/integ.lambda.ts | 10 +- .../aws-lambda/test/integ.vpc-lambda.ts | 8 +- .../@aws-cdk/aws-lambda/test/test.alias.ts | 248 +- .../@aws-cdk/aws-lambda/test/test.inline.ts | 54 +- .../@aws-cdk/aws-lambda/test/test.lambda.ts | 1962 +-- .../aws-lambda/test/test.singleton-lambda.ts | 100 +- .../test/test.subscriptiondestination.ts | 54 +- .../aws-lambda/test/test.vpc-lambda.ts | 306 +- .../aws-logs/lib/cross-account-destination.ts | 134 +- packages/@aws-cdk/aws-logs/lib/log-group.ts | 446 +- packages/@aws-cdk/aws-logs/lib/log-stream.ts | 134 +- .../@aws-cdk/aws-logs/lib/metric-filter.ts | 118 +- packages/@aws-cdk/aws-logs/lib/pattern.ts | 678 +- .../aws-logs/lib/subscription-filter.ts | 90 +- .../aws-logs/test/example.retention.lit.ts | 28 +- .../aws-logs/test/integ.metricfilter.lit.ts | 30 +- .../aws-logs/test/test.destination.ts | 100 +- .../@aws-cdk/aws-logs/test/test.loggroup.ts | 226 +- packages/@aws-cdk/aws-logs/test/test.logs.ts | 8 +- .../@aws-cdk/aws-logs/test/test.logstream.ts | 26 +- .../aws-logs/test/test.metricfilter.ts | 48 +- .../@aws-cdk/aws-logs/test/test.pattern.ts | 200 +- .../aws-logs/test/test.subscriptionfilter.ts | 46 +- packages/@aws-cdk/aws-neptune/lib/index.ts | 250 +- .../@aws-cdk/aws-neptune/test/test.neptune.ts | 30 +- .../aws-opsworks/test/test.opsworks.ts | 8 +- .../@aws-cdk/aws-quickstarts/lib/database.ts | 84 +- packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts | 90 +- .../lib/cluster-parameter-group-ref.ts | 50 +- .../aws-rds/lib/cluster-parameter-group.ts | 102 +- packages/@aws-cdk/aws-rds/lib/cluster-ref.ts | 334 +- packages/@aws-cdk/aws-rds/lib/cluster.ts | 400 +- packages/@aws-cdk/aws-rds/lib/props.ts | 82 +- .../@aws-cdk/aws-rds/test/integ.cluster.ts | 28 +- .../@aws-cdk/aws-rds/test/test.cluster.ts | 240 +- .../aws-redshift/test/test.redshift.ts | 8 +- .../aws-route53/lib/hosted-zone-ref.ts | 78 +- .../@aws-cdk/aws-route53/lib/hosted-zone.ts | 188 +- .../@aws-cdk/aws-route53/lib/records/_util.ts | 26 +- .../@aws-cdk/aws-route53/lib/records/txt.ts | 34 +- .../lib/records/zone-delegation.ts | 64 +- packages/@aws-cdk/aws-route53/lib/util.ts | 30 +- .../aws-route53/test/integ.route53.ts | 10 +- .../@aws-cdk/aws-route53/test/test.route53.ts | 218 +- .../aws-route53/test/test.txt-record.ts | 80 +- .../@aws-cdk/aws-route53/test/test.util.ts | 18 +- .../test/test.zone-delegation-record.ts | 86 +- .../aws-s3-notifications/lib/destination.ts | 50 +- .../aws-s3-notifications/lib/index.ts | 2 +- packages/@aws-cdk/aws-s3/lib/bucket-policy.ts | 40 +- packages/@aws-cdk/aws-s3/lib/bucket.ts | 1254 +- .../lib/notifications-resource/index.ts | 2 +- .../notifications-resource-handler.ts | 238 +- .../notifications-resource.ts | 228 +- packages/@aws-cdk/aws-s3/lib/perms.ts | 26 +- .../@aws-cdk/aws-s3/lib/pipeline-action.ts | 72 +- packages/@aws-cdk/aws-s3/lib/rule.ts | 292 +- packages/@aws-cdk/aws-s3/lib/util.ts | 76 +- .../aws-s3/test/demo.import-export.ts | 40 +- packages/@aws-cdk/aws-s3/test/integ.bucket.ts | 4 +- .../aws-s3/test/integ.bucket.url.lit.ts | 16 +- .../@aws-cdk/aws-s3/test/integ.lifecycle.ts | 6 +- .../aws-s3/test/integ.notifications.ts | 2 +- .../aws-s3/test/notification-dests.ts | 74 +- packages/@aws-cdk/aws-s3/test/test.bucket.ts | 1874 +-- .../aws-s3/test/test.notifications.ts | 566 +- packages/@aws-cdk/aws-s3/test/test.rules.ts | 248 +- packages/@aws-cdk/aws-s3/test/test.util.ts | 118 +- .../aws-sagemaker/test/test.sagemaker.ts | 8 +- packages/@aws-cdk/aws-sam/test/test.sam.ts | 8 +- packages/@aws-cdk/aws-sdb/test/test.sdb.ts | 8 +- .../aws-serverless/test/test.serverless.ts | 8 +- .../test/test.servicecatalog.ts | 8 +- .../test/test.servicediscovery.ts | 8 +- packages/@aws-cdk/aws-ses/test/test.ses.ts | 8 +- .../sns-codecommit-event-rule-target.lit.ts | 32 +- packages/@aws-cdk/aws-sns/lib/policy.ts | 40 +- packages/@aws-cdk/aws-sns/lib/subscription.ts | 108 +- packages/@aws-cdk/aws-sns/lib/topic-ref.ts | 580 +- packages/@aws-cdk/aws-sns/lib/topic.ts | 56 +- .../test/integ.sns-bucket-notifications.ts | 18 +- .../test/integ.sns-event-rule-target.ts | 2 +- .../@aws-cdk/aws-sns/test/integ.sns-lambda.ts | 32 +- .../aws-sns/test/integ.sns-sqs.lit.ts | 16 +- packages/@aws-cdk/aws-sns/test/integ.sns.ts | 14 +- packages/@aws-cdk/aws-sns/test/test.sns.ts | 1378 +- packages/@aws-cdk/aws-sqs/lib/policy.ts | 40 +- packages/@aws-cdk/aws-sqs/lib/queue-ref.ts | 256 +- packages/@aws-cdk/aws-sqs/lib/queue.ts | 550 +- .../@aws-cdk/aws-sqs/lib/validate-props.ts | 20 +- .../test/integ.bucket-notifications.ts | 2 +- packages/@aws-cdk/aws-sqs/test/integ.sqs.ts | 4 +- packages/@aws-cdk/aws-sqs/test/test.sqs.ts | 706 +- packages/@aws-cdk/aws-ssm/test/test.ssm.ts | 8 +- .../test/test.stepfunctions.ts | 8 +- packages/@aws-cdk/aws-waf/test/test.waf.ts | 8 +- .../aws-wafregional/test/test.wafregional.ts | 8 +- .../aws-workspaces/test/test.workspaces.ts | 8 +- packages/@aws-cdk/cdk/lib/app.ts | 412 +- .../@aws-cdk/cdk/lib/cloudformation/arn.ts | 542 +- .../lib/cloudformation/cloudformation-json.ts | 134 +- .../cloudformation/cloudformation-token.ts | 24 +- .../cdk/lib/cloudformation/condition.ts | 40 +- .../@aws-cdk/cdk/lib/cloudformation/fn.ts | 418 +- .../cdk/lib/cloudformation/include.ts | 46 +- .../cdk/lib/cloudformation/logical-id.ts | 166 +- .../cdk/lib/cloudformation/mapping.ts | 70 +- .../@aws-cdk/cdk/lib/cloudformation/output.ts | 392 +- .../cdk/lib/cloudformation/parameter.ts | 216 +- .../cdk/lib/cloudformation/permission.ts | 588 +- .../@aws-cdk/cdk/lib/cloudformation/pseudo.ts | 60 +- .../cdk/lib/cloudformation/removal-policy.ts | 48 +- .../cdk/lib/cloudformation/resource-policy.ts | 286 +- .../cdk/lib/cloudformation/resource.ts | 326 +- .../@aws-cdk/cdk/lib/cloudformation/rule.ts | 122 +- .../@aws-cdk/cdk/lib/cloudformation/secret.ts | 102 +- .../@aws-cdk/cdk/lib/cloudformation/stack.ts | 696 +- .../@aws-cdk/cdk/lib/cloudformation/tag.ts | 18 +- packages/@aws-cdk/cdk/lib/context.ts | 236 +- packages/@aws-cdk/cdk/lib/core/construct.ts | 764 +- packages/@aws-cdk/cdk/lib/core/jsx.ts | 124 +- packages/@aws-cdk/cdk/lib/core/tag-manager.ts | 328 +- packages/@aws-cdk/cdk/lib/core/tokens.ts | 638 +- packages/@aws-cdk/cdk/lib/core/util.ts | 54 +- packages/@aws-cdk/cdk/lib/environment.ts | 20 +- packages/@aws-cdk/cdk/lib/runtime.ts | 374 +- packages/@aws-cdk/cdk/lib/util/uniqueid.ts | 52 +- .../cdk/test/cloudformation/evaluate-cfn.ts | 102 +- .../cdk/test/cloudformation/test.arn.ts | 398 +- .../test.cloudformation-json.ts | 248 +- .../cdk/test/cloudformation/test.fn.ts | 10 +- .../cdk/test/cloudformation/test.include.ts | 132 +- .../test/cloudformation/test.logical-id.ts | 414 +- .../cdk/test/cloudformation/test.mappings.ts | 74 +- .../cdk/test/cloudformation/test.output.ts | 110 +- .../cdk/test/cloudformation/test.parameter.ts | 54 +- .../cdk/test/cloudformation/test.perms.ts | 354 +- .../cdk/test/cloudformation/test.resource.ts | 696 +- .../cdk/test/cloudformation/test.rule.ts | 44 +- .../cdk/test/cloudformation/test.secret.ts | 90 +- .../cdk/test/cloudformation/test.stack.ts | 338 +- .../@aws-cdk/cdk/test/core/test.construct.ts | 796 +- .../cdk/test/core/test.tag-manager.ts | 312 +- .../@aws-cdk/cdk/test/core/test.tokens.ts | 562 +- packages/@aws-cdk/cdk/test/core/test.util.ts | 112 +- packages/@aws-cdk/cdk/test/test.app.ts | 604 +- packages/@aws-cdk/cdk/test/test.context.ts | 102 +- .../@aws-cdk/cdk/test/test.environment.ts | 56 +- .../@aws-cdk/cfnspec/build-tools/build.ts | 134 +- .../@aws-cdk/cfnspec/build-tools/spec-diff.ts | 334 +- packages/@aws-cdk/cfnspec/lib/index.ts | 48 +- .../@aws-cdk/cfnspec/lib/schema/base-types.ts | 42 +- .../@aws-cdk/cfnspec/lib/schema/property.ts | 154 +- .../cfnspec/lib/schema/resource-type.ts | 66 +- .../cfnspec/lib/schema/specification.ts | 34 +- .../@aws-cdk/cfnspec/test/spec-validators.ts | 230 +- .../test/test.filtered-specification.ts | 40 +- .../@aws-cdk/cfnspec/test/test.namespaces.ts | 148 +- .../cloudformation-diff/lib/diff-template.ts | 68 +- .../cloudformation-diff/lib/diff/index.ts | 110 +- .../cloudformation-diff/lib/diff/types.ts | 362 +- .../cloudformation-diff/lib/diff/util.ts | 78 +- .../cloudformation-diff/lib/format.ts | 328 +- .../@aws-cdk/cloudformation-diff/lib/index.ts | 2 +- .../test/test.diff-template.ts | 482 +- packages/@aws-cdk/cx-api/lib/cxapi.ts | 120 +- packages/@aws-cdk/cx-api/lib/environment.ts | 12 +- packages/@aws-cdk/runtime-values/lib/index.ts | 2 +- packages/@aws-cdk/runtime-values/lib/rtv.ts | 124 +- .../runtime-values/test/integ.rtv.lambda.ts | 48 +- .../@aws-cdk/runtime-values/test/test.rtv.ts | 86 +- packages/aws-cdk/bin/cdk.ts | 1334 +- .../aws-cdk/lib/api/aws-auth/credentials.ts | 38 +- .../aws-cdk/lib/api/bootstrap-environment.ts | 58 +- packages/aws-cdk/lib/api/deploy-stack.ts | 170 +- packages/aws-cdk/lib/api/toolkit-info.ts | 168 +- .../aws-cdk/lib/api/util/account-cache.ts | 126 +- .../aws-cdk/lib/api/util/cloudformation.ts | 148 +- .../cloudformation/stack-activity-monitor.ts | 430 +- .../api/util/cloudformation/stack-status.ts | 54 +- packages/aws-cdk/lib/api/util/sdk.ts | 516 +- packages/aws-cdk/lib/api/util/sdk_ini_file.ts | 42 +- packages/aws-cdk/lib/archive.ts | 24 +- packages/aws-cdk/lib/assets.ts | 142 +- packages/aws-cdk/lib/commands/docs.ts | 44 +- packages/aws-cdk/lib/commands/doctor.ts | 38 +- packages/aws-cdk/lib/contextplugins.ts | 66 +- packages/aws-cdk/lib/diff.ts | 14 +- .../app/dotnet/add-project.hook.ts | 42 +- .../app/typescript/bin/%name%.template.ts | 16 +- .../lib/typescript/lib/index.template.ts | 34 +- packages/aws-cdk/lib/init.ts | 394 +- packages/aws-cdk/lib/interactive.ts | 80 +- packages/aws-cdk/lib/logging.ts | 24 +- packages/aws-cdk/lib/plugin.ts | 116 +- packages/aws-cdk/lib/renames.ts | 100 +- packages/aws-cdk/lib/settings.ts | 116 +- packages/aws-cdk/lib/util/arrays.ts | 22 +- packages/aws-cdk/lib/util/objects.ts | 118 +- packages/aws-cdk/lib/util/types.ts | 6 +- packages/aws-cdk/test/test.account-cache.ts | 154 +- packages/aws-cdk/test/test.archive.ts | 60 +- packages/aws-cdk/test/test.assets.ts | 78 +- packages/aws-cdk/test/test.cdk-docs.ts | 80 +- packages/aws-cdk/test/test.cdk-doctor.ts | 46 +- packages/aws-cdk/test/test.init.ts | 80 +- .../aws-cdk/test/util/test.applydefaults.ts | 14 +- packages/aws-cdk/test/util/test.arrays.ts | 44 +- packages/aws-cdk/test/util/test.objects.ts | 82 +- .../simple-resource-bundler/bin/bundler.ts | 66 +- tools/cdk-build-tools/bin/cdk-build.ts | 72 +- tools/cdk-build-tools/bin/cdk-package.ts | 92 +- tools/cdk-build-tools/bin/cdk-test.ts | 112 +- tools/cdk-build-tools/bin/cdk-watch.ts | 38 +- tools/cdk-build-tools/lib/compile.ts | 50 +- tools/cdk-build-tools/lib/ignore-list.ts | 2 +- tools/cdk-build-tools/lib/os.ts | 126 +- tools/cdk-build-tools/lib/package-info.ts | 104 +- tools/cdk-build-tools/lib/timer.ts | 116 +- tools/cdk-integ-tools/bin/cdk-integ-assert.ts | 46 +- tools/cdk-integ-tools/bin/cdk-integ.ts | 74 +- tools/cdk-integ-tools/lib/integ-helpers.ts | 174 +- tools/cfn2ts/bin/cfn2ts.ts | 18 +- tools/cfn2ts/lib/codegen.ts | 1082 +- tools/cfn2ts/lib/genspec.ts | 410 +- tools/cfn2ts/lib/index.ts | 32 +- tools/cfn2ts/lib/spec-utils.ts | 138 +- tools/cfn2ts/lib/util.ts | 10 +- tools/cfn2ts/module-template/lib/registry.ts | 22 +- tools/cfn2ts/module-template/lib/runtime.ts | 358 +- .../aws.apigateway.AuthorizerProps.ts | 6 +- ...way.Deployment.StageDescriptionProperty.ts | 6 +- .../cfn2ts/test/enrichments/aws.sqs.Queue.ts | 6 +- .../enrichments/aws.sqs.QueueArnAttribute.ts | 6 +- tools/cfn2ts/test/test.gen.ts | 38 +- tools/merkle-build/lib/calculate.ts | 170 +- tools/merkle-build/lib/change-detector.ts | 48 +- tools/merkle-build/lib/file-ops.ts | 22 +- tools/pkglint/bin/pkglint.ts | 42 +- tools/pkglint/lib/index.ts | 2 +- tools/pkglint/lib/licensing.ts | 2 +- tools/pkglint/lib/packagejson.ts | 420 +- tools/pkglint/lib/rules.ts | 624 +- tools/pkglint/lib/util.ts | 156 +- tools/pkgtools/bin/find-jsii-packages.ts | 184 +- tools/y-npm/bin/y-npm.ts | 74 +- .../y-npm/lib/determine-storage-directory.ts | 50 +- tools/y-npm/lib/find-all-packages.ts | 38 +- tools/y-npm/lib/logging.ts | 12 +- tools/y-npm/lib/run-npm-command.ts | 138 +- tools/y-npm/lib/start-verdaccio.ts | 104 +- tools/y-npm/lib/with-temporary-file.ts | 16 +- 509 files changed, 53501 insertions(+), 53501 deletions(-) diff --git a/examples/cdk-examples-typescript/advanced-usage/index.ts b/examples/cdk-examples-typescript/advanced-usage/index.ts index 8b5caf2362f8b..6bc453eb5b1fd 100644 --- a/examples/cdk-examples-typescript/advanced-usage/index.ts +++ b/examples/cdk-examples-typescript/advanced-usage/index.ts @@ -10,25 +10,25 @@ import cdk = require('@aws-cdk/cdk'); * This stack demonstrates the use of the IAM policy library shipped with the CDK. */ class PolicyExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - // here's how to create an IAM Role with an assume policy for the Lambda - // service principal. - const role = new iam.Role(this, 'Role', { - assumedBy: new cdk.ServicePrincipal('lambda.amazon.aws.com') - }); - - // when you call `addToPolicy`, a default policy is defined and attached - // to the bucket. - const bucket = new s3.Bucket(this, 'MyBucket'); - - // the role also has a policy attached to it. - role.addToPolicy(new cdk.PolicyStatement() - .addResource(bucket.arnForObjects('*')) - .addResource(bucket.bucketArn) - .addActions('s3:*')); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + // here's how to create an IAM Role with an assume policy for the Lambda + // service principal. + const role = new iam.Role(this, 'Role', { + assumedBy: new cdk.ServicePrincipal('lambda.amazon.aws.com') + }); + + // when you call `addToPolicy`, a default policy is defined and attached + // to the bucket. + const bucket = new s3.Bucket(this, 'MyBucket'); + + // the role also has a policy attached to it. + role.addToPolicy(new cdk.PolicyStatement() + .addResource(bucket.arnForObjects('*')) + .addResource(bucket.bucketArn) + .addActions('s3:*')); + } } /** @@ -38,29 +38,29 @@ class PolicyExample extends cdk.Stack { * the AZ list and the AMI IDs are different. */ class EnvContextExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - // get the list of AZs for the current region/account - const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones; + // get the list of AZs for the current region/account + const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones; - // get the AMI ID for a specific Windows version in this region - const ami = new ec2.WindowsImage(ec2.WindowsVersion.WindowsServer2016EnglishNanoBase).getImage(this); + // get the AMI ID for a specific Windows version in this region + const ami = new ec2.WindowsImage(ec2.WindowsVersion.WindowsServer2016EnglishNanoBase).getImage(this); - for (const az of azs) { - if (typeof(az) !== 'string') { - continue; - } + for (const az of azs) { + if (typeof(az) !== 'string') { + continue; + } - // render construct name based on it's availablity zone - const constructName = `InstanceFor${az.replace(/-/g, '').toUpperCase()}`; + // render construct name based on it's availablity zone + const constructName = `InstanceFor${az.replace(/-/g, '').toUpperCase()}`; - new ec2.cloudformation.InstanceResource(this, constructName, { - imageId: ami.imageId, - availabilityZone: az, - }); - } + new ec2.cloudformation.InstanceResource(this, constructName, { + imageId: ami.imageId, + availabilityZone: az, + }); } + } } /** @@ -68,53 +68,53 @@ class EnvContextExample extends cdk.Stack { * into your CDK stack and then add constructs and resources programmatically to it. */ class IncludeExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - // so you have an existing template... - // you can also load it from a file: - // const template = JSON.parse(fs.readFileSync('./my-template.json).toString()); - const template = { - Resources: { - IncludedQueue: { - Type: "AWS::SQS::Queue", - Properties: { - VisibilityTimeout: 300 - } - } - } - }; - - // merge template as-is into the stack - new cdk.Include(this, 'Include', { template }); - - // add constructs (and resources) programmatically - new EnvContextExample(parent, 'Example'); - new sqs.cloudformation.QueueResource(this, 'CDKQueue', {}); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + // so you have an existing template... + // you can also load it from a file: + // const template = JSON.parse(fs.readFileSync('./my-template.json).toString()); + const template = { + Resources: { + IncludedQueue: { + Type: "AWS::SQS::Queue", + Properties: { + VisibilityTimeout: 300 + } + } + } + }; + + // merge template as-is into the stack + new cdk.Include(this, 'Include', { template }); + + // add constructs (and resources) programmatically + new EnvContextExample(parent, 'Example'); + new sqs.cloudformation.QueueResource(this, 'CDKQueue', {}); + } } class NestedStackExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - // pick up to 3 AZs from environment. - const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones.slice(0, 3); - - // add an "AWS::CloudFormation::Stack" resource which uses the MongoDB quickstart - // https://aws.amazon.com/quickstart/architecture/mongodb/ - // only non-default values are provided here. - new cloudformation.StackResource(this, 'NestedStack', { - templateUrl: 'https://s3.amazonaws.com/quickstart-reference/mongodb/latest/templates/mongodb-master.template', - parameters: { - KeyPairName: 'my-key-pair', - RemoteAccessCIDR: '0.0.0.0/0', - AvailabilityZones: azs.join(','), - NumberOfAZs: azs.length.toString(), - MongoDBAdminPassword: 'root1234', - } - }); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + // pick up to 3 AZs from environment. + const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones.slice(0, 3); + + // add an "AWS::CloudFormation::Stack" resource which uses the MongoDB quickstart + // https://aws.amazon.com/quickstart/architecture/mongodb/ + // only non-default values are provided here. + new cloudformation.StackResource(this, 'NestedStack', { + templateUrl: 'https://s3.amazonaws.com/quickstart-reference/mongodb/latest/templates/mongodb-master.template', + parameters: { + KeyPairName: 'my-key-pair', + RemoteAccessCIDR: '0.0.0.0/0', + AvailabilityZones: azs.join(','), + NumberOfAZs: azs.length.toString(), + MongoDBAdminPassword: 'root1234', + } + }); + } } /** @@ -122,70 +122,70 @@ class NestedStackExample extends cdk.Stack { * It also demonstrates how to modify resource options such as metadata */ class ResourceReferencesExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - const topic = new sns.cloudformation.TopicResource(this, 'Topic', {}); - const queue = new sqs.cloudformation.QueueResource(this, 'Queue', {}); - - new sns.cloudformation.SubscriptionResource(this, 'Subscription', { - topicArn: topic.ref, // resolves to { Ref: } - protocol: 'sqs', - endpoint: queue.queueArn // resolves to { "Fn::GetAtt": [ , "Arn" ] } - }); - - // resource.options can be used to set options on a resource construct - queue.options.metadata = { - MyKey: "MyValue" - }; - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + const topic = new sns.cloudformation.TopicResource(this, 'Topic', {}); + const queue = new sqs.cloudformation.QueueResource(this, 'Queue', {}); + + new sns.cloudformation.SubscriptionResource(this, 'Subscription', { + topicArn: topic.ref, // resolves to { Ref: } + protocol: 'sqs', + endpoint: queue.queueArn // resolves to { "Fn::GetAtt": [ , "Arn" ] } + }); + + // resource.options can be used to set options on a resource construct + queue.options.metadata = { + MyKey: "MyValue" + }; + } } /** * Demonstrates how to use CloudFormation parameters, outputs, pseudo parameters and intrinsic functions. */ class CloudFormationExample extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - // parameters are constructs that synthesize into the template's "Parameters" section - const param = new cdk.Parameter(this, 'MyTemplateParameter', { - type: 'String', - default: 'HelloWorld' - }); - - // outputs are constructs the synthesize into the template's "Outputs" section - new cdk.Output(this, 'Output', { - description: 'This is an output of the template', - value: new cdk.FnConcat(new cdk.AwsAccountId(), '/', param.ref) - }); - - // stack.templateOptions can be used to specify template-level options - this.templateOptions.description = 'This goes into the "Description" attribute of the template'; - this.templateOptions.metadata = { - - // all CloudFormation's pseudo-parameters are supported via the `cdk.AwsXxx` classes - PseudoParameters: [ - new cdk.AwsAccountId(), - new cdk.AwsDomainSuffix(), - new cdk.AwsNotificationARNs(), - new cdk.AwsNoValue(), - new cdk.AwsPartition(), - new cdk.AwsRegion(), - new cdk.AwsStackId(), - new cdk.AwsStackName(), - ], - - // all CloudFormation's intrinsic functions are supported via the `cdk.FnXxx` classes - IntrinsicFunctions: [ - new cdk.FnAnd( - new cdk.FnFindInMap('MyMap', 'K1', 'K2'), - new cdk.FnSub('hello ${world}', { - world: new cdk.FnBase64(param.ref) // resolves to { Ref: } - })) - ], - }; - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + // parameters are constructs that synthesize into the template's "Parameters" section + const param = new cdk.Parameter(this, 'MyTemplateParameter', { + type: 'String', + default: 'HelloWorld' + }); + + // outputs are constructs the synthesize into the template's "Outputs" section + new cdk.Output(this, 'Output', { + description: 'This is an output of the template', + value: new cdk.FnConcat(new cdk.AwsAccountId(), '/', param.ref) + }); + + // stack.templateOptions can be used to specify template-level options + this.templateOptions.description = 'This goes into the "Description" attribute of the template'; + this.templateOptions.metadata = { + + // all CloudFormation's pseudo-parameters are supported via the `cdk.AwsXxx` classes + PseudoParameters: [ + new cdk.AwsAccountId(), + new cdk.AwsDomainSuffix(), + new cdk.AwsNotificationARNs(), + new cdk.AwsNoValue(), + new cdk.AwsPartition(), + new cdk.AwsRegion(), + new cdk.AwsStackId(), + new cdk.AwsStackName(), + ], + + // all CloudFormation's intrinsic functions are supported via the `cdk.FnXxx` classes + IntrinsicFunctions: [ + new cdk.FnAnd( + new cdk.FnFindInMap('MyMap', 'K1', 'K2'), + new cdk.FnSub('hello ${world}', { + world: new cdk.FnBase64(param.ref) // resolves to { Ref: } + })) + ], + }; + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/bucket-import-export/index.ts b/examples/cdk-examples-typescript/bucket-import-export/index.ts index 1df1c56805ba5..03811a8059b21 100644 --- a/examples/cdk-examples-typescript/bucket-import-export/index.ts +++ b/examples/cdk-examples-typescript/bucket-import-export/index.ts @@ -7,26 +7,26 @@ import cdk = require('@aws-cdk/cdk'); // `Bucket.import`. class Producer extends cdk.Stack { - public readonly myBucketRef: s3.BucketRefProps; + public readonly myBucketRef: s3.BucketRefProps; - constructor(parent: cdk.App, name: string) { - super(parent, name); + constructor(parent: cdk.App, name: string) { + super(parent, name); - const bucket = new s3.Bucket(this, 'MyBucket'); - this.myBucketRef = bucket.export(); - } + const bucket = new s3.Bucket(this, 'MyBucket'); + this.myBucketRef = bucket.export(); + } } interface ConsumerConstructProps { - bucket: s3.BucketRef; + bucket: s3.BucketRef; } class ConsumerConstruct extends cdk.Construct { - constructor(parent: cdk.Construct, name: string, props: ConsumerConstructProps) { - super(parent, name); + constructor(parent: cdk.Construct, name: string, props: ConsumerConstructProps) { + super(parent, name); - props.bucket.addToResourcePolicy(new cdk.PolicyStatement().addAction('*')); - } + props.bucket.addToResourcePolicy(new cdk.PolicyStatement().addAction('*')); + } } // Define a stack that requires a BucketRef as an input and uses `Bucket.import` @@ -35,20 +35,20 @@ class ConsumerConstruct extends cdk.Construct { // this bucket and contents. interface ConsumerProps { - userBucketRef: s3.BucketRefProps; + userBucketRef: s3.BucketRefProps; } class Consumer extends cdk.Stack { - constructor(parent: cdk.App, name: string, props: ConsumerProps) { - super(parent, name); + constructor(parent: cdk.App, name: string, props: ConsumerProps) { + super(parent, name); - const user = new iam.User(this, 'MyUser'); - const userBucket = s3.Bucket.import(this, 'ImportBucket', props.userBucketRef); + const user = new iam.User(this, 'MyUser'); + const userBucket = s3.Bucket.import(this, 'ImportBucket', props.userBucketRef); - new ConsumerConstruct(this, 'SomeConstruct', { bucket: userBucket }); + new ConsumerConstruct(this, 'SomeConstruct', { bucket: userBucket }); - userBucket.grantReadWrite(user); - } + userBucket.grantReadWrite(user); + } } // ------------------------------------------------------- @@ -62,7 +62,7 @@ const app = new cdk.App(process.argv); const producer = new Producer(app, 'produce'); new Consumer(app, 'consume', { - userBucketRef: producer.myBucketRef + userBucketRef: producer.myBucketRef }); process.stdout.write(app.run()); diff --git a/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts b/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts index 87e25158452ba..74d3c5bd77981 100644 --- a/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts +++ b/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts @@ -2,35 +2,35 @@ import cognito = require('@aws-cdk/aws-cognito'); import cdk = require('@aws-cdk/cdk'); export class CognitoChatRoomPool extends cdk.Construct { - constructor(parent: cdk.Construct, name: string) { - super(parent, name); + constructor(parent: cdk.Construct, name: string) { + super(parent, name); - // Create chat room user pool - const chatPool = new cognito.cloudformation.UserPoolResource(this, 'UserPool', { - adminCreateUserConfig: { - allowAdminCreateUserOnly: false - }, - policies: { - passwordPolicy: { - minimumLength: 6, - requireNumbers: true - } }, - schema: [ - { - attributeDataType: 'String', - name: 'email', - required: true - } - ], - autoVerifiedAttributes: [ 'email' ] - }); + // Create chat room user pool + const chatPool = new cognito.cloudformation.UserPoolResource(this, 'UserPool', { + adminCreateUserConfig: { + allowAdminCreateUserOnly: false + }, + policies: { + passwordPolicy: { + minimumLength: 6, + requireNumbers: true + } }, + schema: [ + { + attributeDataType: 'String', + name: 'email', + required: true + } + ], + autoVerifiedAttributes: [ 'email' ] + }); - // Now for the client - new cognito.cloudformation.UserPoolClientResource(this, 'UserPoolClient', { - clientName: 'Chat-Room', - explicitAuthFlows: [ 'ADMIN_NO_SRP_AUTH' ], - refreshTokenValidity: 30, - userPoolId: chatPool.ref - }); - } + // Now for the client + new cognito.cloudformation.UserPoolClientResource(this, 'UserPoolClient', { + clientName: 'Chat-Room', + explicitAuthFlows: [ 'ADMIN_NO_SRP_AUTH' ], + refreshTokenValidity: 30, + userPoolId: chatPool.ref + }); + } } diff --git a/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts b/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts index 0a92f6ab9927a..4964eb58b485c 100644 --- a/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts +++ b/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts @@ -2,14 +2,14 @@ import dynamodb = require('@aws-cdk/aws-dynamodb'); import cdk = require('@aws-cdk/cdk'); export class DynamoPostsTable extends cdk.Construct { - constructor(parent: cdk.Construct, name: string) { - super(parent, name); + constructor(parent: cdk.Construct, name: string) { + super(parent, name); - const table = new dynamodb.Table(this, 'Table', { - readCapacity: 5, writeCapacity: 5 - }); + const table = new dynamodb.Table(this, 'Table', { + readCapacity: 5, writeCapacity: 5 + }); - table.addPartitionKey({ name: 'Alias', type: dynamodb.AttributeType.String }); - table.addSortKey({ name: 'Timestamp', type: dynamodb.AttributeType.String }); - } + table.addPartitionKey({ name: 'Alias', type: dynamodb.AttributeType.String }); + table.addSortKey({ name: 'Timestamp', type: dynamodb.AttributeType.String }); + } } diff --git a/examples/cdk-examples-typescript/chat-app/index.ts b/examples/cdk-examples-typescript/chat-app/index.ts index a87fae99d73ba..bb2d8deef5bd5 100644 --- a/examples/cdk-examples-typescript/chat-app/index.ts +++ b/examples/cdk-examples-typescript/chat-app/index.ts @@ -5,85 +5,85 @@ import { CognitoChatRoomPool } from './cognito-chat-room-pool'; import { DynamoPostsTable } from './dynamodb-posts-table'; class MyStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - new DynamoPostsTable(this, 'Posts'); - - new CognitoChatRoomPool(this, 'UserPool'); - - const bucket = s3.BucketRef.import(this, 'DougsBucket', { - bucketName: 'dougs-chat-app' - }); - - new ChatAppFunction(this, 'StartAddBucket', { - bucket, - zipFile: 'StartAddingPendingCognitoUser.zip' - }); - - new ChatAppFunction(this, 'FinishAddBucket', { - bucket, - zipFile: 'FinishAddingPendingCognitoUser.zip' - }); - - new ChatAppFunction(this, 'SignInUserBucket', { - bucket, - zipFile: 'SignInCognitoUser.zip' - }); - - new ChatAppFunction(this, 'VerifyBucket', { - bucket, - zipFile: 'VerifyCognitoSignIn.zip' - }); - - new ChatAppFunction(this, 'StartChangeBucket', { - bucket, - zipFile: 'StartChangingForgottenCognitoUserPassword.zip' - }); - - new ChatAppFunction(this, 'FinishChangeBucket', { - bucket, - zipFile: 'FinishChangingForgottenCognitoUserPassword.zip' - }); - - new ChatAppFunction(this, 'GetPostsBucket', { - bucket, - zipFile: 'GetPosts.zip' - }); - - new ChatAppFunction(this, 'AddPostBucket', { - bucket, - zipFile: 'AddPost.zip' - }); - - new ChatAppFunction(this, 'DeletePostBucket', { - bucket, - zipFile: 'DeletePost.zip' - }); - - new ChatAppFunction(this, 'DeleteUserBucket', { - bucket, - zipFile: 'DeleteCognitoUser.zip' - }); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + new DynamoPostsTable(this, 'Posts'); + + new CognitoChatRoomPool(this, 'UserPool'); + + const bucket = s3.BucketRef.import(this, 'DougsBucket', { + bucketName: 'dougs-chat-app' + }); + + new ChatAppFunction(this, 'StartAddBucket', { + bucket, + zipFile: 'StartAddingPendingCognitoUser.zip' + }); + + new ChatAppFunction(this, 'FinishAddBucket', { + bucket, + zipFile: 'FinishAddingPendingCognitoUser.zip' + }); + + new ChatAppFunction(this, 'SignInUserBucket', { + bucket, + zipFile: 'SignInCognitoUser.zip' + }); + + new ChatAppFunction(this, 'VerifyBucket', { + bucket, + zipFile: 'VerifyCognitoSignIn.zip' + }); + + new ChatAppFunction(this, 'StartChangeBucket', { + bucket, + zipFile: 'StartChangingForgottenCognitoUserPassword.zip' + }); + + new ChatAppFunction(this, 'FinishChangeBucket', { + bucket, + zipFile: 'FinishChangingForgottenCognitoUserPassword.zip' + }); + + new ChatAppFunction(this, 'GetPostsBucket', { + bucket, + zipFile: 'GetPosts.zip' + }); + + new ChatAppFunction(this, 'AddPostBucket', { + bucket, + zipFile: 'AddPost.zip' + }); + + new ChatAppFunction(this, 'DeletePostBucket', { + bucket, + zipFile: 'DeletePost.zip' + }); + + new ChatAppFunction(this, 'DeleteUserBucket', { + bucket, + zipFile: 'DeleteCognitoUser.zip' + }); + } } interface ChatAppFuncProps { - bucket: s3.BucketRef; - zipFile: string; + bucket: s3.BucketRef; + zipFile: string; } /* * Extend Function as all of the Chat app functions have these common props. */ class ChatAppFunction extends lambda.Function { - constructor(parent: cdk.Construct, name: string, props: ChatAppFuncProps) { - super(parent, name, { - code: new lambda.S3Code(props.bucket, props.zipFile), - runtime: lambda.Runtime.NodeJS610, - handler: 'index.handler' - }); - } + constructor(parent: cdk.Construct, name: string, props: ChatAppFuncProps) { + super(parent, name, { + code: new lambda.S3Code(props.bucket, props.zipFile), + runtime: lambda.Runtime.NodeJS610, + handler: 'index.handler' + }); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/cloudformation/index.ts b/examples/cdk-examples-typescript/cloudformation/index.ts index dcde332a827bf..10ff49dfe3580 100644 --- a/examples/cdk-examples-typescript/cloudformation/index.ts +++ b/examples/cdk-examples-typescript/cloudformation/index.ts @@ -2,13 +2,13 @@ import sqs = require('@aws-cdk/aws-sqs'); import cdk = require('@aws-cdk/cdk'); class CloudFormationExample extends cdk.Stack { - constructor(parent: cdk.App) { - super(parent); + constructor(parent: cdk.App) { + super(parent); - new sqs.cloudformation.QueueResource(this, 'MyQueue', { - visibilityTimeout: 300 - }); - } + new sqs.cloudformation.QueueResource(this, 'MyQueue', { + visibilityTimeout: 300 + }); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/custom-resource/index.ts b/examples/cdk-examples-typescript/custom-resource/index.ts index 0b0db906ecf3c..24cc28c1aae60 100644 --- a/examples/cdk-examples-typescript/custom-resource/index.ts +++ b/examples/cdk-examples-typescript/custom-resource/index.ts @@ -5,72 +5,72 @@ import cdk = require('@aws-cdk/cdk'); import fs = require('fs'); interface DemoResourceProps { - /** - * Message to echo - */ - message: string; - - /** - * Set this to true to fail the CREATE invocation - */ - failCreate?: boolean; + /** + * Message to echo + */ + message: string; + + /** + * Set this to true to fail the CREATE invocation + */ + failCreate?: boolean; } class DemoResource extends cdk.Construct implements cdk.IDependable { - public readonly dependencyElements: cdk.IDependable[]; - public readonly response: string; - - constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { - super(parent, name); - - const resource = new CustomResource(this, 'Resource', { - lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { - uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc', - // This makes the demo only work as top-level TypeScript program, but that's fine for now - code: lambda.Code.inline(fs.readFileSync('provider.py', { encoding: 'utf-8' })), - handler: 'index.main', - timeout: 300, - runtime: lambda.Runtime.Python27, - }), - properties: props - }); - - this.response = resource.getAtt('Response').toString(); - this.dependencyElements = [resource]; - } + public readonly dependencyElements: cdk.IDependable[]; + public readonly response: string; + + constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { + super(parent, name); + + const resource = new CustomResource(this, 'Resource', { + lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { + uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc', + // This makes the demo only work as top-level TypeScript program, but that's fine for now + code: lambda.Code.inline(fs.readFileSync('provider.py', { encoding: 'utf-8' })), + handler: 'index.main', + timeout: 300, + runtime: lambda.Runtime.Python27, + }), + properties: props + }); + + this.response = resource.getAtt('Response').toString(); + this.dependencyElements = [resource]; + } } /** * A stack that only sets up the CustomResource and shows how to get an attribute from it */ class SucceedingStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - const resource = new DemoResource(this, 'DemoResource', { - message: 'CustomResource says hello', - }); - - // Publish the custom resource output - new cdk.Output(this, 'ResponseMessage', { - description: 'The message that came back from the Custom Resource', - value: resource.response - }); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + const resource = new DemoResource(this, 'DemoResource', { + message: 'CustomResource says hello', + }); + + // Publish the custom resource output + new cdk.Output(this, 'ResponseMessage', { + description: 'The message that came back from the Custom Resource', + value: resource.response + }); + } } /** * A stack that sets up a failing CustomResource creation */ class FailCreationStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - new DemoResource(this, 'DemoResource', { - message: 'CustomResource is silent', - failCreate: true - }); - } + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + new DemoResource(this, 'DemoResource', { + message: 'CustomResource is silent', + failCreate: true + }); + } } /** @@ -78,21 +78,21 @@ class FailCreationStack extends cdk.Stack { * done properly. */ class FailAfterCreatingStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - const resource = new DemoResource(this, 'DemoResource', { - message: 'CustomResource says hello', - }); + const resource = new DemoResource(this, 'DemoResource', { + message: 'CustomResource says hello', + }); - // Bucket with an invalid name will fail the deployment and cause a rollback - const bucket = new s3.BucketResource(this, 'FailingBucket', { - bucketName: 'hello!@#$^' - }); + // Bucket with an invalid name will fail the deployment and cause a rollback + const bucket = new s3.BucketResource(this, 'FailingBucket', { + bucketName: 'hello!@#$^' + }); - // Make sure the rollback gets triggered only after the custom resource has been fully created. - bucket.addDependency(resource); - } + // Make sure the rollback gets triggered only after the custom resource has been fully created. + bucket.addDependency(resource); + } } const app = new cdk.App(process.argv); @@ -101,4 +101,4 @@ new SucceedingStack(app, 'SucceedingStack'); new FailCreationStack(app, 'FailCreationStack'); new FailAfterCreatingStack(app, 'FailAfterCreatingStack'); -process.stdout.write(app.run()); \ No newline at end of file +process.stdout.write(app.run()); diff --git a/examples/cdk-examples-typescript/ec2/index.ts b/examples/cdk-examples-typescript/ec2/index.ts index 2962b8f62850c..fd12ee6b9cc3f 100644 --- a/examples/cdk-examples-typescript/ec2/index.ts +++ b/examples/cdk-examples-typescript/ec2/index.ts @@ -4,62 +4,62 @@ import elb = require('@aws-cdk/aws-elasticloadbalancing'); import cdk = require('@aws-cdk/cdk'); class AppWithVpc extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - const vpc = new ec2.VpcNetwork(this, 'MyVpc'); + const vpc = new ec2.VpcNetwork(this, 'MyVpc'); - const asg = new autoscaling.AutoScalingGroup(this, 'MyASG', { - vpc, - instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge), - machineImage: new ec2.AmazonLinuxImage() - }); + const asg = new autoscaling.AutoScalingGroup(this, 'MyASG', { + vpc, + instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge), + machineImage: new ec2.AmazonLinuxImage() + }); - const clb = new elb.LoadBalancer(this, 'LB', { - vpc, - internetFacing: true - }); + const clb = new elb.LoadBalancer(this, 'LB', { + vpc, + internetFacing: true + }); - clb.addListener({ externalPort: 80 }); - clb.addTarget(asg); - } + clb.addListener({ externalPort: 80 }); + clb.addTarget(asg); + } } interface MyAppProps extends cdk.StackProps { - infra: CommonInfrastructure + infra: CommonInfrastructure } class MyApp extends cdk.Stack { - constructor(parent: cdk.App, name: string, props: MyAppProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props: MyAppProps) { + super(parent, name, props); - const vpc = ec2.VpcNetwork.import(this, 'VPC', props.infra.vpc); + const vpc = ec2.VpcNetwork.import(this, 'VPC', props.infra.vpc); - const fleet = new autoscaling.AutoScalingGroup(this, 'MyASG', { - vpc, - instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge), - machineImage: new ec2.AmazonLinuxImage() - }); + const fleet = new autoscaling.AutoScalingGroup(this, 'MyASG', { + vpc, + instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge), + machineImage: new ec2.AmazonLinuxImage() + }); - const clb = new elb.LoadBalancer(this, 'LB', { - vpc, - internetFacing: true - }); + const clb = new elb.LoadBalancer(this, 'LB', { + vpc, + internetFacing: true + }); - clb.addListener({ externalPort: 80 }); - clb.addTarget(fleet); - } + clb.addListener({ externalPort: 80 }); + clb.addTarget(fleet); + } } class CommonInfrastructure extends cdk.Stack { - public vpc: ec2.VpcNetworkRefProps; + public vpc: ec2.VpcNetworkRefProps; - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - const vpc = new ec2.VpcNetwork(this, 'VPC'); - this.vpc = vpc.export(); - } + const vpc = new ec2.VpcNetwork(this, 'VPC'); + this.vpc = vpc.export(); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/hello-cdk/index.ts b/examples/cdk-examples-typescript/hello-cdk/index.ts index f6f7f0ae08224..fdfa32218df2b 100644 --- a/examples/cdk-examples-typescript/hello-cdk/index.ts +++ b/examples/cdk-examples-typescript/hello-cdk/index.ts @@ -2,17 +2,17 @@ import dynamodb = require('@aws-cdk/aws-dynamodb'); import cdk = require('@aws-cdk/cdk'); class HelloCDK extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - const table = new dynamodb.Table(this, 'Table', { - readCapacity: 1, - writeCapacity: 1 - }); + const table = new dynamodb.Table(this, 'Table', { + readCapacity: 1, + writeCapacity: 1 + }); - table.addPartitionKey({ name: 'ID', type: dynamodb.AttributeType.String }); - table.addSortKey({ name: 'Timestamp', type: dynamodb.AttributeType.Number }); - } + table.addPartitionKey({ name: 'ID', type: dynamodb.AttributeType.String }); + table.addSortKey({ name: 'Timestamp', type: dynamodb.AttributeType.Number }); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/neptune-demo/index.ts b/examples/cdk-examples-typescript/neptune-demo/index.ts index c9a247b246bb2..ff327b6ed7956 100644 --- a/examples/cdk-examples-typescript/neptune-demo/index.ts +++ b/examples/cdk-examples-typescript/neptune-demo/index.ts @@ -3,27 +3,27 @@ import neptune = require('@aws-cdk/aws-neptune'); import cdk = require('@aws-cdk/cdk'); class NeptuneDemoStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); - const vpc = new ec2.VpcNetwork(this, 'VPC'); + const vpc = new ec2.VpcNetwork(this, 'VPC'); - const database = new neptune.NeptuneDatabase(this, 'NeptuneCluster', { - instances: 3, - instanceProps: { - instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), - vpc, - vpcPlacement: { subnetsToUse: ec2.SubnetType.Public }, - }, - masterUser: { - // This would normally be imported from SSM parmeter store encrypted string, - // but don't want to overcomplicate the example - username: 'admin', - password: 'eRSDwst7lpzu', - } - }); - database.connections.allowDefaultPortFrom(new ec2.AnyIPv4(), 'Allow the world to connect'); - } + const database = new neptune.NeptuneDatabase(this, 'NeptuneCluster', { + instances: 3, + instanceProps: { + instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), + vpc, + vpcPlacement: { subnetsToUse: ec2.SubnetType.Public }, + }, + masterUser: { + // This would normally be imported from SSM parmeter store encrypted string, + // but don't want to overcomplicate the example + username: 'admin', + password: 'eRSDwst7lpzu', + } + }); + database.connections.allowDefaultPortFrom(new ec2.AnyIPv4(), 'Allow the world to connect'); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/sns-sqs/index.ts b/examples/cdk-examples-typescript/sns-sqs/index.ts index 9569c1c7dfaf2..58dcbff371ea9 100644 --- a/examples/cdk-examples-typescript/sns-sqs/index.ts +++ b/examples/cdk-examples-typescript/sns-sqs/index.ts @@ -3,43 +3,43 @@ import sqs = require('@aws-cdk/aws-sqs'); import cdk = require('@aws-cdk/cdk'); class ACL extends cdk.Stack { - constructor(parent: cdk.App, name: string) { - super(parent, name); + constructor(parent: cdk.App, name: string) { + super(parent, name); - const topic = new sns.Topic(this, 'MyTopic'); - const queue = new sqs.Queue(this, 'MyQueue', { - visibilityTimeoutSec: 300 - }); + const topic = new sns.Topic(this, 'MyTopic'); + const queue = new sqs.Queue(this, 'MyQueue', { + visibilityTimeoutSec: 300 + }); - topic.subscribeQueue(queue); - } + topic.subscribeQueue(queue); + } } class CFN extends cdk.Stack { - constructor(parent: cdk.App, name: string) { - super(parent, name); - - const topic = new sns.cloudformation.TopicResource(this, 'MyTopic'); - const queue = new sqs.cloudformation.QueueResource(this, 'MyQueue'); - - new sns.cloudformation.SubscriptionResource(this, 'TopicToQueue', { - topicArn: topic.ref, // ref == arn for topics - endpoint: queue.queueName, - protocol: 'sqs' - }); - - const policyDocument = new cdk.PolicyDocument(); - policyDocument.addStatement(new cdk.PolicyStatement() - .addResource(queue.queueArn) - .addAction('sqs:SendMessage') - .addServicePrincipal('sns.amazonaws.com') - .setCondition('ArnEquals', { 'aws:SourceArn': topic.ref })); - - new sqs.cloudformation.QueuePolicyResource(this, 'MyQueuePolicy', { - policyDocument, - queues: [ queue.ref ] - }); - } + constructor(parent: cdk.App, name: string) { + super(parent, name); + + const topic = new sns.cloudformation.TopicResource(this, 'MyTopic'); + const queue = new sqs.cloudformation.QueueResource(this, 'MyQueue'); + + new sns.cloudformation.SubscriptionResource(this, 'TopicToQueue', { + topicArn: topic.ref, // ref == arn for topics + endpoint: queue.queueName, + protocol: 'sqs' + }); + + const policyDocument = new cdk.PolicyDocument(); + policyDocument.addStatement(new cdk.PolicyStatement() + .addResource(queue.queueArn) + .addAction('sqs:SendMessage') + .addServicePrincipal('sns.amazonaws.com') + .setCondition('ArnEquals', { 'aws:SourceArn': topic.ref })); + + new sqs.cloudformation.QueuePolicyResource(this, 'MyQueuePolicy', { + policyDocument, + queues: [ queue.ref ] + }); + } } const app = new cdk.App(process.argv); diff --git a/examples/cdk-examples-typescript/use-vpc-from-another-stack/index.ts b/examples/cdk-examples-typescript/use-vpc-from-another-stack/index.ts index 14b26922efa49..defa0a18c002a 100644 --- a/examples/cdk-examples-typescript/use-vpc-from-another-stack/index.ts +++ b/examples/cdk-examples-typescript/use-vpc-from-another-stack/index.ts @@ -12,7 +12,7 @@ const app = new cdk.App(process.argv); const vpcStack = new cdk.Stack(app, 'VPCStack'); const exportedVpc = new ec2.VpcNetwork(vpcStack, 'VPC', { - maxAZs: 3 + maxAZs: 3 }); const appStack = new cdk.Stack(app, 'AppStack'); @@ -20,22 +20,22 @@ const appStack = new cdk.Stack(app, 'AppStack'); const importedVpc = ec2.VpcNetworkRef.import(appStack, 'VPC', exportedVpc.export()); const asg = new autoscaling.AutoScalingGroup(appStack, 'ASG', { - vpc: importedVpc, - instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Micro), - machineImage: new ec2.AmazonLinuxImage() + vpc: importedVpc, + instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Micro), + machineImage: new ec2.AmazonLinuxImage() }); new elb.LoadBalancer(appStack, 'LB', { - vpc: importedVpc, - internetFacing: true, - listeners: [{ - externalPort: 80, - allowConnectionsFrom: [new ec2.AnyIPv4()] - }], - healthCheck: { - port: 80 - }, - targets: [asg] + vpc: importedVpc, + internetFacing: true, + listeners: [{ + externalPort: 80, + allowConnectionsFrom: [new ec2.AnyIPv4()] + }], + healthCheck: { + port: 80 + }, + targets: [asg] }); process.stdout.write(app.run()); diff --git a/packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts b/packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts index 9ab3b0d887a49..9bb68f13fcfb2 100644 --- a/packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts +++ b/packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts @@ -8,79 +8,79 @@ import path = require('path'); const YAML = require('yamljs'); main().catch(e => { - // tslint:disable-next-line:no-console - console.error(e); - process.exit(1); + // tslint:disable-next-line:no-console + console.error(e); + process.exit(1); }); async function main() { - const progname = path.basename(process.argv[1]); + const progname = path.basename(process.argv[1]); - const appletFile = process.argv[2]; - if (!appletFile) { - throw new Error(`Usage: ${progname}| `); - } + const appletFile = process.argv[2]; + if (!appletFile) { + throw new Error(`Usage: ${progname}| `); + } - // read applet properties from the provided file - const props = YAML.load(appletFile); + // read applet properties from the provided file + const props = YAML.load(appletFile); - // the cx request is expected to be passed as the second parameter for this applet program. - // that's how cdk toolkit will use it. - const request = process.argv[3] || JSON.stringify({}); + // the cx request is expected to be passed as the second parameter for this applet program. + // that's how cdk toolkit will use it. + const request = process.argv[3] || JSON.stringify({}); - // the 'applet' attribute tells us how to load the applet. in the javascript case - // it will be in the format : where is technically passed to "require" - // and is expected to be exported from the module. - const applet: string = props.applet; - if (!applet) { - throw new Error('Applet file missing "applet" attribute'); - } + // the 'applet' attribute tells us how to load the applet. in the javascript case + // it will be in the format : where is technically passed to "require" + // and is expected to be exported from the module. + const applet: string = props.applet; + if (!applet) { + throw new Error('Applet file missing "applet" attribute'); + } - const { moduleName, className } = parseApplet(applet); + const { moduleName, className } = parseApplet(applet); - // remove the 'applet' attribute as we pass it along to the applet class. - delete props.applet; + // remove the 'applet' attribute as we pass it along to the applet class. + delete props.applet; - // we need to resolve the module name relatively to where the applet file is - // and not relative to this module or cwd. - const resolve = require.resolve as any; // escapse type-checking since { paths } is not defined - const modulePath = resolve(moduleName, { paths: [ path.dirname(appletFile) ] }); + // we need to resolve the module name relatively to where the applet file is + // and not relative to this module or cwd. + const resolve = require.resolve as any; // escapse type-checking since { paths } is not defined + const modulePath = resolve(moduleName, { paths: [ path.dirname(appletFile) ] }); - // load the module - const pkg = require(modulePath); + // load the module + const pkg = require(modulePath); - // find the applet class within the package - // tslint:disable-next-line:variable-name - const AppletStack = pkg[className]; - if (!AppletStack) { - throw new Error(`Cannot find applet class "${className}" in module "${moduleName}"`); - } + // find the applet class within the package + // tslint:disable-next-line:variable-name + const AppletStack = pkg[className]; + if (!AppletStack) { + throw new Error(`Cannot find applet class "${className}" in module "${moduleName}"`); + } - // create the CDK app - const app = new cdk.App([ progname, request ]); + // create the CDK app + const app = new cdk.App([ progname, request ]); - const constructName = props.name || className; + const constructName = props.name || className; - // add the applet stack into the app. - new AppletStack(app, constructName, props); + // add the applet stack into the app. + new AppletStack(app, constructName, props); - // transfer control to the app - process.stdout.write(app.run()); + // transfer control to the app + process.stdout.write(app.run()); } function parseApplet(applet: string) { - const components = applet.split(':'); - // tslint:disable-next-line:prefer-const - let [ moduleName, className ] = components; + const components = applet.split(':'); + // tslint:disable-next-line:prefer-const + let [ moduleName, className ] = components; - if (components.length > 2 || !moduleName) { - throw new Error(`"applet" value is "${applet}" but it must be in the form "[:]". - If is not specified, "Applet" is the default`); - } + if (components.length > 2 || !moduleName) { + throw new Error(`"applet" value is "${applet}" but it must be in the form "[:]". + If is not specified, "Applet" is the default`); + } - if (!className) { - className = 'Applet'; - } + if (!className) { + className = 'Applet'; + } - return { moduleName, className }; + return { moduleName, className }; } diff --git a/packages/@aws-cdk/applet-js/test/strip-stacktrace.ts b/packages/@aws-cdk/applet-js/test/strip-stacktrace.ts index 9c4d1ddf0080f..154b2449bc897 100644 --- a/packages/@aws-cdk/applet-js/test/strip-stacktrace.ts +++ b/packages/@aws-cdk/applet-js/test/strip-stacktrace.ts @@ -1,26 +1,26 @@ import 'source-map-support/register'; function outputPatchedJson(text: string) { - const document: any = JSON.parse(text); - for (const stack of (document.stacks as any[])) { - for (const key of Object.keys(stack.metadata)) { - if (!stack.metadata[key]) { continue; } - for (const entry of (stack.metadata[key] as any[])) { - if (entry.trace) { entry.trace = ['**REDACTED**']; } - } - } + const document: any = JSON.parse(text); + for (const stack of (document.stacks as any[])) { + for (const key of Object.keys(stack.metadata)) { + if (!stack.metadata[key]) { continue; } + for (const entry of (stack.metadata[key] as any[])) { + if (entry.trace) { entry.trace = ['**REDACTED**']; } + } } - if ('runtime' in document) { - delete document.runtime; - } - process.stdout.write(JSON.stringify(document, null, 2)); + } + if ('runtime' in document) { + delete document.runtime; + } + process.stdout.write(JSON.stringify(document, null, 2)); } function main() { - let inputText: string = ''; - process.stdin.setEncoding('utf8') - .on('data', chunk => inputText += chunk) - .on('end', () => outputPatchedJson(inputText)); + let inputText: string = ''; + process.stdin.setEncoding('utf8') + .on('data', chunk => inputText += chunk) + .on('end', () => outputPatchedJson(inputText)); } main(); diff --git a/packages/@aws-cdk/applet-js/test/test-applet.ts b/packages/@aws-cdk/applet-js/test/test-applet.ts index a2c8feccef72a..6d228770db998 100644 --- a/packages/@aws-cdk/applet-js/test/test-applet.ts +++ b/packages/@aws-cdk/applet-js/test/test-applet.ts @@ -1,32 +1,32 @@ import { App, Parameter, Stack, StackProps } from '@aws-cdk/cdk'; export interface TestAppletProps extends StackProps { - prop1: string - prop2: number - prop3?: string[] + prop1: string + prop2: number + prop3?: string[] } export class TestApplet extends Stack { - constructor(parent: App, name: string, props: TestAppletProps) { - super(parent, name, props); + constructor(parent: App, name: string, props: TestAppletProps) { + super(parent, name, props); - new Parameter(this, 'P1', { default: this.required(props, 'prop1'), type: 'String' }); - new Parameter(this, 'P2', { default: this.required(props, 'prop2'), type: 'Number' }); + new Parameter(this, 'P1', { default: this.required(props, 'prop1'), type: 'String' }); + new Parameter(this, 'P2', { default: this.required(props, 'prop2'), type: 'Number' }); - if (props.prop3) { - new Parameter(this, 'P3', { default: props.prop3.join(','), type: 'StringList' }); - } + if (props.prop3) { + new Parameter(this, 'P3', { default: props.prop3.join(','), type: 'StringList' }); } + } } export interface AppletProps extends StackProps { - desc?: string + desc?: string } export class Applet extends Stack { - constructor(parent: App, name: string, props: AppletProps) { - super(parent, name); + constructor(parent: App, name: string, props: AppletProps) { + super(parent, name); - this.templateOptions.description = props.desc; - } + this.templateOptions.description = props.desc; + } } diff --git a/packages/@aws-cdk/assert/lib/assertion.ts b/packages/@aws-cdk/assert/lib/assertion.ts index 3d19f411bff0b..d193a6856c27e 100644 --- a/packages/@aws-cdk/assert/lib/assertion.ts +++ b/packages/@aws-cdk/assert/lib/assertion.ts @@ -1,33 +1,33 @@ import { Inspector } from "./inspector"; export abstract class Assertion { - public abstract readonly description: string; + public abstract readonly description: string; - public abstract assertUsing(inspector: InspectorClass): boolean; + public abstract assertUsing(inspector: InspectorClass): boolean; - /** - * Assert this thing and another thing - */ - public and(assertion: Assertion): Assertion { - // Needs to delegate to a function so that we can import mutually dependent classes in the right order - return and(this, assertion); - } + /** + * Assert this thing and another thing + */ + public and(assertion: Assertion): Assertion { + // Needs to delegate to a function so that we can import mutually dependent classes in the right order + return and(this, assertion); + } - public assertOrThrow(inspector: InspectorClass) { - if (!this.assertUsing(inspector)) { - throw new Error(`${JSON.stringify(inspector.value, null, 2)} does not match ${this.description}`); - } + public assertOrThrow(inspector: InspectorClass) { + if (!this.assertUsing(inspector)) { + throw new Error(`${JSON.stringify(inspector.value, null, 2)} does not match ${this.description}`); } + } } import { AndAssertion } from "./assertions/and-assertion"; function and(left: Assertion, right: Assertion): Assertion { - return new AndAssertion(left, right); + return new AndAssertion(left, right); } import { NegatedAssertion } from "./assertions/negated-assertion"; export function not(assertion: Assertion): Assertion { - return new NegatedAssertion(assertion); -} \ No newline at end of file + return new NegatedAssertion(assertion); +} diff --git a/packages/@aws-cdk/assert/lib/assertions/and-assertion.ts b/packages/@aws-cdk/assert/lib/assertions/and-assertion.ts index c4c35157b67d7..73e1f49afd1fb 100644 --- a/packages/@aws-cdk/assert/lib/assertions/and-assertion.ts +++ b/packages/@aws-cdk/assert/lib/assertions/and-assertion.ts @@ -2,18 +2,18 @@ import { Assertion } from "../assertion"; import { Inspector } from "../inspector"; export class AndAssertion extends Assertion { - public description: string = 'Combined assertion'; + public description: string = 'Combined assertion'; - constructor(private readonly first: Assertion, private readonly second: Assertion) { - super(); - } + constructor(private readonly first: Assertion, private readonly second: Assertion) { + super(); + } - public assertUsing(_inspector: InspectorClass): boolean { - throw new Error('This is never called'); - } + public assertUsing(_inspector: InspectorClass): boolean { + throw new Error('This is never called'); + } - public assertOrThrow(inspector: InspectorClass) { - this.first.assertOrThrow(inspector); - this.second.assertOrThrow(inspector); - } + public assertOrThrow(inspector: InspectorClass) { + this.first.assertOrThrow(inspector); + this.second.assertOrThrow(inspector); + } } diff --git a/packages/@aws-cdk/assert/lib/assertions/count-resources.ts b/packages/@aws-cdk/assert/lib/assertions/count-resources.ts index ef4911a734e56..481a72cb0c0dd 100644 --- a/packages/@aws-cdk/assert/lib/assertions/count-resources.ts +++ b/packages/@aws-cdk/assert/lib/assertions/count-resources.ts @@ -5,31 +5,31 @@ import { StackInspector } from "../inspector"; * An assertion to check whether a resource of a given type and with the given properties exists, disregarding properties */ export function countResources(resourceType: string, count = 1): Assertion { - return new CountResourcesAssertion(resourceType, count); + return new CountResourcesAssertion(resourceType, count); } class CountResourcesAssertion extends Assertion { - private inspected: number = 0; + private inspected: number = 0; - constructor(private readonly resourceType: string, - private readonly count: number) { - super(); - } - - public assertUsing(inspector: StackInspector): boolean { - let counted = 0; - for (const logicalId of Object.keys(inspector.value.Resources || {})) { - const resource = inspector.value.Resources[logicalId]; - if (resource.Type === this.resourceType) { - counted++; - this.inspected += 1; - } - } + constructor(private readonly resourceType: string, + private readonly count: number) { + super(); + } - return counted === this.count; + public assertUsing(inspector: StackInspector): boolean { + let counted = 0; + for (const logicalId of Object.keys(inspector.value.Resources || {})) { + const resource = inspector.value.Resources[logicalId]; + if (resource.Type === this.resourceType) { + counted++; + this.inspected += 1; + } } - public get description(): string { - return `stack only has ${this.inspected} resource of type ${this.resourceType} but we expected to find ${this.count}`; - } + return counted === this.count; + } + + public get description(): string { + return `stack only has ${this.inspected} resource of type ${this.resourceType} but we expected to find ${this.count}`; + } } diff --git a/packages/@aws-cdk/assert/lib/assertions/exist.ts b/packages/@aws-cdk/assert/lib/assertions/exist.ts index 1ae0b00f86d65..3cc62f0444de4 100644 --- a/packages/@aws-cdk/assert/lib/assertions/exist.ts +++ b/packages/@aws-cdk/assert/lib/assertions/exist.ts @@ -2,17 +2,17 @@ import { Assertion } from '../assertion'; import { StackPathInspector } from '../inspector'; class ExistingResourceAssertion extends Assertion { - public description: string = 'an existing resource'; + public description: string = 'an existing resource'; - constructor() { - super(); - } + constructor() { + super(); + } - public assertUsing(inspector: StackPathInspector): boolean { - return inspector.value !== undefined; - } + public assertUsing(inspector: StackPathInspector): boolean { + return inspector.value !== undefined; + } } export function exist(): Assertion { - return new ExistingResourceAssertion(); -} \ No newline at end of file + return new ExistingResourceAssertion(); +} diff --git a/packages/@aws-cdk/assert/lib/assertions/have-resource.ts b/packages/@aws-cdk/assert/lib/assertions/have-resource.ts index dcd5d1524ca57..3978879873585 100644 --- a/packages/@aws-cdk/assert/lib/assertions/have-resource.ts +++ b/packages/@aws-cdk/assert/lib/assertions/have-resource.ts @@ -10,61 +10,61 @@ import { StackInspector } from "../inspector"; * - A callable, in which case it will be treated as a predicate that is applied to the Properties of the found resources. */ export function haveResource(resourceType: string, properties?: any, comparison?: ResourcePart): Assertion { - return new HaveResourceAssertion(resourceType, properties, comparison); + return new HaveResourceAssertion(resourceType, properties, comparison); } type PropertyPredicate = (props: any) => boolean; class HaveResourceAssertion extends Assertion { - private inspected: any[] = []; - private readonly part: ResourcePart; - private readonly predicate: PropertyPredicate; + private inspected: any[] = []; + private readonly part: ResourcePart; + private readonly predicate: PropertyPredicate; - constructor(private readonly resourceType: string, - private readonly properties?: any, - part?: ResourcePart) { - super(); + constructor(private readonly resourceType: string, + private readonly properties?: any, + part?: ResourcePart) { + super(); - this.predicate = typeof properties === 'function' ? properties : makeSuperObjectPredicate(properties); - this.part = part !== undefined ? part : ResourcePart.Properties; - } + this.predicate = typeof properties === 'function' ? properties : makeSuperObjectPredicate(properties); + this.part = part !== undefined ? part : ResourcePart.Properties; + } - public assertUsing(inspector: StackInspector): boolean { - for (const logicalId of Object.keys(inspector.value.Resources)) { - const resource = inspector.value.Resources[logicalId]; - if (resource.Type === this.resourceType) { - this.inspected.push(resource); + public assertUsing(inspector: StackInspector): boolean { + for (const logicalId of Object.keys(inspector.value.Resources)) { + const resource = inspector.value.Resources[logicalId]; + if (resource.Type === this.resourceType) { + this.inspected.push(resource); - const propsToCheck = this.part === ResourcePart.Properties ? resource.Properties : resource; + const propsToCheck = this.part === ResourcePart.Properties ? resource.Properties : resource; - if (this.predicate(propsToCheck)) { - return true; - } - } + if (this.predicate(propsToCheck)) { + return true; } - - return false; + } } - public assertOrThrow(inspector: StackInspector) { - if (!this.assertUsing(inspector)) { - throw new Error(`None of ${JSON.stringify(this.inspected, null, 2)} match ${this.description}`); - } - } + return false; + } - public get description(): string { - // tslint:disable-next-line:max-line-length - return `resource '${this.resourceType}' with properties ${JSON.stringify(this.properties, undefined, 2)}`; + public assertOrThrow(inspector: StackInspector) { + if (!this.assertUsing(inspector)) { + throw new Error(`None of ${JSON.stringify(this.inspected, null, 2)} match ${this.description}`); } + } + + public get description(): string { + // tslint:disable-next-line:max-line-length + return `resource '${this.resourceType}' with properties ${JSON.stringify(this.properties, undefined, 2)}`; + } } /** * Make a predicate that checks property superset */ function makeSuperObjectPredicate(obj: any) { - return (resourceProps: any) => { - return isSuperObject(resourceProps, obj); - }; + return (resourceProps: any) => { + return isSuperObject(resourceProps, obj); + }; } /** @@ -73,46 +73,46 @@ function makeSuperObjectPredicate(obj: any) { * A super-object has the same or more property values, recursing into nested objects. */ export function isSuperObject(superObj: any, obj: any): boolean { - if (obj == null) { return true; } - if (Array.isArray(superObj) !== Array.isArray(obj)) { return false; } - if (Array.isArray(superObj)) { - if (obj.length !== superObj.length) { return false; } - - // Do isSuperObject comparison for individual objects - for (let i = 0; i < obj.length; i++) { - if (!isSuperObject(superObj[i], obj[i])) { - return false; - } - } - return true; + if (obj == null) { return true; } + if (Array.isArray(superObj) !== Array.isArray(obj)) { return false; } + if (Array.isArray(superObj)) { + if (obj.length !== superObj.length) { return false; } + + // Do isSuperObject comparison for individual objects + for (let i = 0; i < obj.length; i++) { + if (!isSuperObject(superObj[i], obj[i])) { + return false; + } } - if ((typeof superObj === 'object') !== (typeof obj === 'object')) { return false; } - if (typeof obj === 'object') { - for (const key of Object.keys(obj)) { - if (!(key in superObj)) { return false; } - - if (!isSuperObject(superObj[key], obj[key])) { - return false; - } - } - return true; + return true; + } + if ((typeof superObj === 'object') !== (typeof obj === 'object')) { return false; } + if (typeof obj === 'object') { + for (const key of Object.keys(obj)) { + if (!(key in superObj)) { return false; } + + if (!isSuperObject(superObj[key], obj[key])) { + return false; + } } - return superObj === obj; + return true; + } + return superObj === obj; } /** * What part of the resource to compare */ export enum ResourcePart { - /** - * Only compare the resource's properties - */ - Properties, - - /** - * Check the entire CloudFormation config - * - * (including UpdateConfig, DependsOn, etc.) - */ - CompleteDefinition -} \ No newline at end of file + /** + * Only compare the resource's properties + */ + Properties, + + /** + * Check the entire CloudFormation config + * + * (including UpdateConfig, DependsOn, etc.) + */ + CompleteDefinition +} diff --git a/packages/@aws-cdk/assert/lib/assertions/have-type.ts b/packages/@aws-cdk/assert/lib/assertions/have-type.ts index 518f8f78d9736..a04d8a450a338 100644 --- a/packages/@aws-cdk/assert/lib/assertions/have-type.ts +++ b/packages/@aws-cdk/assert/lib/assertions/have-type.ts @@ -2,20 +2,20 @@ import { Assertion } from '../assertion'; import { StackPathInspector } from '../inspector'; export function haveType(type: string): Assertion { - return new StackPathHasTypeAssertion(type); + return new StackPathHasTypeAssertion(type); } class StackPathHasTypeAssertion extends Assertion { - constructor(private readonly type: string) { - super(); - } + constructor(private readonly type: string) { + super(); + } - public assertUsing(inspector: StackPathInspector): boolean { - const resource = inspector.value; - return resource !== undefined && resource.Type === this.type; - } + public assertUsing(inspector: StackPathInspector): boolean { + const resource = inspector.value; + return resource !== undefined && resource.Type === this.type; + } - public get description(): string { - return `resource of type ${this.type}`; - } -} \ No newline at end of file + public get description(): string { + return `resource of type ${this.type}`; + } +} diff --git a/packages/@aws-cdk/assert/lib/assertions/match-template.ts b/packages/@aws-cdk/assert/lib/assertions/match-template.ts index 5a4aa9795a6b2..cc00cd7627b7e 100644 --- a/packages/@aws-cdk/assert/lib/assertions/match-template.ts +++ b/packages/@aws-cdk/assert/lib/assertions/match-template.ts @@ -3,76 +3,76 @@ import { Assertion } from '../assertion'; import { StackInspector } from '../inspector'; export enum MatchStyle { - /** Requires an exact match */ - EXACT = "exactly", - /** Allows any change that does not cause a resource replacement */ - NO_REPLACES = "no replaces", - /** Allows additions, but no updates */ - SUPERSET = "superset" + /** Requires an exact match */ + EXACT = "exactly", + /** Allows any change that does not cause a resource replacement */ + NO_REPLACES = "no replaces", + /** Allows additions, but no updates */ + SUPERSET = "superset" } export function exactlyMatchTemplate(template: { [key: string]: any }) { - return matchTemplate(template, MatchStyle.EXACT); + return matchTemplate(template, MatchStyle.EXACT); } export function beASupersetOfTemplate(template: { [key: string]: any }) { - return matchTemplate(template, MatchStyle.SUPERSET); + return matchTemplate(template, MatchStyle.SUPERSET); } export function matchTemplate(template: { [key: string]: any }, matchStyle: MatchStyle = MatchStyle.EXACT): Assertion { - return new StackMatchesTemplateAssertion(template, matchStyle); + return new StackMatchesTemplateAssertion(template, matchStyle); } class StackMatchesTemplateAssertion extends Assertion { - constructor(private readonly template: { [key: string]: any }, - private readonly matchStyle: MatchStyle) { - super(); - } + constructor(private readonly template: { [key: string]: any }, + private readonly matchStyle: MatchStyle) { + super(); + } - public assertOrThrow(inspector: StackInspector) { - if (!this.assertUsing(inspector)) { - // The details have already been printed, so don't generate a huge error message - throw new Error(`Template comparison produced unacceptable match`); - } + public assertOrThrow(inspector: StackInspector) { + if (!this.assertUsing(inspector)) { + // The details have already been printed, so don't generate a huge error message + throw new Error(`Template comparison produced unacceptable match`); } + } - public assertUsing(inspector: StackInspector): boolean { - const diff = cfnDiff.diffTemplate(this.template, inspector.value); - const acceptable = this.isDiffAcceptable(diff); - if (!acceptable) { - // Print the diff - cfnDiff.formatDifferences(process.stderr, diff); - - // Print the actual template - process.stdout.write('--------------------------------------------------------------------------------------\n'); - process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n'); - } + public assertUsing(inspector: StackInspector): boolean { + const diff = cfnDiff.diffTemplate(this.template, inspector.value); + const acceptable = this.isDiffAcceptable(diff); + if (!acceptable) { + // Print the diff + cfnDiff.formatDifferences(process.stderr, diff); - return acceptable; + // Print the actual template + process.stdout.write('--------------------------------------------------------------------------------------\n'); + process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n'); } - private isDiffAcceptable(diff: cfnDiff.TemplateDiff): boolean { - switch (this.matchStyle) { - case MatchStyle.EXACT: - return diff.count === 0; - case MatchStyle.NO_REPLACES: - for (const key of Object.keys(diff.resources.changes)) { - const change = diff.resources.changes[key]!; - if (change.changeImpact === cfnDiff.ResourceImpact.MAY_REPLACE) { return false; } - if (change.changeImpact === cfnDiff.ResourceImpact.WILL_REPLACE) { return false; } - } - return true; - case MatchStyle.SUPERSET: - for (const key of Object.keys(diff.resources.changes)) { - const change = diff.resources.changes[key]!; - return change.changeImpact === cfnDiff.ResourceImpact.WILL_CREATE; - } - } - throw new Error(`Unsupported match style: ${this.matchStyle}`); - } + return acceptable; + } - public get description(): string { - return `template (${this.matchStyle}): ${JSON.stringify(this.template, null, 2)}`; + private isDiffAcceptable(diff: cfnDiff.TemplateDiff): boolean { + switch (this.matchStyle) { + case MatchStyle.EXACT: + return diff.count === 0; + case MatchStyle.NO_REPLACES: + for (const key of Object.keys(diff.resources.changes)) { + const change = diff.resources.changes[key]!; + if (change.changeImpact === cfnDiff.ResourceImpact.MAY_REPLACE) { return false; } + if (change.changeImpact === cfnDiff.ResourceImpact.WILL_REPLACE) { return false; } + } + return true; + case MatchStyle.SUPERSET: + for (const key of Object.keys(diff.resources.changes)) { + const change = diff.resources.changes[key]!; + return change.changeImpact === cfnDiff.ResourceImpact.WILL_CREATE; + } } + throw new Error(`Unsupported match style: ${this.matchStyle}`); + } + + public get description(): string { + return `template (${this.matchStyle}): ${JSON.stringify(this.template, null, 2)}`; + } } diff --git a/packages/@aws-cdk/assert/lib/assertions/negated-assertion.ts b/packages/@aws-cdk/assert/lib/assertions/negated-assertion.ts index 17d0f01343dea..4c62225ee48a9 100644 --- a/packages/@aws-cdk/assert/lib/assertions/negated-assertion.ts +++ b/packages/@aws-cdk/assert/lib/assertions/negated-assertion.ts @@ -2,15 +2,15 @@ import { Assertion } from '../assertion'; import { Inspector } from '../inspector'; export class NegatedAssertion extends Assertion { - constructor(private readonly negated: Assertion) { - super(); - } + constructor(private readonly negated: Assertion) { + super(); + } - public assertUsing(inspector: I): boolean { - return !this.negated.assertUsing(inspector); - } + public assertUsing(inspector: I): boolean { + return !this.negated.assertUsing(inspector); + } - public get description(): string { - return `not ${this.negated.description}`; - } -} \ No newline at end of file + public get description(): string { + return `not ${this.negated.description}`; + } +} diff --git a/packages/@aws-cdk/assert/lib/expect.ts b/packages/@aws-cdk/assert/lib/expect.ts index dc771418ae17a..2205658cdf0e2 100644 --- a/packages/@aws-cdk/assert/lib/expect.ts +++ b/packages/@aws-cdk/assert/lib/expect.ts @@ -3,30 +3,30 @@ import api = require('@aws-cdk/cx-api'); import { StackInspector } from './inspector'; export function expect(stack: api.SynthesizedStack | cdk.Stack, skipValidation = false): StackInspector { - // Can't use 'instanceof' here, that breaks if we have multiple copies - // of this library. - let sstack: api.SynthesizedStack; + // Can't use 'instanceof' here, that breaks if we have multiple copies + // of this library. + let sstack: api.SynthesizedStack; - if (isStackClassInstance(stack)) { - if (!skipValidation) { - const errors = stack.validateTree(); - if (errors.length > 0) { - throw new Error(`Stack validation failed:\n${errors.map(e => `${e.message} at: ${e.source.parent}`).join('\n')}`); - } - } - - sstack = { - name: 'test', - template: stack.toCloudFormation(), - metadata: {} - }; - } else { - sstack = stack; + if (isStackClassInstance(stack)) { + if (!skipValidation) { + const errors = stack.validateTree(); + if (errors.length > 0) { + throw new Error(`Stack validation failed:\n${errors.map(e => `${e.message} at: ${e.source.parent}`).join('\n')}`); + } } - return new StackInspector(sstack); + sstack = { + name: 'test', + template: stack.toCloudFormation(), + metadata: {} + }; + } else { + sstack = stack; + } + + return new StackInspector(sstack); } function isStackClassInstance(x: api.SynthesizedStack | cdk.Stack): x is cdk.Stack { - return 'toCloudFormation' in x; + return 'toCloudFormation' in x; } diff --git a/packages/@aws-cdk/assert/lib/index.ts b/packages/@aws-cdk/assert/lib/index.ts index 1f9b78815a7c6..e811cd2e0bb0d 100644 --- a/packages/@aws-cdk/assert/lib/index.ts +++ b/packages/@aws-cdk/assert/lib/index.ts @@ -8,4 +8,4 @@ export * from './assertions/have-type'; export * from './assertions/match-template'; export * from './assertions/and-assertion'; export * from './assertions/negated-assertion'; -export * from './assertions/count-resources'; \ No newline at end of file +export * from './assertions/count-resources'; diff --git a/packages/@aws-cdk/assert/lib/inspector.ts b/packages/@aws-cdk/assert/lib/inspector.ts index 4357cb1c3907b..0b7a13490acab 100644 --- a/packages/@aws-cdk/assert/lib/inspector.ts +++ b/packages/@aws-cdk/assert/lib/inspector.ts @@ -4,58 +4,58 @@ import { not } from './assertion'; import { MatchStyle, matchTemplate } from './assertions/match-template'; export abstract class Inspector { - public aroundAssert?: (cb: () => void) => any; + public aroundAssert?: (cb: () => void) => any; - constructor() { - this.aroundAssert = undefined; - } + constructor() { + this.aroundAssert = undefined; + } - public to(assertion: Assertion): any { - return this.aroundAssert ? this.aroundAssert(() => this._to(assertion)) - : this._to(assertion); - } + public to(assertion: Assertion): any { + return this.aroundAssert ? this.aroundAssert(() => this._to(assertion)) + : this._to(assertion); + } - public notTo(assertion: Assertion): any { - return this.to(not(assertion)); - } + public notTo(assertion: Assertion): any { + return this.to(not(assertion)); + } - abstract get value(): any; + abstract get value(): any; - private _to(assertion: Assertion): any { - assertion.assertOrThrow(this); - } + private _to(assertion: Assertion): any { + assertion.assertOrThrow(this); + } } export class StackInspector extends Inspector { - constructor(public readonly stack: api.SynthesizedStack) { - super(); - } - - public at(path: string | string[]): StackPathInspector { - const strPath = typeof path === 'string' ? path : path.join('/'); - return new StackPathInspector(this.stack, strPath); - } - - public toMatch(template: { [key: string]: any }, matchStyle = MatchStyle.EXACT) { - return this.to(matchTemplate(template, matchStyle)); - } - - public get value(): { [key: string]: any } { - return this.stack.template; - } + constructor(public readonly stack: api.SynthesizedStack) { + super(); + } + + public at(path: string | string[]): StackPathInspector { + const strPath = typeof path === 'string' ? path : path.join('/'); + return new StackPathInspector(this.stack, strPath); + } + + public toMatch(template: { [key: string]: any }, matchStyle = MatchStyle.EXACT) { + return this.to(matchTemplate(template, matchStyle)); + } + + public get value(): { [key: string]: any } { + return this.stack.template; + } } export class StackPathInspector extends Inspector { - constructor(public readonly stack: api.SynthesizedStack, public readonly path: string) { - super(); - } - - public get value(): { [key: string]: any } | undefined { - const md = this.stack.metadata[`/${this.stack.name}${this.path}`]; - if (md === undefined) { return undefined; } - const resourceMd = md.find(entry => entry.type === 'aws:cdk:logicalId'); - if (resourceMd === undefined) { return undefined; } - const logicalId = resourceMd.data; - return this.stack.template.Resources[logicalId]; - } + constructor(public readonly stack: api.SynthesizedStack, public readonly path: string) { + super(); + } + + public get value(): { [key: string]: any } | undefined { + const md = this.stack.metadata[`/${this.stack.name}${this.path}`]; + if (md === undefined) { return undefined; } + const resourceMd = md.find(entry => entry.type === 'aws:cdk:logicalId'); + if (resourceMd === undefined) { return undefined; } + const logicalId = resourceMd.data; + return this.stack.template.Resources[logicalId]; + } } diff --git a/packages/@aws-cdk/assert/test/test.assertions.ts b/packages/@aws-cdk/assert/test/test.assertions.ts index 5eb5fe6447d47..5745b05985c03 100644 --- a/packages/@aws-cdk/assert/test/test.assertions.ts +++ b/packages/@aws-cdk/assert/test/test.assertions.ts @@ -8,174 +8,174 @@ import { Stack } from '@aws-cdk/cdk'; import { countResources, exist, expect, haveType, MatchStyle, matchTemplate } from '../lib/index'; passingExample('expect at to have ', () => { - const resourceType = 'Test::Resource'; - const synthStack = synthesizedStack(stack => { - new TestResource(stack, 'TestResource', { type: resourceType }); - }); - expect(synthStack).at('/TestResource').to(haveType(resourceType)); + const resourceType = 'Test::Resource'; + const synthStack = synthesizedStack(stack => { + new TestResource(stack, 'TestResource', { type: resourceType }); + }); + expect(synthStack).at('/TestResource').to(haveType(resourceType)); }); passingExample('expect at *not* to have ', () => { - const resourceType = 'Test::Resource'; - const synthStack = synthesizedStack(stack => { - new TestResource(stack, 'TestResource', { type: resourceType }); - }); - expect(synthStack).at('/TestResource').notTo(haveType('Foo::Bar')); + const resourceType = 'Test::Resource'; + const synthStack = synthesizedStack(stack => { + new TestResource(stack, 'TestResource', { type: resourceType }); + }); + expect(synthStack).at('/TestResource').notTo(haveType('Foo::Bar')); }); passingExample('expect at to exist', () => { - const resourceType = 'Test::Resource'; - const synthStack = synthesizedStack(stack => { - new TestResource(stack, 'TestResource', { type: resourceType }); - }); - expect(synthStack).at('/TestResource').to(exist()); + const resourceType = 'Test::Resource'; + const synthStack = synthesizedStack(stack => { + new TestResource(stack, 'TestResource', { type: resourceType }); + }); + expect(synthStack).at('/TestResource').to(exist()); }); passingExample('expect to match (exactly)