From b1f42f9b8f6de546d937ffbbff7bdc04ed1fd234 Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Thu, 22 Nov 2018 10:38:19 +0100 Subject: [PATCH 1/6] chore: Indent the title format options correctly (#1230) This makes for a better rendering. --- .github/PULL_REQUEST_TEMPLATE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6250e88d22536..b637f4f6f30a4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -22,10 +22,10 @@ manually executed (paste output to the PR description) ### Title and description - [ ] __Change type__: Title is prefixed with change type: - * `fix(module): ` bug fix (_patch_) - * `feat(module): <title>` feature/capability (_minor_) - * `chore(module): <title> ` won't appear in changelog - * `build(module): <title>` won't appear in changelog + * `fix(module): <title>` bug fix (_patch_) + * `feat(module): <title>` feature/capability (_minor_) + * `chore(module): <title> ` won't appear in changelog + * `build(module): <title>` won't appear in changelog - [ ] __Title format__: Title uses lower case and doesn't end with a period - [ ] __Breaking change?__: Last paragraph of description is: `BREAKING CHANGE: <describe exactly what changed and how to achieve similar behavior + From 8e17500fc64465dbd884dea7b869a0ad3ccad985 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel <benisrae@amazon.com> Date: Thu, 22 Nov 2018 15:18:05 +0200 Subject: [PATCH 2/6] chore(aws-s3-deployment): allow building on debian (#1234) In debian, python modules are installed under dist-packages. --- packages/@aws-cdk/aws-s3-deployment/lambda/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/lambda/build.sh b/packages/@aws-cdk/aws-s3-deployment/lambda/build.sh index f7997d7f7836a..fe753e2aa3de8 100755 --- a/packages/@aws-cdk/aws-s3-deployment/lambda/build.sh +++ b/packages/@aws-cdk/aws-s3-deployment/lambda/build.sh @@ -28,7 +28,7 @@ cd ${staging} # Must use --prefix to because --target cannot be used on # platforms that have a default --prefix set. pip3 install --ignore-installed --prefix ${piptemp} -r ${staging}/requirements.txt -mv ${piptemp}/lib/python*/site-packages/* . +mv ${piptemp}/lib/python*/*-packages/* . # create archive zip -qr ${bundle_out} . From 6a13a185f00bb1aa82958e60542cc3fc0f93933c Mon Sep 17 00:00:00 2001 From: Rico Huijbers <rix0rrr@gmail.com> Date: Thu, 22 Nov 2018 16:31:07 +0100 Subject: [PATCH 3/6] fix(aws-ec2): fix code generation of IcmpPing (#1235) IcmpPing used to generate a piece of ingress/egress rule that would not deploy. Added to integration test to make sure. Fixes #1231. --- .../aws-ec2/lib/security-group-rule.ts | 1 + .../aws-ec2/test/integ.vpc.expected.json | 84 ++++++++++++++++--- packages/@aws-cdk/aws-ec2/test/integ.vpc.ts | 25 ++++-- 3 files changed, 93 insertions(+), 17 deletions(-) diff --git a/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts b/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts index 1aae45389a5ee..96ddbd5dbefae 100644 --- a/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts +++ b/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts @@ -350,6 +350,7 @@ export class IcmpPing implements IPortRange { return { ipProtocol: Protocol.Icmp, fromPort: 8, + toPort: -1 }; } diff --git a/packages/@aws-cdk/aws-ec2/test/integ.vpc.expected.json b/packages/@aws-cdk/aws-ec2/test/integ.vpc.expected.json index 7ac8bc19f1ffb..fc6f104af9b79 100644 --- a/packages/@aws-cdk/aws-ec2/test/integ.vpc.expected.json +++ b/packages/@aws-cdk/aws-ec2/test/integ.vpc.expected.json @@ -67,9 +67,6 @@ }, "MyVpcPublicSubnet1DefaultRoute95FDF9EB": { "Type": "AWS::EC2::Route", - "DependsOn": [ - "MyVpcVPCGW488ACE0D" - ], "Properties": { "RouteTableId": { "Ref": "MyVpcPublicSubnet1RouteTableC46AB2F4" @@ -78,7 +75,10 @@ "GatewayId": { "Ref": "MyVpcIGW5C4A4F63" } - } + }, + "DependsOn": [ + "MyVpcVPCGW488ACE0D" + ] }, "MyVpcPublicSubnet1EIP096967CB": { "Type": "AWS::EC2::EIP", @@ -158,9 +158,6 @@ }, "MyVpcPublicSubnet2DefaultRoute052936F6": { "Type": "AWS::EC2::Route", - "DependsOn": [ - "MyVpcVPCGW488ACE0D" - ], "Properties": { "RouteTableId": { "Ref": "MyVpcPublicSubnet2RouteTable1DF17386" @@ -169,7 +166,10 @@ "GatewayId": { "Ref": "MyVpcIGW5C4A4F63" } - } + }, + "DependsOn": [ + "MyVpcVPCGW488ACE0D" + ] }, "MyVpcPublicSubnet2EIP8CCBA239": { "Type": "AWS::EC2::EIP", @@ -249,9 +249,6 @@ }, "MyVpcPublicSubnet3DefaultRoute3A83AB36": { "Type": "AWS::EC2::Route", - "DependsOn": [ - "MyVpcVPCGW488ACE0D" - ], "Properties": { "RouteTableId": { "Ref": "MyVpcPublicSubnet3RouteTable15028F08" @@ -260,7 +257,10 @@ "GatewayId": { "Ref": "MyVpcIGW5C4A4F63" } - } + }, + "DependsOn": [ + "MyVpcVPCGW488ACE0D" + ] }, "MyVpcPublicSubnet3EIPC5ACADAB": { "Type": "AWS::EC2::EIP", @@ -495,6 +495,66 @@ "Ref": "MyVpcIGW5C4A4F63" } } + }, + "SGADB53937": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "aws-cdk-ec2-vpc/SG", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "SecurityGroupIngress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:ICMP PING", + "FromPort": 8, + "IpProtocol": "icmp", + "ToPort": -1 + }, + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:ICMP Type 128", + "FromPort": 128, + "IpProtocol": "icmp", + "ToPort": -1 + }, + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:ALL ICMP", + "FromPort": -1, + "IpProtocol": "icmp", + "ToPort": -1 + }, + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:UDP ALL PORTS", + "FromPort": 0, + "IpProtocol": "udp", + "ToPort": 65535 + }, + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:UDP 123", + "FromPort": 123, + "IpProtocol": "udp", + "ToPort": 123 + }, + { + "CidrIp": "0.0.0.0/0", + "Description": "from 0.0.0.0/0:UDP 800-801", + "FromPort": 800, + "IpProtocol": "udp", + "ToPort": 801 + } + ], + "VpcId": { + "Ref": "MyVpcF9F0CA6F" + } + } } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ec2/test/integ.vpc.ts b/packages/@aws-cdk/aws-ec2/test/integ.vpc.ts index 201a5619b46b4..fe66412cd50de 100644 --- a/packages/@aws-cdk/aws-ec2/test/integ.vpc.ts +++ b/packages/@aws-cdk/aws-ec2/test/integ.vpc.ts @@ -1,10 +1,25 @@ -import { App, Stack } from '@aws-cdk/cdk'; -import { VpcNetwork } from '../lib'; +import cdk = require('@aws-cdk/cdk'); +import ec2 = require('../lib'); -const app = new App(); +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-cdk-ec2-vpc'); -const stack = new Stack(app, 'aws-cdk-ec2-vpc'); +const vpc = new ec2.VpcNetwork(stack, 'MyVpc'); -new VpcNetwork(stack, 'MyVpc'); +// Test Security Group Rules +const sg = new ec2.SecurityGroup(stack, 'SG', { vpc }); + +const rules = [ + new ec2.IcmpPing(), + new ec2.IcmpAllTypeCodes(128), + new ec2.IcmpAllTypesAndCodes(), + new ec2.UdpAllPorts(), + new ec2.UdpPort(123), + new ec2.UdpPortRange(800, 801), +]; + +for (const rule of rules) { + sg.addIngressRule(new ec2.AnyIPv4(), rule); +} app.run(); From 2aa35e60c9127d8c14b1935ec8838cdb9221e25b Mon Sep 17 00:00:00 2001 From: sam gordon <32661007+sam-gordon-f@users.noreply.github.com> Date: Fri, 23 Nov 2018 19:51:19 +1100 Subject: [PATCH 4/6] chore: updated lambda principal in example (#1238) --- examples/cdk-examples-typescript/advanced-usage/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cdk-examples-typescript/advanced-usage/index.ts b/examples/cdk-examples-typescript/advanced-usage/index.ts index afe41ba90102a..356b634bf73fe 100644 --- a/examples/cdk-examples-typescript/advanced-usage/index.ts +++ b/examples/cdk-examples-typescript/advanced-usage/index.ts @@ -16,7 +16,7 @@ class PolicyExample extends cdk.Stack { // 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 iam.ServicePrincipal('lambda.amazon.aws.com') + assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com') }); // when you call `addToPolicy`, a default policy is defined and attached From 4b779516fb93392a09270798ce1b27327c949c38 Mon Sep 17 00:00:00 2001 From: Rico Huijbers <rix0rrr@gmail.com> Date: Mon, 26 Nov 2018 09:45:22 +0100 Subject: [PATCH 5/6] chore: refactoring of toolkit and cxapi (#1236) Right now we're abusing the 'command objects' feature of yargs with a decorator that changes the expected type of the handler function from (yargs) => void to (yargs) => Promise<number>. Instead, we make explicit what is happening: during the execution of the original handler, we store the async "real" handler object is written to a variable and executed later on instead of main(). The async handler gets access to more of the state of the application so that more realistic handlers can be written that need access to the CX app's stacks. Organize metadata types of CX API into a folder. --- packages/@aws-cdk/cx-api/lib/cxapi.ts | 58 ------------------- packages/@aws-cdk/cx-api/lib/index.ts | 1 + .../@aws-cdk/cx-api/lib/metadata/assets.ts | 57 ++++++++++++++++++ packages/aws-cdk/bin/cdk.ts | 48 ++------------- .../aws-cdk/integ-tests/test-cdk-synth.sh | 6 ++ packages/aws-cdk/lib/command-api.ts | 28 +++++++++ packages/aws-cdk/lib/commands/context.ts | 12 ++-- packages/aws-cdk/lib/commands/docs.ts | 9 ++- packages/aws-cdk/lib/commands/doctor.ts | 8 ++- packages/aws-cdk/lib/settings.ts | 4 -- packages/aws-cdk/test/test.cdk-docs.ts | 16 ++++- packages/aws-cdk/test/test.cdk-doctor.ts | 7 ++- scripts/build-typescript.sh | 2 +- 13 files changed, 139 insertions(+), 117 deletions(-) create mode 100644 packages/@aws-cdk/cx-api/lib/metadata/assets.ts create mode 100644 packages/aws-cdk/lib/command-api.ts diff --git a/packages/@aws-cdk/cx-api/lib/cxapi.ts b/packages/@aws-cdk/cx-api/lib/cxapi.ts index 32fc928ef7407..5e91a7b296586 100644 --- a/packages/@aws-cdk/cx-api/lib/cxapi.ts +++ b/packages/@aws-cdk/cx-api/lib/cxapi.ts @@ -103,64 +103,6 @@ export const DEFAULT_ACCOUNT_CONTEXT_KEY = 'aws:cdk:toolkit:default-account'; */ export const DEFAULT_REGION_CONTEXT_KEY = 'aws:cdk:toolkit:default-region'; -export const ASSET_METADATA = 'aws:cdk:asset'; - -export interface FileAssetMetadataEntry { - /** - * Requested packaging style - */ - packaging: 'zip' | 'file'; - - /** - * Path on disk to the asset - */ - path: string; - - /** - * Logical identifier for the asset - */ - id: string; - - /** - * Name of parameter where S3 bucket should be passed in - */ - s3BucketParameter: string; - - /** - * Name of parameter where S3 key should be passed in - */ - s3KeyParameter: string; -} - -export interface ContainerImageAssetMetadataEntry { - /** - * Type of asset - */ - packaging: 'container-image'; - - /** - * Path on disk to the asset - */ - path: string; - - /** - * Logical identifier for the asset - */ - id: string; - - /** - * Name of the parameter that takes the repository name - */ - repositoryParameter: string; - - /** - * Name of the parameter that takes the tag - */ - tagParameter: string; -} - -export type AssetMetadataEntry = FileAssetMetadataEntry | ContainerImageAssetMetadataEntry; - /** * Metadata key used to print INFO-level messages by the toolkit when an app is syntheized. */ diff --git a/packages/@aws-cdk/cx-api/lib/index.ts b/packages/@aws-cdk/cx-api/lib/index.ts index 7856e10f5b787..8be9dc02a8bd7 100644 --- a/packages/@aws-cdk/cx-api/lib/index.ts +++ b/packages/@aws-cdk/cx-api/lib/index.ts @@ -4,3 +4,4 @@ export * from './context/hosted-zone'; export * from './context/vpc'; export * from './context/ssm-parameter'; export * from './context/availability-zones'; +export * from './metadata/assets'; diff --git a/packages/@aws-cdk/cx-api/lib/metadata/assets.ts b/packages/@aws-cdk/cx-api/lib/metadata/assets.ts new file mode 100644 index 0000000000000..524539166b724 --- /dev/null +++ b/packages/@aws-cdk/cx-api/lib/metadata/assets.ts @@ -0,0 +1,57 @@ +export const ASSET_METADATA = 'aws:cdk:asset'; + +export interface FileAssetMetadataEntry { + /** + * Requested packaging style + */ + packaging: 'zip' | 'file'; + + /** + * Path on disk to the asset + */ + path: string; + + /** + * Logical identifier for the asset + */ + id: string; + + /** + * Name of parameter where S3 bucket should be passed in + */ + s3BucketParameter: string; + + /** + * Name of parameter where S3 key should be passed in + */ + s3KeyParameter: string; +} + +export interface ContainerImageAssetMetadataEntry { + /** + * Type of asset + */ + packaging: 'container-image'; + + /** + * Path on disk to the asset + */ + path: string; + + /** + * Logical identifier for the asset + */ + id: string; + + /** + * Name of the parameter that takes the repository name + */ + repositoryParameter: string; + + /** + * Name of the parameter that takes the tag + */ + tagParameter: string; +} + +export type AssetMetadataEntry = FileAssetMetadataEntry | ContainerImageAssetMetadataEntry; \ No newline at end of file diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 2a26c19fa7a83..43ad09fe0e94d 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -63,7 +63,7 @@ async function parseCommandLineArguments() { .command('init [TEMPLATE]', 'Create a new, empty CDK project from a template. Invoked without TEMPLATE, the app template will be used.', yargs => yargs .option('language', { type: 'string', alias: 'l', desc: 'the language to be used for the new project (default can be configured in ~/.cdk.json)', choices: initTemplateLanuages }) .option('list', { type: 'boolean', desc: 'list the available templates' })) - .commandDir('../lib/commands', { exclude: /^_.*/, visit: decorateCommand }) + .commandDir('../lib/commands', { exclude: /^_.*/ }) .version(VERSION) .demandCommand(1, '') // just print help .help() @@ -75,47 +75,6 @@ async function parseCommandLineArguments() { } // tslint:enable:no-shadowed-variable max-line-length -/** - * Decorates commands discovered by ``yargs.commandDir`` in order to apply global - * options as appropriate. - * - * Command handlers are supposed to be (args) => void, but ours are actually - * (args) => Promise<number>, so we deal with the asyncness by copying the actual - * handler object to `args.commandHandler` which will be 'await'ed later on - * (instead of awaiting 'main'). - * - * Also adds exception handling so individual command handlers don't all have to do it. - * - * @param commandObject is the command to be decorated. - * @returns a decorated ``CommandModule``. - */ -function decorateCommand(commandObject: yargs.CommandModule): yargs.CommandModule { - return { - ...commandObject, - handler(args: yargs.Arguments) { - if (args.verbose) { - setVerbose(); - } - args.commandHandler = wrapExceptionHandler(args.verbose, commandObject.handler as any)(args); - } - }; -} - -function wrapExceptionHandler(verbose: boolean, fn: (args: any) => Promise<number>) { - return async (a: any) => { - try { - return await fn(a); - } catch (e) { - if (verbose) { - error(e); - } else { - error(e.message); - } - return 1; - } - }; -} - async function initCommandLine() { const argv = await parseCommandLineArguments(); if (argv.verbose) { @@ -167,7 +126,10 @@ async function initCommandLine() { const cmd = argv._[0]; - const returnValue = await (argv.commandHandler || main(cmd, argv)); + // Bundle up global objects so the commands have access to them + const commandOptions = { args: argv, appStacks, configuration, aws }; + + const returnValue = argv.commandHandler ? await argv.commandHandler(commandOptions) : await main(cmd, argv); if (typeof returnValue === 'object') { return toJsonOrYaml(returnValue); } else if (typeof returnValue === 'string') { diff --git a/packages/aws-cdk/integ-tests/test-cdk-synth.sh b/packages/aws-cdk/integ-tests/test-cdk-synth.sh index 50a7ebdbaa9bb..837d076248ace 100755 --- a/packages/aws-cdk/integ-tests/test-cdk-synth.sh +++ b/packages/aws-cdk/integ-tests/test-cdk-synth.sh @@ -10,6 +10,8 @@ assert "cdk synth cdk-toolkit-integration-test-1" <<HERE Resources: topic69831491: Type: AWS::SNS::Topic + Metadata: + aws:cdk:path: cdk-toolkit-integration-test-1/topic/Resource HERE @@ -17,8 +19,12 @@ assert "cdk synth cdk-toolkit-integration-test-2" <<HERE Resources: topic152D84A37: Type: AWS::SNS::Topic + Metadata: + aws:cdk:path: cdk-toolkit-integration-test-2/topic1/Resource topic2A4FB547F: Type: AWS::SNS::Topic + Metadata: + aws:cdk:path: cdk-toolkit-integration-test-2/topic2/Resource HERE diff --git a/packages/aws-cdk/lib/command-api.ts b/packages/aws-cdk/lib/command-api.ts new file mode 100644 index 0000000000000..dff4faeb5200a --- /dev/null +++ b/packages/aws-cdk/lib/command-api.ts @@ -0,0 +1,28 @@ +import yargs = require('yargs'); +import { AppStacks } from './api/cxapp/stacks'; +import { SDK } from './api/util/sdk'; +import { Configuration } from './settings'; + +/** + * Command handlers are supposed to be (args) => void, but ours are actually + * (args) => Promise<number>, so we deal with the asyncness by copying the actual + * handler object to `args.commandHandler` which will be executed an 'await'ed later on + * (instead of awaiting 'main'). + * + * Also adds exception handling so individual command handlers don't all have to do it. + */ + +/** + * The parts of the world that our command functions have access to + */ +export interface CommandOptions { + args: yargs.Arguments; + configuration: Configuration; + appStacks: AppStacks; + aws: SDK; +} + +/** + * This is the type of the *real* async command handlers + */ +export type CommandHandler = (options: CommandOptions) => Promise<number>; \ No newline at end of file diff --git a/packages/aws-cdk/lib/commands/context.ts b/packages/aws-cdk/lib/commands/context.ts index e77d0cbf35864..3ba0ffc494ea2 100644 --- a/packages/aws-cdk/lib/commands/context.ts +++ b/packages/aws-cdk/lib/commands/context.ts @@ -2,7 +2,8 @@ import colors = require('colors/safe'); import table = require('table'); import yargs = require('yargs'); import { print } from '../../lib/logging'; -import { Configuration, DEFAULTS } from '../settings'; +import { CommandOptions } from '../command-api'; +import { DEFAULTS } from '../settings'; export const command = 'context'; export const describe = 'Manage cached context values'; @@ -19,9 +20,12 @@ export const builder = { }, }; -export async function handler(args: yargs.Arguments): Promise<number> { - const configuration = new Configuration(); - await configuration.load(); +export function handler(args: yargs.Arguments) { + args.commandHandler = realHandler; +} + +export async function realHandler(options: CommandOptions): Promise<number> { + const { configuration, args } = options; const context = configuration.projectConfig.get(['context']) || {}; diff --git a/packages/aws-cdk/lib/commands/docs.ts b/packages/aws-cdk/lib/commands/docs.ts index 65280f572ecfe..a3b1424b4662e 100644 --- a/packages/aws-cdk/lib/commands/docs.ts +++ b/packages/aws-cdk/lib/commands/docs.ts @@ -3,6 +3,7 @@ import colors = require('colors/safe'); import process = require('process'); import yargs = require('yargs'); import { debug, print, warning } from '../../lib/logging'; +import { CommandOptions } from '../command-api'; export const command = 'docs'; export const describe = 'Opens the documentation in a browser'; @@ -20,11 +21,15 @@ export interface Arguments extends yargs.Arguments { browser: string } -export function handler(argv: Arguments): Promise<number> { +export function handler(args: yargs.Arguments) { + args.commandHandler = realHandler; +} + +export async function realHandler(options: CommandOptions): Promise<number> { const docVersion = require('../../package.json').version; const url = `https://awslabs.github.io/aws-cdk/versions/${docVersion}/`; print(colors.green(url)); - const browserCommand = argv.browser.replace(/%u/g, url); + const browserCommand = options.args.browser.replace(/%u/g, url); debug(`Opening documentation ${colors.green(browserCommand)}`); return new Promise<number>((resolve, _reject) => { childProcess.exec(browserCommand, (err, stdout, stderr) => { diff --git a/packages/aws-cdk/lib/commands/doctor.ts b/packages/aws-cdk/lib/commands/doctor.ts index f3cbeee5d69ae..4fd301c2ff16e 100644 --- a/packages/aws-cdk/lib/commands/doctor.ts +++ b/packages/aws-cdk/lib/commands/doctor.ts @@ -1,13 +1,19 @@ import colors = require('colors/safe'); import process = require('process'); +import yargs = require('yargs'); import { print } from '../../lib/logging'; import { VERSION } from '../../lib/version'; +import { CommandOptions } from '../command-api'; export const command = 'doctor'; export const describe = 'Check your set-up for potential problems'; export const builder = {}; -export async function handler(): Promise<number> { +export function handler(args: yargs.Arguments) { + args.commandHandler = realHandler; +} + +export async function realHandler(_options: CommandOptions): Promise<number> { let exitStatus: number = 0; for (const verification of verifications) { if (!await verification()) { diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 07ff6716c0aaf..cb5447859c059 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -58,10 +58,6 @@ export class Configuration { } } -export async function saveProjectConfig(settings: Settings) { - return settings.save(DEFAULTS); -} - /** * A single set of settings */ diff --git a/packages/aws-cdk/test/test.cdk-docs.ts b/packages/aws-cdk/test/test.cdk-docs.ts index ac1836b2533c8..4bec94256a911 100644 --- a/packages/aws-cdk/test/test.cdk-docs.ts +++ b/packages/aws-cdk/test/test.cdk-docs.ts @@ -1,7 +1,11 @@ import mockery = require('mockery'); import { ICallbackFunction, Test, testCase } from 'nodeunit'; +import { CommandHandler } from '../lib/command-api'; -const argv = { browser: 'echo %u' }; +const argv = { + browser: 'echo %u', + commandHandler: undefined as (CommandHandler | undefined), +}; module.exports = testCase({ '`cdk docs`': { @@ -22,7 +26,10 @@ module.exports = testCase({ }, async 'exits with 0 when everything is OK'(test: Test) { try { - const result = await require('../lib/commands/docs').handler(argv); + require('../lib/commands/docs').handler(argv); + const result = await argv.commandHandler!({ + args: argv + } as any); test.equal(result, 0, 'exit status was 0'); } catch (e) { test.doesNotThrow(() => { throw e; }); @@ -37,7 +44,10 @@ module.exports = testCase({ } }); try { - const result = await require('../lib/commands/docs').handler(argv); + require('../lib/commands/docs').handler(argv); + const result = await argv.commandHandler!({ + args: argv + } as any); test.equal(result, 0, 'exit status was 0'); } catch (e) { test.doesNotThrow(() => { throw e; }); diff --git a/packages/aws-cdk/test/test.cdk-doctor.ts b/packages/aws-cdk/test/test.cdk-doctor.ts index cfb00f38ecddd..0443e723bace1 100644 --- a/packages/aws-cdk/test/test.cdk-doctor.ts +++ b/packages/aws-cdk/test/test.cdk-doctor.ts @@ -1,5 +1,6 @@ import mockery = require('mockery'); import { ICallbackFunction, Test, testCase } from 'nodeunit'; +import { CommandHandler } from '../lib/command-api'; module.exports = testCase({ '`cdk doctor`': { @@ -16,8 +17,12 @@ module.exports = testCase({ cb(); }, async 'exits with 0 when everything is OK'(test: Test) { + const argv: any = {}; try { - const result = await require('../lib/commands/doctor').handler(); + require('../lib/commands/doctor').handler(argv); + const result = await (argv.commandHandler as CommandHandler)({ + args: argv + } as any); test.equal(result, 0, 'exit status was 0'); } catch (e) { test.doesNotThrow(() => e); diff --git a/scripts/build-typescript.sh b/scripts/build-typescript.sh index 98bc1dbd77538..ac691e1124a4c 100755 --- a/scripts/build-typescript.sh +++ b/scripts/build-typescript.sh @@ -14,7 +14,7 @@ cat <<EOF > tsconfig.json "es2017.string" ], "module": "CommonJS", - "noEmitOnError": true, + "noEmitOnError": false, "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "noImplicitReturns": true, From 10b7092b92a401d683905f1bc3cd47b7a9dcb5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Lamand=C3=A9?= <jlamande@gmail.com> Date: Mon, 26 Nov 2018 11:14:46 +0100 Subject: [PATCH 6/6] fix(aws-cloudfront): Allow to disable IPv6 on cloudfront distribution (#1244) Fixes #1243 --- .../aws-cloudfront/lib/web_distribution.ts | 2 +- ...teg.cloudfront-ipv6-disabled.expected.json | 53 +++++++++++++++++++ .../test/integ.cloudfront-ipv6-disabled.ts | 24 +++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.expected.json create mode 100644 packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index f6e691866fc74..456c3a0e7021a 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -532,7 +532,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements route53. defaultRootObject: props.defaultRootObject !== undefined ? props.defaultRootObject : "index.html", httpVersion: props.httpVersion || HttpVersion.HTTP2, priceClass: props.priceClass || PriceClass.PriceClass100, - ipv6Enabled: props.enableIpV6 || true, + ipv6Enabled: (props.enableIpV6 !== undefined) ? props.enableIpV6 : true, // tslint:disable-next-line:max-line-length customErrorResponses: props.errorConfigurations, // TODO: validation : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-customerrorresponse.html#cfn-cloudfront-distribution-customerrorresponse-errorcachingminttl webAclId: props.webACLId, diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.expected.json b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.expected.json new file mode 100644 index 0000000000000..0bf449d269685 --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.expected.json @@ -0,0 +1,53 @@ +{ + "Resources": { + "Bucket83908E77": { + "Type": "AWS::S3::Bucket" + }, + "MyDistributionCFDistributionDE147309": { + "Type": "AWS::CloudFront::Distribution", + "Properties": { + "DistributionConfig": { + "CacheBehaviors": [], + "DefaultCacheBehavior": { + "AllowedMethods": [ + "GET", + "HEAD" + ], + "CachedMethods": [ + "GET", + "HEAD" + ], + "ForwardedValues": { + "Cookies": { + "Forward": "none" + }, + "QueryString": false + }, + "TargetOriginId": "origin1", + "ViewerProtocolPolicy": "redirect-to-https" + }, + "DefaultRootObject": "index.html", + "Enabled": true, + "HttpVersion": "http2", + "IPV6Enabled": false, + "Origins": [ + { + "DomainName": { + "Fn::GetAtt": [ + "Bucket83908E77", + "DomainName" + ] + }, + "Id": "origin1", + "S3OriginConfig": {} + } + ], + "PriceClass": "PriceClass_100", + "ViewerCertificate": { + "CloudFrontDefaultCertificate": true + } + } + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts new file mode 100644 index 0000000000000..55be5891f9acc --- /dev/null +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts @@ -0,0 +1,24 @@ + +import s3 = require('@aws-cdk/aws-s3'); +import cdk = require('@aws-cdk/cdk'); +import cloudfront = require('../lib'); + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-cloudfront'); + +const sourceBucket = new s3.Bucket(stack, 'Bucket'); + +new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', { + originConfigs: [ + { + s3OriginSource: { + s3BucketSource: sourceBucket + }, + behaviors : [ {isDefaultBehavior: true}] + } + ], + enableIpV6: false + }); + +app.run();