Skip to content

Commit

Permalink
Merge branch 'master' into eks-pinger-subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 11, 2021
2 parents 038e98d + f7c3217 commit c8a444b
Show file tree
Hide file tree
Showing 176 changed files with 2,839 additions and 822 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@
"nohoist": [
"**/jszip",
"**/jszip/**",
"@aws-cdk/assertions-alpha/fs-extra",
"@aws-cdk/assertions-alpha/fs-extra/**",
"@aws-cdk/assertions/fs-extra",
"@aws-cdk/assertions/fs-extra/**",
"@aws-cdk/aws-amplify-alpha/yaml",
"@aws-cdk/aws-amplify-alpha/yaml/**",
"@aws-cdk/aws-iot-actions-alpha/case",
"@aws-cdk/aws-iot-actions-alpha/case/**",
"@aws-cdk/aws-amplify/yaml",
"@aws-cdk/aws-amplify/yaml/**",
"@aws-cdk/aws-codebuild/yaml",
Expand All @@ -87,6 +93,8 @@
"@aws-cdk/aws-eks/yaml/**",
"@aws-cdk/aws-events-targets/aws-sdk",
"@aws-cdk/aws-events-targets/aws-sdk/**",
"@aws-cdk/aws-iot-actions/case",
"@aws-cdk/aws-iot-actions/case/**",
"@aws-cdk/aws-s3-deployment/case",
"@aws-cdk/aws-s3-deployment/case/**",
"@aws-cdk/cloud-assembly-schema/jsonschema",
Expand Down
88 changes: 87 additions & 1 deletion packages/@aws-cdk/assertions/NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,88 @@
AWS Cloud Development Kit (AWS CDK)
Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

-------------------------------------------------------------------------------

The AWS CDK includes the following third-party software/licensing:

** fs-extra - https://www.npmjs.com/package/fs-extra
Copyright (c) 2011-2017 JP Richardson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------

** at-least-node - https://www.npmjs.com/package/at-least-node
Copyright (c) 2020 Ryan Zimmerman <opensrc@ryanzim.com>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

----------------

** graceful-fs - https://www.npmjs.com/package/graceful-fs
Copyright (c) Isaac Z. Schlueter, Ben Noordhuis, and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

----------------

** jsonfile - https://www.npmjs.com/package/jsonfile
Copyright (c) 2012-2015, JP Richardson <jprichardson@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------

** universalify - https://www.npmjs.com/package/universalify
Copyright (c) 2017, Ryan Zimmerman <opensrc@ryanzim.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------
6 changes: 6 additions & 0 deletions packages/@aws-cdk/assertions/lib/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as path from 'path';
import { Stack, Stage } from '@aws-cdk/core';
import * as fs from 'fs-extra';
import { Match } from './match';
import { Matcher } from './matcher';
import { findMappings, hasMapping } from './private/mappings';
Expand Down Expand Up @@ -179,5 +181,9 @@ function toTemplate(stack: Stack): any {
throw new Error('unexpected: all stacks must be part of a Stage or an App');
}
const assembly = root.synth();
if (stack.nestedStackParent) {
// if this is a nested stack (it has a parent), then just read the template as a string
return JSON.parse(fs.readFileSync(path.join(assembly.directory, stack.templateFile)).toString('utf-8'));
}
return assembly.getStackArtifact(stack.artifactId).template;
}
9 changes: 7 additions & 2 deletions packages/@aws-cdk/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"metadata": {
"jsii": {
"rosetta": {
"strict": false
"strict": true
}
}
}
Expand All @@ -64,6 +64,7 @@
"devDependencies": {
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.0.2",
"constructs": "^3.3.69",
"jest": "^27.3.1",
Expand All @@ -73,14 +74,18 @@
"@aws-cdk/cloud-assembly-schema": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/cx-api": "0.0.0",
"constructs": "^3.3.69"
"constructs": "^3.3.69",
"fs-extra": "^9.1.0"
},
"peerDependencies": {
"@aws-cdk/cloud-assembly-schema": "0.0.0",
"@aws-cdk/core": "0.0.0",
"@aws-cdk/cx-api": "0.0.0",
"constructs": "^3.3.69"
},
"bundledDependencies": [
"fs-extra"
],
"repository": {
"url": "https://github.com/aws/aws-cdk.git",
"type": "git",
Expand Down
44 changes: 35 additions & 9 deletions packages/@aws-cdk/assertions/test/template.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { App, CfnMapping, CfnOutput, CfnResource, Stack } from '@aws-cdk/core';
import { App, CfnMapping, CfnOutput, CfnResource, NestedStack, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { Match, Template } from '../lib';

describe('Template', () => {
describe('asObject', () => {
test('fromString', () => {
const template = Template.fromString(`{
test('fromString', () => {
const template = Template.fromString(`{
"Resources": {
"Foo": {
"Type": "Baz::Qux",
Expand All @@ -14,30 +13,57 @@ describe('Template', () => {
}
}`);

expect(template.toJSON()).toEqual({
Resources: {
Foo: {
Type: 'Baz::Qux',
Properties: { Fred: 'Waldo' },
},
},
});
});

describe('fromStack', () => {
test('default', () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
const stack = new Stack(app);
new CfnResource(stack, 'Foo', {
type: 'Foo::Bar',
properties: {
Baz: 'Qux',
},
});
const template = Template.fromStack(stack);

expect(template.toJSON()).toEqual({
Resources: {
Foo: {
Type: 'Baz::Qux',
Properties: { Fred: 'Waldo' },
Type: 'Foo::Bar',
Properties: { Baz: 'Qux' },
},
},
});
});

test('fromStack', () => {
test('nested', () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
const stack = new Stack(app);
new CfnResource(stack, 'Foo', {
const nested = new NestedStack(stack, 'MyNestedStack');
new CfnResource(nested, 'Foo', {
type: 'Foo::Bar',
properties: {
Baz: 'Qux',
},
});
const template = Template.fromStack(stack);
const template = Template.fromStack(nested);

expect(template.toJSON()).toEqual({
Resources: {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"aws-cdk": "0.0.0",
"jest": "^27.3.1",
"sinon": "^9.2.4",
"ts-mock-imports": "^1.3.7"
"ts-mock-imports": "^1.3.8"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
Expand Down
27 changes: 27 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/api-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import * as s3_assets from '@aws-cdk/aws-s3-assets';

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import * as cxapi from '@aws-cdk/cx-api';
import { Node } from 'constructs';
import { CfnRestApi } from './apigateway.generated';
import { IRestApi } from './restapi';
import { Construct } from '@aws-cdk/core';

/**
Expand Down Expand Up @@ -82,6 +86,15 @@ export abstract class ApiDefinition {
* assume it's initialized. You may just use it as a construct scope.
*/
public abstract bind(scope: Construct): ApiDefinitionConfig;

/**
* Called after the CFN RestApi resource has been created to allow the Api
* Definition to bind to it. Specifically it's required to allow assets to add
* metadata for tooling like SAM CLI to be able to find their origins.
*/
public bindAfterCreate(_scope: Construct, _restApi: IRestApi) {
return;
}
}

/**
Expand Down Expand Up @@ -198,4 +211,18 @@ export class AssetApiDefinition extends ApiDefinition {
},
};
}

public bindAfterCreate(scope: Construct, restApi: IRestApi) {
if (!scope.node.tryGetContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT)) {
return; // not enabled
}

if (!this.asset) {
throw new Error('bindToResource() must be called after bind()');
}

const child = Node.of(restApi).defaultChild as CfnRestApi;
child.addMetadata(cxapi.ASSET_RESOURCE_METADATA_PATH_KEY, this.asset.assetPath);
child.addMetadata(cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY, 'BodyS3Location');
}
}
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ export class SpecRestApi extends RestApiBase {
endpointConfiguration: this._configureEndpoints(props),
parameters: props.parameters,
});

props.apiDefinition.bindAfterCreate(this, this);

this.node.defaultChild = resource;
this.restApiId = resource.ref;
this.restApiRootResourceId = resource.attrRootResourceId;
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
]
}
},
"projectReferences": true
"projectReferences": true,
"metadata": {
"jsii": {
"rosetta": {
"strict": true
}
}
}
},
"repository": {
"type": "git",
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/api-definition.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import '@aws-cdk/assert-internal/jest';
import * as path from 'path';
import { ResourcePart } from '@aws-cdk/assert-internal';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import * as apigw from '../lib';

describe('api definition', () => {
Expand Down Expand Up @@ -73,6 +75,23 @@ describe('api definition', () => {
expect(synthesized.assets.length).toEqual(1);

});

test('asset metadata added to RestApi resource that contains Asset Api Definition', () => {
const stack = new cdk.Stack();
stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true);
const assetApiDefinition = apigw.ApiDefinition.fromAsset(path.join(__dirname, 'sample-definition.yaml'));
new apigw.SpecRestApi(stack, 'API', {
apiDefinition: assetApiDefinition,
});

expect(stack).toHaveResource('AWS::ApiGateway::RestApi', {
Metadata: {
'aws:asset:path': 'asset.68497ac876de4e963fc8f7b5f1b28844c18ecc95e3f7c6e9e0bf250e03c037fb.yaml',
'aws:asset:property': 'BodyS3Location',
},
}, ResourcePart.CompleteDefinition);

});
});

describe('apigateway.ApiDefinition.fromBucket', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
]
}
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyAuthorizerFunctionServiceRole8A34C19E",
"Arn"
]
},
"Runtime": "nodejs10.x"
"Handler": "index.handler",
"Runtime": "nodejs14.x"
},
"DependsOn": [
"MyAuthorizerFunctionServiceRole8A34C19E"
Expand Down Expand Up @@ -313,4 +313,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const app = new App();
const stack = new Stack(app, 'RequestAuthorizerInteg');

const authorizerFn = new lambda.Function(stack, 'MyAuthorizerFunction', {
runtime: lambda.Runtime.NODEJS_10_X,
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.AssetCode.fromAsset(path.join(__dirname, 'integ.request-authorizer.handler')),
});
Expand Down
Loading

0 comments on commit c8a444b

Please sign in to comment.