Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: readonly struct properties and hide internals #2106

Merged
merged 59 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d4ed3b6
upgrade to jsii 0.8.0
Mar 27, 2019
fc52de4
assert.SynthUtils
Mar 27, 2019
b2df442
cfn2ts: Add "readonly" to all props interfaces in L1
Mar 27, 2019
669e0db
applicationautoscaling
Mar 27, 2019
3ebf9ed
alexa-ask
Mar 27, 2019
29cc760
autoscaling
Mar 27, 2019
26bcd18
cloudwatch
Mar 27, 2019
13981e9
ec2
Mar 27, 2019
66eed07
events
Mar 27, 2019
8b9d1d8
iam
Mar 27, 2019
e173d32
kms
Mar 27, 2019
3a72dee
logs
Mar 27, 2019
28065c6
s3-notifications
Mar 27, 2019
3f4e401
stepfunctions
Mar 27, 2019
f676ba1
ssm
Mar 27, 2019
d6f3e1b
dynamodb
Mar 27, 2019
0f6df4d
foreach: show failing directory
Mar 27, 2019
2900060
ecr
Mar 27, 2019
812e00f
codepipeline-api
Mar 27, 2019
5958975
dynamodb
Mar 27, 2019
6254526
elb
Mar 27, 2019
b8b9efe
kinesis
Mar 27, 2019
703e538
route53
Mar 27, 2019
157435c
aws-s3
Mar 27, 2019
39ff7ea
rtv
Mar 27, 2019
404bb0d
elbv2
Mar 27, 2019
526dd7e
assets
Mar 27, 2019
407f439
cloudtrail
Mar 27, 2019
06174a4
glue
Mar 27, 2019
8db8c50
lambda
Mar 27, 2019
39b88d0
sqs
Mar 27, 2019
5b6a2a7
servicediscovery
Mar 27, 2019
1be83cb
apigateway
Mar 27, 2019
8121b97
cognito
Mar 27, 2019
4b9eaa3
secretsmanager
Mar 27, 2019
7f112cf
sns
Mar 27, 2019
a8be00b
autoscaling
Mar 27, 2019
a7843dd
rtv
Mar 27, 2019
f14e0cc
app-delivery
Mar 27, 2019
f2ea3b4
assets-docker
Mar 27, 2019
71d1d73
certificatemanager
Mar 27, 2019
da41b18
cloudformation
Mar 27, 2019
bdc3477
cloudfront
Mar 27, 2019
07ecbb2
codebuild
Mar 27, 2019
1ef6003
codecommit
Mar 27, 2019
b40bf00
codedeploy
Mar 27, 2019
16da6bb
codepipeline
Mar 27, 2019
de0eaaa
ecs
Mar 27, 2019
c830a87
eks
Mar 27, 2019
c341aae
lambda-event-sources
Mar 27, 2019
a07ef7a
quickstarts
Mar 27, 2019
1bdcd46
rds
Mar 27, 2019
758b379
s3-deployment
Mar 27, 2019
949379e
ses
Mar 27, 2019
ec500e1
upgrade jsii-reflect
Mar 27, 2019
4be60c7
random change to trigger PR build
Mar 27, 2019
d55f983
fix cloudfront
Mar 27, 2019
3a77bf0
another minor change to trigger PR build
Mar 27, 2019
987a50f
another minor change
Mar 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/@aws-cdk/alexa-ask/lib/pipeline-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ export interface AlexaSkillDeployActionProps extends codepipeline.CommonActionPr
/**
* The client id of the developer console token
*/
clientId: cdk.Secret;
readonly clientId: cdk.Secret;

/**
* The client secret of the developer console token
*/
clientSecret: cdk.Secret;
readonly clientSecret: cdk.Secret;

/**
* The refresh token of the developer console token
*/
refreshToken: cdk.Secret;
readonly refreshToken: cdk.Secret;

/**
* The Alexa skill id
*/
skillId: string;
readonly skillId: string;

/**
* The source artifact containing the voice model and skill manifest
*/
inputArtifact: codepipeline.Artifact;
readonly inputArtifact: codepipeline.Artifact;

/**
* An optional artifact containing overrides for the skill manifest
*/
parameterOverridesArtifact?: codepipeline.Artifact;
readonly parameterOverridesArtifact?: codepipeline.Artifact;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ export interface PipelineDeployStackActionProps {
/**
* The CDK stack to be deployed.
*/
stack: cdk.Stack;
readonly stack: cdk.Stack;

/**
* The CodePipeline stage in which to perform the deployment.
*/
stage: codepipeline.IStage;
readonly stage: codepipeline.IStage;

/**
* The CodePipeline artifact that holds the synthesized app, which is the
* contents of the ``<directory>`` when running ``cdk synth -o <directory>``.
*/
inputArtifact: codepipeline.Artifact;
readonly inputArtifact: codepipeline.Artifact;

/**
* The name to use when creating a ChangeSet for the stack.
*
* @default CDK-CodePipeline-ChangeSet
*/
changeSetName?: string;
readonly changeSetName?: string;

/**
* The runOrder for the CodePipeline action creating the ChangeSet.
*
* @default 1
*/
createChangeSetRunOrder?: number;
readonly createChangeSetRunOrder?: number;

/**
* The runOrder for the CodePipeline action executing the ChangeSet.
*
* @default ``createChangeSetRunOrder + 1``
*/
executeChangeSetRunOrder?: number;
readonly executeChangeSetRunOrder?: number;

/**
* IAM role to assume when deploying changes.
Expand All @@ -51,7 +51,7 @@ export interface PipelineDeployStackActionProps {
*
* @default A fresh role with admin or no permissions (depending on the value of `adminPermissions`).
*/
role?: iam.IRole;
readonly role?: iam.IRole;

/**
* Acknowledge certain changes made as part of deployment
Expand All @@ -64,7 +64,7 @@ export interface PipelineDeployStackActionProps {
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities
* @default AnonymousIAM, unless `adminPermissions` is true
*/
capabilities?: cfn.CloudFormationCapabilities;
readonly capabilities?: cfn.CloudFormationCapabilities;

/**
* Whether to grant admin permissions to CloudFormation while deploying this template.
Expand All @@ -81,7 +81,7 @@ export interface PipelineDeployStackActionProps {
* use `addToRolePolicy` and `capabilities` to control what the CloudFormation
* deployment is allowed to do.
*/
adminPermissions: boolean;
readonly adminPermissions: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/app-delivery/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/applet-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 9 additions & 17 deletions packages/@aws-cdk/assert/lib/expect.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import cdk = require('@aws-cdk/cdk');
import { ConstructNode, ConstructOrder } from '@aws-cdk/cdk';
import api = require('@aws-cdk/cx-api');
import { StackInspector } from './inspector';
import { SynthUtils } from './synth-utils';

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;

if (isStackClassInstance(stack)) {
if (!skipValidation) {
// Do a prepare-and-validate run over the given stack
stack.node.prepareTree();

const errors = stack.node.validateTree();
if (errors.length > 0) {
throw new Error(`Stack validation failed:\n${errors.map(e => `${e.message} at: ${e.source.node.scope}`).join('\n')}`);
}
}
if (cdk.Stack.isStack(stack)) {
const session = SynthUtils.synthesize(stack, {
skipValidation
});

sstack = {
name: stack.name,
template: stack._toCloudFormation(),
template: SynthUtils.templateForStackName(session, stack.name),
metadata: collectStackMetadata(stack.node),
environment: {
name: 'test',
Expand All @@ -35,13 +31,9 @@ export function expect(stack: api.SynthesizedStack | cdk.Stack, skipValidation =
return new StackInspector(sstack);
}

function isStackClassInstance(x: api.SynthesizedStack | cdk.Stack): x is cdk.Stack {
return '_toCloudFormation' in x;
}

function collectStackMetadata(root: cdk.ConstructNode): api.StackMetadata {
function collectStackMetadata(root: ConstructNode): api.StackMetadata {
const result: api.StackMetadata = {};
for (const construct of root.findAll(cdk.ConstructOrder.PreOrder)) {
for (const construct of root.findAll(ConstructOrder.PreOrder)) {
const path = `/${root.id}/${construct.node.path}`;
for (const entry of construct.node.metadata) {
result[path] = result[path] || [];
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/assert/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './assertion';
export * from './expect';
export * from './inspector';
export * from './synth-utils';

export * from './assertions/exist';
export * from './assertions/have-resource';
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/assert/lib/synth-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ISynthesisSession, Stack, SynthesisOptions, Synthesizer } from '@aws-cdk/cdk';

export class SynthUtils {
public static toCloudFormation(stack: Stack, options: SynthesisOptions = { }): any {
const session = this.synthesize(stack, options);
return this.templateForStackName(session, stack.name);
}

public static templateForStackName(session: ISynthesisSession, stackName: string): any {
return session.store.readJson(session.getArtifact(stackName).properties!.templateFile);
}

public static synthesize(stack: Stack, options: SynthesisOptions): ISynthesisSession {
const synth = new Synthesizer();
return synth.synthesize(stack, options);
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/assets-docker/lib/image-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DockerImageAssetProps {
/**
* The directory where the Dockerfile is stored
*/
directory: string;
readonly directory: string;

/**
* ECR repository name
Expand All @@ -20,7 +20,7 @@ export interface DockerImageAssetProps {
*
* @default automatically derived from the asset's ID.
*/
repositoryName?: string;
readonly repositoryName?: string;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets-docker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/assets-docker/test/test.image-asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { expect, haveResource, SynthUtils } from '@aws-cdk/assert';
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
Expand All @@ -18,7 +18,7 @@ export = {
});

// THEN
const template = stack._toCloudFormation();
const template = SynthUtils.toCloudFormation(stack);

test.deepEqual(template.Parameters.ImageImageName5E684353, {
Type: 'String',
Expand Down
14 changes: 7 additions & 7 deletions packages/@aws-cdk/assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export interface GenericAssetProps {
/**
* The disk location of the asset.
*/
path: string;
readonly path: string;

/**
* The packaging type for this asset.
*/
packaging: AssetPackaging;
readonly packaging: AssetPackaging;

/**
* A list of principals that should be able to read this asset from S3.
* You can use `asset.grantRead(principal)` to grant read permissions later.
*/
readers?: iam.IPrincipal[];
readonly readers?: iam.IPrincipal[];
}

/**
Expand Down Expand Up @@ -184,13 +184,13 @@ export interface FileAssetProps {
/**
* File path.
*/
path: string;
readonly path: string;

/**
* A list of principals that should be able to read this file asset from S3.
* You can use `asset.grantRead(principal)` to grant read permissions later.
*/
readers?: iam.IPrincipal[];
readonly readers?: iam.IPrincipal[];
}

/**
Expand All @@ -206,13 +206,13 @@ export interface ZipDirectoryAssetProps {
/**
* Path of the directory.
*/
path: string;
readonly path: string;

/**
* A list of principals that should be able to read this ZIP file from S3.
* You can use `asset.grantRead(principal)` to grant read permissions later.
*/
readers?: iam.IPrincipal[];
readonly readers?: iam.IPrincipal[];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/assets/test/test.asset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource, ResourcePart } from '@aws-cdk/assert';
import { expect, haveResource, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import cxapi = require('@aws-cdk/cx-api');
Expand Down Expand Up @@ -30,7 +30,7 @@ export = {
});

// verify that now the template contains parameters for this asset
const template = stack._toCloudFormation();
const template = SynthUtils.toCloudFormation(stack);
test.equal(template.Parameters.MyAssetS3Bucket68C9B344.Type, 'String');
test.equal(template.Parameters.MyAssetS3VersionKey68E1A45D.Type, 'String');

Expand Down Expand Up @@ -74,7 +74,7 @@ export = {
});

// verify that now the template contains parameters for this asset
const template = stack._toCloudFormation();
const template = SynthUtils.toCloudFormation(stack);
test.equal(template.Parameters.MyAssetS3Bucket68C9B344.Type, 'String');
test.equal(template.Parameters.MyAssetS3VersionKey68E1A45D.Type, 'String');

Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export interface DeploymentProps {
/**
* The Rest API to deploy.
*/
api: IRestApi;
readonly api: IRestApi;

/**
* A description of the purpose of the API Gateway deployment.
*/
description?: string;
readonly description?: string;

/**
* When an API Gateway model is updated, a new deployment will automatically be created.
Expand All @@ -21,7 +21,7 @@ export interface DeploymentProps {
*
* @default false
*/
retainDeployments?: boolean;
readonly retainDeployments?: boolean;
}

/**
Expand Down
Loading