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(core): improvements to Construct API #2767

Merged
merged 26 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions packages/@aws-cdk/assets/test/test.asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export = {
// verify that now the template contains parameters for this asset
const session = app.synth();

test.deepEqual(stack.node.resolve(entry!.data), {
test.deepEqual(stack.resolve(entry!.data), {
path: SAMPLE_ASSET_DIR,
id: 'MyStackMyAssetBDDF29E3',
packaging: 'zip',
Expand Down Expand Up @@ -84,7 +84,7 @@ export = {
// synthesize first so "prepare" is called
const template = SynthUtils.synthesize(stack).template;

test.deepEqual(stack.node.resolve(entry!.data), {
test.deepEqual(stack.resolve(entry!.data), {
path: 'asset.78add9eaf468dfa2191da44a7da92a21baba4c686cf6053d772556768ef21197.txt',
packaging: 'file',
id: 'MyAsset',
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ class LatestDeploymentResource extends CfnDeployment {
* add via `addToLogicalId`.
*/
protected prepare() {
const stack = Stack.of(this);

// if hash components were added to the deployment, we use them to calculate
// a logical ID for the deployment resource.
if (this.hashComponents.length > 0) {
const md5 = crypto.createHash('md5');
this.hashComponents
.map(c => this.node.resolve(c))
.map(c => stack.resolve(c))
.forEach(c => md5.update(JSON.stringify(c)));

this.overrideLogicalId(this.originalLogicalId + md5.digest("hex"));
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export = {
});

// THEN
test.deepEqual(method.node.resolve(method.methodArn), {
test.deepEqual(stack.resolve(method.methodArn), {
"Fn::Join": [
"",
[
Expand Down Expand Up @@ -182,7 +182,7 @@ export = {
});

// THEN
test.deepEqual(method.node.resolve(method.testMethodArn), {
test.deepEqual(stack.resolve(method.testMethodArn), {
"Fn::Join": [
"",
[
Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export = {
const imported = apigateway.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f');

// THEN
test.deepEqual(imported.node.resolve(imported.restApiId), 'api-rxt4498f');
test.deepEqual(stack.resolve(imported.restApiId), 'api-rxt4498f');
test.done();
},

Expand All @@ -347,7 +347,7 @@ export = {
api.root.addMethod('GET');

// THEN
test.deepEqual(api.node.resolve(api.url), { 'Fn::Join':
test.deepEqual(stack.resolve(api.url), { 'Fn::Join':
[ '',
[ 'https://',
{ Ref: 'apiC8550315' },
Expand All @@ -358,7 +358,7 @@ export = {
"/",
{ Ref: 'apiDeploymentStageprod896C8101' },
'/' ] ] });
test.deepEqual(api.node.resolve(api.urlForPath('/foo/bar')), { 'Fn::Join':
test.deepEqual(stack.resolve(api.urlForPath('/foo/bar')), { 'Fn::Join':
[ '',
[ 'https://',
{ Ref: 'apiC8550315' },
Expand Down Expand Up @@ -405,7 +405,7 @@ export = {
const arn = api.executeApiArn('method', '/path', 'stage');

// THEN
test.deepEqual(api.node.resolve(arn), { 'Fn::Join':
test.deepEqual(stack.resolve(arn), { 'Fn::Join':
[ '',
[ 'arn:',
{ Ref: 'AWS::Partition' },
Expand Down Expand Up @@ -438,7 +438,7 @@ export = {
const method = api.root.addMethod('ANY');

// THEN
test.deepEqual(api.node.resolve(method.methodArn), { 'Fn::Join':
test.deepEqual(stack.resolve(method.methodArn), { 'Fn::Join':
[ '',
[ 'arn:',
{ Ref: 'AWS::Partition' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
});
this.connections = new ec2.Connections({ securityGroups: [this.securityGroup] });
this.securityGroups.push(this.securityGroup);
this.node.apply(new Tag(NAME_TAG, this.node.path));
this.node.applyAspect(new Tag(NAME_TAG, this.node.path));

this.role = props.role || new iam.Role(this, 'InstanceRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ export = {
pauseTimeSec: 345
},
});
asg.node.apply(new cdk.Tag('superfood', 'acai'));
asg.node.apply(new cdk.Tag('notsuper', 'caramel', { applyToLaunchedInstances: false }));
asg.node.applyAspect(new cdk.Tag('superfood', 'acai'));
asg.node.applyAspect(new cdk.Tag('notsuper', 'caramel', { applyToLaunchedInstances: false }));

// THEN
expect(stack).to(haveResource("AWS::AutoScaling::AutoScalingGroup", {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct, Resource, Token } from "@aws-cdk/cdk";
import { Construct, Resource, Stack, Token } from "@aws-cdk/cdk";
import { CfnDashboard } from './cloudwatch.generated';
import { Column, Row } from "./layout";
import { IWidget } from "./widget";
Expand Down Expand Up @@ -61,7 +61,7 @@ export class Dashboard extends Resource {
dashboardBody: new Token(() => {
const column = new Column(...this.rows);
column.position(0, 0);
return this.node.stringifyJson({
return Stack.of(this).stringifyJson({
start: props ? props.start : undefined,
end: props ? props.end : undefined,
periodOverride: props ? props.periodOverride : undefined,
Expand Down
14 changes: 7 additions & 7 deletions packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down Expand Up @@ -45,7 +45,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down Expand Up @@ -74,7 +74,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 3,
Expand Down Expand Up @@ -105,7 +105,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down Expand Up @@ -139,7 +139,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down Expand Up @@ -182,7 +182,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down Expand Up @@ -229,7 +229,7 @@ export = {
});

// THEN
test.deepEqual(stack.node.resolve(widget.toJson()), [{
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-codecommit/test/test.codecommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export = {
const repo = Repository.fromRepositoryArn(stack, 'ImportedRepo', repositoryArn);

// THEN
test.deepEqual(repo.node.resolve(repo.repositoryArn), repositoryArn);
test.deepEqual(repo.node.resolve(repo.repositoryName), 'my-repo');
test.deepEqual(stack.resolve(repo.repositoryArn), repositoryArn);
test.deepEqual(stack.resolve(repo.repositoryName), 'my-repo');

test.done();
},
Expand All @@ -73,7 +73,7 @@ export = {
const repo = Repository.fromRepositoryName(stack, 'ImportedRepo', 'my-repo');

// THEN
test.deepEqual(repo.node.resolve(repo.repositoryArn), {
test.deepEqual(stack.resolve(repo.repositoryArn), {
'Fn::Join': ['', [
'arn:',
{ Ref: 'AWS::Partition' },
Expand All @@ -84,7 +84,7 @@ export = {
':my-repo'
]],
});
test.deepEqual(repo.node.resolve(repo.repositoryName), 'my-repo');
test.deepEqual(stack.resolve(repo.repositoryName), 'my-repo');

test.done();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export abstract class CloudFormationDeployAction extends CloudFormationAction {
// None evaluates to empty string which is falsey and results in undefined
Capabilities: (capabilities && capabilities.toString()) || undefined,
RoleArn: new cdk.Token(() => this.deploymentRole.roleArn),
ParameterOverrides: new cdk.Token(() => this.scope.node.stringifyJson(props.parameterOverrides)),
ParameterOverrides: new cdk.Token(() => Stack.of(this.scope).stringifyJson(props.parameterOverrides)),
TemplateConfiguration: props.templateConfiguration ? props.templateConfiguration.location : undefined,
StackName: props.stackName,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import codepipeline = require('@aws-cdk/aws-codepipeline');
import iam = require('@aws-cdk/aws-iam');
import lambda = require('@aws-cdk/aws-lambda');
import { Stack } from '@aws-cdk/cdk';

/**
* Construction properties of the {@link LambdaInvokeAction Lambda invoke CodePipeline Action}.
Expand Down Expand Up @@ -68,7 +69,7 @@ export class LambdaInvokeAction extends codepipeline.Action {
},
configuration: {
FunctionName: props.lambda.functionName,
UserParameters: props.lambda.node.stringifyJson(props.userParameters),
UserParameters: Stack.of(props.lambda).stringifyJson(props.userParameters),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export = nodeunit.testCase({
});

test.deepEqual(
stack.node.resolve(pipelineRole.statements),
stack.resolve(pipelineRole.statements),
[
{
Action: 'iam:PassRole',
Expand Down Expand Up @@ -153,7 +153,7 @@ export = nodeunit.testCase({
});

test.deepEqual(
stack.node.resolve(pipelineRole.statements),
stack.resolve(pipelineRole.statements),
[
{
Action: 'cloudformation:ExecuteChangeSet',
Expand Down Expand Up @@ -385,5 +385,5 @@ class RoleDouble extends iam.Role {
}

function resolve(x: any): any {
return new cdk.Stack().node.resolve(x);
return new cdk.Stack().resolve(x);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export = {

// THEN
expect(stack).to(haveResourceLike('AWS::Cognito::UserPoolClient', {
UserPoolId: pool.node.resolve(pool.userPoolId)
UserPoolId: stack.resolve(pool.userPoolId)
}));

test.done();
Expand Down
22 changes: 11 additions & 11 deletions packages/@aws-cdk/aws-cognito/test/test.user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export = {
// THEN
expect(stack).to(haveResourceLike('AWS::Cognito::UserPool', {
LambdaConfig: {
PreSignUp: fn.node.resolve(fn.functionArn),
CustomMessage: fn.node.resolve(fn.functionArn)
PreSignUp: stack.resolve(fn.functionArn),
CustomMessage: stack.resolve(fn.functionArn)
}
}));

Expand Down Expand Up @@ -73,14 +73,14 @@ export = {
// THEN
expect(stack).to(haveResourceLike('AWS::Cognito::UserPool', {
LambdaConfig: {
CreateAuthChallenge: fn.node.resolve(fn.functionArn),
CustomMessage: fn.node.resolve(fn.functionArn),
DefineAuthChallenge: fn.node.resolve(fn.functionArn),
PostAuthentication: fn.node.resolve(fn.functionArn),
PostConfirmation: fn.node.resolve(fn.functionArn),
PreAuthentication: fn.node.resolve(fn.functionArn),
PreSignUp: fn.node.resolve(fn.functionArn),
VerifyAuthChallengeResponse: fn.node.resolve(fn.functionArn)
CreateAuthChallenge: stack.resolve(fn.functionArn),
CustomMessage: stack.resolve(fn.functionArn),
DefineAuthChallenge: stack.resolve(fn.functionArn),
PostAuthentication: stack.resolve(fn.functionArn),
PostConfirmation: stack.resolve(fn.functionArn),
PreAuthentication: stack.resolve(fn.functionArn),
PreSignUp: stack.resolve(fn.functionArn),
VerifyAuthChallengeResponse: stack.resolve(fn.functionArn)
}
}));

Expand All @@ -105,7 +105,7 @@ export = {

// THEN
expect(stack).to(haveResourceLike('AWS::Lambda::Permission', {
FunctionName: fn.node.resolve(fn.functionArn),
FunctionName: stack.resolve(fn.functionArn),
Principal: 'cognito-idp.amazonaws.com'
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
sortKey: TABLE_SORT_KEY
});

tableWithGlobalAndLocalSecondaryIndex.node.apply(new Tag('Environment', 'Production'));
tableWithGlobalAndLocalSecondaryIndex.node.applyAspect(new Tag('Environment', 'Production'));

tableWithGlobalAndLocalSecondaryIndex.addGlobalSecondaryIndex({
indexName: GSI_TEST_CASE_1,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
sortKey: TABLE_SORT_KEY
});

tableWithGlobalAndLocalSecondaryIndex.node.apply(new Tag('Environment', 'Production'));
tableWithGlobalAndLocalSecondaryIndex.node.applyAspect(new Tag('Environment', 'Production'));
tableWithGlobalAndLocalSecondaryIndex.addGlobalSecondaryIndex({
indexName: GSI_TEST_CASE_1,
partitionKey: GSI_PARTITION_KEY,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export = {
partitionKey: TABLE_PARTITION_KEY,
sortKey: TABLE_SORT_KEY,
});
table.node.apply(new Tag('Environment', 'Production'));
table.node.applyAspect(new Tag('Environment', 'Production'));

expect(stack).to(haveResource('AWS::DynamoDB::Table',
{
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ export class Vpc extends VpcBase {
this.vpcDefaultSecurityGroup = this.resource.vpcDefaultSecurityGroup;
this.vpcIpv6CidrBlocks = this.resource.vpcIpv6CidrBlocks;

this.node.apply(new cdk.Tag(NAME_TAG, this.node.path));
this.node.applyAspect(new cdk.Tag(NAME_TAG, this.node.path));

this.availabilityZones = new cdk.AvailabilityZoneProvider(this).availabilityZones;
this.availabilityZones.sort();
Expand Down Expand Up @@ -1004,8 +1004,8 @@ export class Vpc extends VpcBase {

// These values will be used to recover the config upon provider import
const includeResourceTypes = [CfnSubnet.resourceTypeName];
subnet.node.apply(new cdk.Tag(SUBNETNAME_TAG, subnetConfig.name, {includeResourceTypes}));
subnet.node.apply(new cdk.Tag(SUBNETTYPE_TAG, subnetTypeTagValue(subnetConfig.subnetType), {includeResourceTypes}));
subnet.node.applyAspect(new cdk.Tag(SUBNETNAME_TAG, subnetConfig.name, {includeResourceTypes}));
subnet.node.applyAspect(new cdk.Tag(SUBNETTYPE_TAG, subnetTypeTagValue(subnetConfig.subnetType), {includeResourceTypes}));
});
}
}
Expand Down Expand Up @@ -1111,7 +1111,7 @@ export class Subnet extends cdk.Resource implements ISubnet {

Object.defineProperty(this, VPC_SUBNET_SYMBOL, { value: true });

this.node.apply(new cdk.Tag(NAME_TAG, this.node.path));
this.node.applyAspect(new cdk.Tag(NAME_TAG, this.node.path));

this.availabilityZone = props.availabilityZone;
const subnet = new CfnSubnet(this, 'Subnet', {
Expand Down
Loading