Skip to content

Commit

Permalink
Merge branch 'main' into otaviom/awslint-save
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 2, 2022
2 parents e2440f9 + 2430537 commit fcb90fa
Show file tree
Hide file tree
Showing 404 changed files with 3,899 additions and 3,474 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cdk.context.json
.cdk.staging/
cdk.out/
*.tabl.json
cdk-integ.out.*/

# Yarn error log
yarn-error.log
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.50.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.49.1-alpha.0...v2.50.0-alpha.0) (2022-11-01)


### Features

* **synthetics:** aws synthetics runtime version syn-nodejs-puppeteer-3.8 ([#22707](https://github.com/aws/aws-cdk/issues/22707)) ([228c865](https://github.com/aws/aws-cdk/commit/228c86532118b143e365b2268d06ee3a36fcf3a7))

## [2.49.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.49.0-alpha.0...v2.49.1-alpha.0) (2022-10-31)

## [2.49.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.48.0-alpha.0...v2.49.0-alpha.0) (2022-10-27)
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.50.0](https://github.com/aws/aws-cdk/compare/v2.49.1...v2.50.0) (2022-11-01)


### Features

* **aws-ecs-patterns:** entryPoint and command support within ApplicationLoadBalancedFargateService and ApplicationLoadBalancedEc2Service ([#22609](https://github.com/aws/aws-cdk/issues/22609)) ([6925293](https://github.com/aws/aws-cdk/commit/6925293047ff02fbe68234740327f3513a86ef74)), closes [#17092](https://github.com/aws/aws-cdk/issues/17092)
* **codedeploy:** CodeDeploy deployment group construct for ECS ([#22295](https://github.com/aws/aws-cdk/issues/22295)) ([efd24d1](https://github.com/aws/aws-cdk/commit/efd24d1bb9bc1c113e81e033012d99b7d5f8a146)), closes [#1559](https://github.com/aws/aws-cdk/issues/1559)
* **core:** automatic cross stack, cross region references (under feature flag) ([#22008](https://github.com/aws/aws-cdk/issues/22008)) ([f1b5497](https://github.com/aws/aws-cdk/commit/f1b5497879b4ba117723dad4255082f081d4fec7))
* **ec2:** Vpc supports reserving space for future AZs ([#22705](https://github.com/aws/aws-cdk/issues/22705)) ([7b51ea9](https://github.com/aws/aws-cdk/commit/7b51ea9ae1e61d57b8ed6b99510cf26d423bb991))
* **stepfunctions:** add intrinsic functions ([#22431](https://github.com/aws/aws-cdk/issues/22431)) ([8f85b08](https://github.com/aws/aws-cdk/commit/8f85b081724d425f452babe1f38f4cda211c17b9)), closes [#22068](https://github.com/aws/aws-cdk/issues/22068) [#22629](https://github.com/aws/aws-cdk/issues/22629)


### Bug Fixes

* **opensearch:** log group policies ignore incorrect error code on delete ([#22364](https://github.com/aws/aws-cdk/issues/22364)) ([ebba9e3](https://github.com/aws/aws-cdk/commit/ebba9e371c22542a5ae98bbd0e6a2f130eef77d6))
* revert jsii to version 1.69.0 ([#22715](https://github.com/aws/aws-cdk/issues/22715)) ([0837c1a](https://github.com/aws/aws-cdk/commit/0837c1a6af705474dfe127203c2b99a6ff201d77))
* **apigateway:** race condition exists between stage and cfnaccount in specrestapi ([#22671](https://github.com/aws/aws-cdk/issues/22671)) ([4cb008b](https://github.com/aws/aws-cdk/commit/4cb008bd6d27a8e3366ea600a8b9027f15ae6dcd)), closes [#18925](https://github.com/aws/aws-cdk/issues/18925)
* **aws-events:** restrict eventbus statementId to 64 characters ([#22296](https://github.com/aws/aws-cdk/issues/22296)) ([fadbfc1](https://github.com/aws/aws-cdk/commit/fadbfc1eb07f4f2daecfe623812fee029c81e31a)), closes [#22120](https://github.com/aws/aws-cdk/issues/22120) [#21808](https://github.com/aws/aws-cdk/issues/21808)
* **stepfunctions-tasks:** athenaStartQueryExecution task generates invalid s3 arn ([#22692](https://github.com/aws/aws-cdk/issues/22692)) ([6e0cb2b](https://github.com/aws/aws-cdk/commit/6e0cb2ba2e1bfb55d183e65c811d4e17a80cc4b8)), closes [#22608](https://github.com/aws/aws-cdk/issues/22608)

## [2.49.1](https://github.com/aws/aws-cdk/compare/v2.49.0...v2.49.1) (2022-10-31)


Expand Down
25 changes: 23 additions & 2 deletions packages/@aws-cdk/assertions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ The following code asserts that the `Properties` section of a resource of type

```ts
template.hasResourceProperties('Foo::Bar', {
Foo: 'Bar',
Lorem: 'Ipsum',
Baz: 5,
Qux: [ 'Waldo', 'Fred' ],
});
```

You can also assert that the `Properties` section of all resources of type
`Foo::Bar` contains the specified properties -

```ts
template.allResourcesProperties('Foo::Bar', {
Lorem: 'Ipsum',
Baz: 5,
Qux: [ 'Waldo', 'Fred' ],
});
Expand All @@ -113,7 +124,17 @@ can use the `hasResource()` API.

```ts
template.hasResource('Foo::Bar', {
Properties: { Foo: 'Bar' },
Properties: { Lorem: 'Ipsum' },
DependsOn: [ 'Waldo', 'Fred' ],
});
```

You can also assert the definitions of all resources of a type using the
`allResources()` API.

```ts
template.allResources('Foo::Bar', {
Properties: { Lorem: 'Ipsum' },
DependsOn: [ 'Waldo', 'Fred' ],
});
```
Expand Down
38 changes: 37 additions & 1 deletion packages/@aws-cdk/assertions/lib/private/resources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Match, Matcher } from '..';
import { AbsentMatch } from './matchers/absent';
import { formatFailure, matchSection } from './section';
import { formatAllMismatches, formatFailure, matchSection } from './section';
import { Resource, Template } from './template';

export function findResources(template: Template, type: string, props: any = {}): { [key: string]: { [key: string]: any } } {
Expand All @@ -14,6 +14,42 @@ export function findResources(template: Template, type: string, props: any = {})
return result.matches;
}

export function allResources(template: Template, type: string, props: any): string | void {
const section = template.Resources ?? {};
const result = matchSection(filterType(section, type), props);
if (result.match) {
const matchCount = Object.keys(result.matches).length;
if (result.analyzedCount > matchCount) {
return [
`Template has ${result.analyzedCount} resource(s) with type ${type}, but only ${matchCount} match as expected.`,
formatAllMismatches(result.analyzed, result.matches),
].join('\n');
}
} else {
return [
`Template has ${result.analyzedCount} resource(s) with type ${type}, but none match as expected.`,
formatAllMismatches(result.analyzed),
].join('\n');
}
}

export function allResourcesProperties(template: Template, type: string, props: any): string | void {
let amended = template;

// special case to exclude AbsentMatch because adding an empty Properties object will affect its evaluation.
if (!Matcher.isMatcher(props) || !(props instanceof AbsentMatch)) {
// amended needs to be a deep copy to avoid modifying the template.
amended = JSON.parse(JSON.stringify(template));
amended = addEmptyProperties(amended);
}

return allResources(amended, type, Match.objectLike({
Properties: props,
}));

}


export function hasResource(template: Template, type: string, props: any): string | void {
const section = template.Resources ?? {};
const result = matchSection(filterType(section, type), props);
Expand Down
25 changes: 16 additions & 9 deletions packages/@aws-cdk/assertions/lib/private/section.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
import { Match } from '../match';
import { Matcher, MatchResult } from '../matcher';

export type MatchSuccess = { match: true, matches: {[key: string]: any} };
export type MatchFailure = { match: false, closestResult?: MatchResult, analyzedCount: number };
export type MatchSuccess = { match: true, matches: { [key: string]: any }, analyzed: { [key: string]: any }, analyzedCount: number };
export type MatchFailure = { match: false, closestResult?: MatchResult, analyzed: { [key: string]: any }, analyzedCount: number };

export function matchSection(section: any, props: any): MatchSuccess | MatchFailure {
const matcher = Matcher.isMatcher(props) ? props : Match.objectLike(props);
let closestResult: MatchResult | undefined = undefined;
let matching: {[key: string]: any} = {};
let count = 0;
let matching: { [key: string]: any } = {};
let analyzed: { [key: string]: any } = {};

eachEntryInSection(
section,

(logicalId, entry) => {
analyzed[logicalId] = entry;
const result = matcher.test(entry);
result.finished();
if (!result.hasFailed()) {
matching[logicalId] = entry;
} else {
count++;
if (closestResult === undefined || closestResult.failCount > result.failCount) {
closestResult = result;
}
}
},
);
if (Object.keys(matching).length > 0) {
return { match: true, matches: matching };
return { match: true, matches: matching, analyzedCount: Object.keys(analyzed).length, analyzed: analyzed };
} else {
return { match: false, closestResult, analyzedCount: count };
return { match: false, closestResult, analyzedCount: Object.keys(analyzed).length, analyzed: analyzed };
}
}

function eachEntryInSection(
section: any,
cb: (logicalId: string, entry: {[key: string]: any}) => void): void {
cb: (logicalId: string, entry: { [key: string]: any }) => void): void {

for (const logicalId of Object.keys(section ?? {})) {
const resource: { [key: string]: any } = section[logicalId];
cb(logicalId, resource);
}
}

export function formatAllMatches(matches: {[key: string]: any}): string {
export function formatAllMatches(matches: { [key: string]: any }): string {
return [
leftPad(JSON.stringify(matches, undefined, 2)),
].join('\n');
}

export function formatAllMismatches(analyzed: { [key: string]: any }, matches: { [key: string]: any } = {}): string {
return [
'The following resources do not match the given definition:',
...Object.keys(analyzed).filter(id => !(id in matches)).map(id => `\t${id}`),
].join('\n');
}

export function formatFailure(closestResult: MatchResult): string {
return [
'The closest result is:',
Expand Down
34 changes: 32 additions & 2 deletions packages/@aws-cdk/assertions/lib/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkTemplateForCyclicDependencies } from './private/cyclic';
import { findMappings, hasMapping } from './private/mappings';
import { findOutputs, hasOutput } from './private/outputs';
import { findParameters, hasParameter } from './private/parameters';
import { countResources, countResourcesProperties, findResources, hasResource, hasResourceProperties } from './private/resources';
import { allResources, allResourcesProperties, countResources, countResourcesProperties, findResources, hasResource, hasResourceProperties } from './private/resources';
import { Template as TemplateType } from './private/template';

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ export class Template {
* By default, performs partial matching on the resource, via the `Match.objectLike()`.
* To configure different behavour, use other matchers in the `Match` class.
* @param type the resource type; ex: `AWS::S3::Bucket`
* @param props the entire defintion of the resource as should be expected in the template.
* @param props the entire definition of the resource as should be expected in the template.
*/
public hasResource(type: string, props: any): void {
const matchError = hasResource(this.template, type, props);
Expand All @@ -134,6 +134,36 @@ export class Template {
return findResources(this.template, type, props);
}

/**
* Assert that all resources of the given type contain the given definition in the
* CloudFormation template.
* By default, performs partial matching on the resource, via the `Match.objectLike()`.
* To configure different behavour, use other matchers in the `Match` class.
* @param type the resource type; ex: `AWS::S3::Bucket`
* @param props the entire definition of the resources as they should be expected in the template.
*/
public allResources(type: string, props: any): void {
const matchError = allResources(this.template, type, props);
if (matchError) {
throw new Error(matchError);
}
}

/**
* Assert that all resources of the given type contain the given properties
* CloudFormation template.
* By default, performs partial matching on the `Properties` key of the resource, via the
* `Match.objectLike()`. To configure different behavour, use other matchers in the `Match` class.
* @param type the resource type; ex: `AWS::S3::Bucket`
* @param props the 'Properties' section of the resource as should be expected in the template.
*/
public allResourcesProperties(type: string, props: any): void {
const matchError = allResourcesProperties(this.template, type, props);
if (matchError) {
throw new Error(matchError);
}
}

/**
* Assert that a Parameter with the given properties exists in the CloudFormation template.
* By default, performs partial matching on the parameter, via the `Match.objectLike()`.
Expand Down
Loading

0 comments on commit fcb90fa

Please sign in to comment.