Skip to content

Commit

Permalink
Merge branch 'master' into refactor/routeSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 19, 2020
2 parents 36d1a97 + 9fe0dad commit 7b8521d
Show file tree
Hide file tree
Showing 41 changed files with 311 additions and 184 deletions.
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
});
```

You can find a full working example [here](test/authorizers/integ.token-authorizer.ts).
A full working example is shown below.

[Full token authorizer example](test/authorizers/integ.token-authorizer.lit.ts).

By default, the `TokenAuthorizer` looks for the authorization token in the request header with the key 'Authorization'. This can,
however, be modified by changing the `identitySource` property.
Expand Down Expand Up @@ -565,7 +567,9 @@ books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
});
```

You can find a full working example [here](test/authorizers/integ.request-authorizer.ts).
A full working example is shown below.

[Full request authorizer example](test/authorizers/integ.request-authorizer.lit.ts).

By default, the `RequestAuthorizer` does not pass any kind of information from the request. This can,
however, be modified by changing the `identitySource` property, and is required when specifying a value for caching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront-origins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"pkglint": "0.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ your users. CloudFront delivers your content through a worldwide network of data
you're serving with CloudFront, the user is routed to the edge location that provides the lowest latency, so that content is delivered with the best
possible performance.

## Distribution API - Experimental
## Distribution API - Developer Preview

![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
![Developer Preview](https://img.shields.io/badge/developer--preview-informational.svg?style=for-the-badge)

The `Distribution` API is currently being built to replace the existing `CloudFrontWebDistribution` API. The `Distribution` API is optimized for the
most common use cases of CloudFront distributions (e.g., single origin and behavior, few customizations) while still providing the ability for more
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@aws-cdk/aws-sns": "0.0.0",
"@aws-cdk/aws-sqs": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-sns": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface GitHubSourceActionProps extends codepipeline.CommonActionProps
* * **repo** - to read the repository
* * **admin:repo_hook** - if you plan to use webhooks (true by default)
*
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/GitHub-create-personal-token-CLI.html
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/appendix-github-oauth.html#GitHub-create-personal-token-CLI
*/
readonly oauthToken: SecretValue;

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/jest": "^26.0.15",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"@types/yaml": "1.9.6",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events-targets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-s3": "0.0.0",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-sqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-s3": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.795.0",
"aws-sdk": "^2.796.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
121 changes: 1 addition & 120 deletions packages/@aws-cdk/cfnspec/build-tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/

import * as path from 'path';
import * as fastJsonPatch from 'fast-json-patch';
import * as fs from 'fs-extra';
import * as md5 from 'md5';
import { schema } from '../lib';
import { detectScrutinyTypes } from './scrutiny';
import { decorateResourceTypes, forEachSection, massageSpec, merge, normalize, patch } from './massage-spec';

async function main() {
const inputDir = path.join(process.cwd(), 'spec-source');
Expand All @@ -35,124 +34,6 @@ async function main() {
await fs.writeJson(path.join(outDir, 'specification.json'), spec, { spaces: 2 });
}

export function massageSpec(spec: schema.Specification) {
detectScrutinyTypes(spec);
replaceIncompleteTypes(spec);
dropTypelessAttributes(spec);
}

function forEachSection(spec: schema.Specification, data: any, cb: (spec: any, fragment: any, path: string[]) => void) {
cb(spec.PropertyTypes, data.PropertyTypes, ['PropertyTypes']);
cb(spec.ResourceTypes, data.ResourceTypes, ['ResourceTypes']);
// Per-resource specs are keyed on ResourceType (singular), but we want it in ResourceTypes (plural)
cb(spec.ResourceTypes, data.ResourceType, ['ResourceType']);
}

function decorateResourceTypes(data: any) {
const requiredTransform = data.ResourceSpecificationTransform as string | undefined;
if (!requiredTransform) { return; }
const resourceTypes = data.ResourceTypes || data.ResourceType;
for (const name of Object.keys(resourceTypes)) {
resourceTypes[name].RequiredTransform = requiredTransform;
}
}

/**
* Fix incomplete type definitions in PropertyTypes
*
* Some user-defined types are defined to not have any properties, and not
* be a collection of other types either. They have no definition at all.
*
* Add a property object type with empty properties.
*/
function replaceIncompleteTypes(spec: schema.Specification) {
for (const [name, definition] of Object.entries(spec.PropertyTypes)) {
if (!schema.isRecordType(definition)
&& !schema.isCollectionProperty(definition)
&& !schema.isScalarProperty(definition)
&& !schema.isPrimitiveProperty(definition)) {
// eslint-disable-next-line no-console
console.log(`[${name}] Incomplete type, adding empty "Properties" field`);

(definition as unknown as schema.RecordProperty).Properties = {};
}
}
}

/**
* Drop Attributes specified with the different ResourceTypes that have
* no type specified.
*/
function dropTypelessAttributes(spec: schema.Specification) {
const resourceTypes = spec.ResourceTypes;
Object.values(resourceTypes).forEach((resourceType) => {
const attributes = resourceType.Attributes ?? {};
Object.keys(attributes).forEach((attrKey) => {
const attrVal = attributes[attrKey];
if (Object.keys(attrVal).length === 0) {
delete attributes[attrKey];
}
});
});
}

function merge(spec: any, fragment: any, jsonPath: string[]) {
if (!fragment) { return; }
for (const key of Object.keys(fragment)) {
if (key in spec) {
const specVal = spec[key];
const fragVal = fragment[key];
if (typeof specVal !== typeof fragVal) {
// eslint-disable-next-line max-len
throw new Error(`Attempted to merge ${JSON.stringify(fragVal)} into incompatible ${JSON.stringify(specVal)} at path ${jsonPath.join('/')}/${key}`);
}
if (typeof specVal !== 'object') {
// eslint-disable-next-line max-len
throw new Error(`Conflict when attempting to merge ${JSON.stringify(fragVal)} into ${JSON.stringify(specVal)} at path ${jsonPath.join('/')}/${key}`);
}
merge(specVal, fragVal, [...jsonPath, key]);
} else {
spec[key] = fragment[key];
}
}
}

function patch(spec: any, fragment: any) {
if (!fragment) { return; }
if ('patch' in fragment) {
// eslint-disable-next-line no-console
console.log(`Applying patch: ${fragment.patch.description}`);
fastJsonPatch.applyPatch(spec, fragment.patch.operations);
} else {
for (const key of Object.keys(fragment)) {
patch(spec[key], fragment[key]);
}
}
}

/**
* Modifies the provided specification so that ``ResourceTypes`` and ``PropertyTypes`` are listed in alphabetical order.
*
* @param spec an AWS CloudFormation Resource Specification document.
*
* @returns ``spec``, after having sorted the ``ResourceTypes`` and ``PropertyTypes`` sections alphabetically.
*/
function normalize(spec: schema.Specification): schema.Specification {
spec.ResourceTypes = normalizeSection(spec.ResourceTypes);
if (spec.PropertyTypes) {
spec.PropertyTypes = normalizeSection(spec.PropertyTypes);
}
return spec;

function normalizeSection<T>(section: { [name: string]: T }): { [name: string]: T } {
const result: { [name: string]: T } = {};
for (const key of Object.keys(section).sort()) {
result[key] = section[key];
}
return result;
}
}

main()
.catch(e => {
// eslint-disable-next-line no-console
Expand Down
Loading

0 comments on commit 7b8521d

Please sign in to comment.