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: remove "export"s and normalize resource names #2580

Merged
merged 39 commits into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 0 additions & 29 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,12 @@ import { Method, MethodOptions } from './method';
import { IResource, ResourceBase, ResourceOptions } from './resource';
import { Stage, StageOptions } from './stage';

export interface RestApiAttributes {
/**
* The REST API ID of an existing REST API resource.
*/
readonly restApiId: string;

/**
* The resource ID of the root resource.
*/
readonly restApiRootResourceId?: string;
}

export interface IRestApi extends IResourceBase {
/**
* The ID of this API Gateway RestApi.
* @attribute
*/
readonly restApiId: string;

/**
* Exports a REST API resource from this stack.
* @returns REST API props that can be imported to another stack.
*/
export(): RestApiAttributes;
}

export interface RestApiProps extends ResourceOptions {
Expand Down Expand Up @@ -165,7 +147,6 @@ export class RestApi extends Resource implements IRestApi {
public static fromRestApiId(scope: Construct, id: string, restApiId: string): IRestApi {
class Import extends Resource implements IRestApi {
public readonly restApiId = restApiId;
public export(): RestApiAttributes { return { restApiId }; }
}

return new Import(scope, id);
Expand Down Expand Up @@ -237,16 +218,6 @@ export class RestApi extends Resource implements IRestApi {
this.root = new RootResource(this, props, resource.restApiRootResourceId);
}

/**
* Exports a REST API resource from this stack.
* @returns REST API props that can be imported to another stack.
*/
public export(): RestApiAttributes {
return {
restApiId: new CfnOutput(this, 'RestApiId', { value: this.restApiId }).makeImportValue().toString()
};
}

/**
* The deployed root URL of this REST API.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export = {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', { deploy: false });
const vpc = new ec2.VpcNetwork(stack, 'VPC');
const vpc = new ec2.Vpc(stack, 'VPC');
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', {
vpc
});
Expand Down
14 changes: 2 additions & 12 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource, haveResourceLike, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert';
import cdk = require('@aws-cdk/cdk');
import { App, Stack } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -328,25 +328,15 @@ export = {
test.done();
},

'import/export'(test: Test) {
'fromRestApiId'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const imported = apigateway.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f');
const api = new apigateway.RestApi(stack, 'MyRestApi');
api.root.addMethod('GET');

const exported = api.export();

// THEN
stack.node.prepareTree();
test.deepEqual(SynthUtils.toCloudFormation(stack).Outputs.MyRestApiRestApiIdB93C5C2D, {
Value: { Ref: 'MyRestApi2D1F47A9' },
Export: { Name: 'Stack:MyRestApiRestApiIdB93C5C2D' }
});
test.deepEqual(imported.node.resolve(imported.restApiId), 'api-rxt4498f');
test.deepEqual(imported.node.resolve(exported), { restApiId: { 'Fn::ImportValue': 'Stack:MyRestApiRestApiIdB93C5C2D' } });
test.done();
},

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export = {
'default setup'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'VPC');
const vpc = new ec2.Vpc(stack, 'VPC');
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', {
vpc
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
/**
* VPC to launch these instances in.
*/
readonly vpc: ec2.IVpcNetwork;
readonly vpc: ec2.IVpc;

/**
* Type of instance to launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import autoscaling = require('../lib');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-autoscaling-integ');

const vpc = new ec2.VpcNetwork(stack, 'VPC', {
const vpc = new ec2.Vpc(stack, 'VPC', {
maxAZs: 2
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import autoscaling = require('../lib');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-asg-integ');

const vpc = new ec2.VpcNetwork(stack, 'VPC', {
const vpc = new ec2.Vpc(stack, 'VPC', {
maxAZs: 3
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import autoscaling = require('../lib');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-asg-integ');

const vpc = new ec2.VpcNetwork(stack, 'VPC', {
const vpc = new ec2.Vpc(stack, 'VPC', {
maxAZs: 2
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import autoscaling = require('../lib');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-autoscaling-integ');

const vpc = new ec2.VpcNetwork(stack, 'VPC', {
const vpc = new ec2.Vpc(stack, 'VPC', {
maxAZs: 2
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string) {
super(scope, id);

const vpc = new ec2.VpcNetwork(this, 'VPC');
const vpc = new ec2.Vpc(this, 'VPC');
const role = new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export = {
};

function mockVpc(stack: cdk.Stack) {
return ec2.VpcNetwork.import(stack, 'MyVpc', {
return ec2.Vpc.fromVpcAttributes(stack, 'MyVpc', {
vpcId: 'my-vpc',
availabilityZones: [ 'az1' ],
publicSubnetIds: [ 'pub1' ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export = {
'we can add a lifecycle hook to an ASG'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'VPC');
const vpc = new ec2.Vpc(stack, 'VPC');
const asg = new autoscaling.AutoScalingGroup(stack, 'ASG', {
vpc,
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ export = {
};

class ASGFixture extends cdk.Construct {
public readonly vpc: ec2.VpcNetwork;
public readonly vpc: ec2.Vpc;
public readonly asg: autoscaling.AutoScalingGroup;

constructor(scope: cdk.Construct, id: string) {
super(scope, id);

this.vpc = new ec2.VpcNetwork(this, 'VPC');
this.vpc = new ec2.Vpc(this, 'VPC');
this.asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc: this.vpc,
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export = {
};

function makeAutoScalingGroup(scope: cdk.Construct) {
const vpc = new ec2.VpcNetwork(scope, 'VPC');
const vpc = new ec2.Vpc(scope, 'VPC');
return new autoscaling.AutoScalingGroup(scope, 'ASG', {
vpc,
instanceType: new ec2.InstanceType('t2.micro'),
Expand Down
29 changes: 1 addition & 28 deletions packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CfnOutput, Construct, IResource, Resource } from '@aws-cdk/cdk';
import { Construct, IResource, Resource } from '@aws-cdk/cdk';
import { CfnCertificate } from './certificatemanager.generated';
import { apexDomain } from './util';

Expand All @@ -9,21 +9,6 @@ export interface ICertificate extends IResource {
* @attribute
*/
readonly certificateArn: string;

/**
* Export this certificate from the stack
*/
export(): CertificateAttributes;
}

/**
* Reference to an existing Certificate
*/
export interface CertificateAttributes {
/**
* The certificate's ARN
*/
readonly certificateArn: string;
}

/**
Expand Down Expand Up @@ -79,9 +64,6 @@ export class Certificate extends Resource implements ICertificate {
public static fromCertificateArn(scope: Construct, id: string, certificateArn: string): ICertificate {
class Import extends Resource implements ICertificate {
public certificateArn = certificateArn;
public export(): CertificateAttributes {
return { certificateArn };
}
}

return new Import(scope, id);
Expand Down Expand Up @@ -118,13 +100,4 @@ export class Certificate extends Resource implements ICertificate {
};
}
}

/**
* Export this certificate from the stack
*/
public export(): CertificateAttributes {
return {
certificateArn: new CfnOutput(this, 'Arn', { value: this.certificateArn }).makeImportValue().toString()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import lambda = require('@aws-cdk/aws-lambda');
import route53 = require('@aws-cdk/aws-route53');
import cdk = require('@aws-cdk/cdk');
import path = require('path');
import { CertificateAttributes, CertificateProps, ICertificate } from './certificate';
import { CertificateProps, ICertificate } from './certificate';

export interface DnsValidatedCertificateProps extends CertificateProps {
/**
Expand Down Expand Up @@ -71,15 +71,6 @@ export class DnsValidatedCertificate extends cdk.Construct implements ICertifica
this.certificateArn = certificate.getAtt('Arn').toString();
}

/**
* Export this certificate from the stack
*/
public export(): CertificateAttributes {
return {
certificateArn: new cdk.CfnOutput(this, 'Arn', { value: this.certificateArn }).makeImportValue().toString()
};
}

protected validate(): string[] {
const errors: string[] = [];
// Ensure the zone name is a parent zone of the certificate domain name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export = {
},

'export and import'(test: Test) {
// GIVEN
const stack = new Stack();

const refProps = new Certificate(stack, 'Cert', {
domainName: 'hello.com',
}).export();

Certificate.fromCertificateArn(stack, 'Imported', refProps.certificateArn);
// WHEN
const c = Certificate.fromCertificateArn(stack, 'Imported', 'cert-arn');

// THEN
test.deepEqual(c.certificateArn, 'cert-arn');
test.done();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,6 @@ export = {
test.done();
},

'export and import'(test: Test) {
const stack = new Stack();

const helloDotComZone = new PublicHostedZone(stack, 'HelloDotCom', {
zoneName: 'hello.com'
});

const refProps = new DnsValidatedCertificate(stack, 'Cert', {
domainName: 'hello.com',
hostedZone: helloDotComZone,
}).export();

test.ok('certificateArn' in refProps);
test.done();
},

'adds validation error on domain mismatch'(test: Test) {
const stack = new Stack();

Expand Down
26 changes: 19 additions & 7 deletions packages/@aws-cdk/aws-cloudtrail/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import iam = require('@aws-cdk/aws-iam');
import kms = require('@aws-cdk/aws-kms');
import logs = require('@aws-cdk/aws-logs');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { Construct, Resource } from '@aws-cdk/cdk';
import { CfnTrail } from './cloudtrail.generated';

// AWS::CloudTrail CloudFormation Resources:
export * from './cloudtrail.generated';

export interface CloudTrailProps {
export interface TrailProps {
/**
* For most services, events are recorded in the region where the action occurred.
* For global services such as AWS Identity and Access Management (IAM), AWS STS, Amazon CloudFront, and Route 53,
Expand Down Expand Up @@ -65,7 +65,7 @@ export interface CloudTrailProps {
/** The AWS Key Management Service (AWS KMS) key ID that you want to use to encrypt CloudTrail logs.
* @default none
*/
readonly kmsKey?: kms.IEncryptionKey;
readonly kmsKey?: kms.IKey;

/** The name of an Amazon SNS topic that is notified when new log files are published.
* @default none
Expand Down Expand Up @@ -99,12 +99,21 @@ export enum ReadWriteType {
* const cloudTrail = new CloudTrail(this, 'MyTrail');
*
*/
export class CloudTrail extends cdk.Construct {
export class Trail extends Resource {

/**
* @attribute
*/
public readonly trailArn: string;

/**
* @attribute
*/
public readonly trailSnsTopicArn: string;

public readonly cloudTrailArn: string;
private eventSelectors: EventSelector[] = [];

constructor(scope: cdk.Construct, id: string, props: CloudTrailProps = {}) {
constructor(scope: Construct, id: string, props: TrailProps = {}) {
super(scope, id);

const s3bucket = new s3.Bucket(this, 'S3', {encryption: s3.BucketEncryption.Unencrypted});
Expand Down Expand Up @@ -157,7 +166,10 @@ export class CloudTrail extends cdk.Construct {
snsTopicName: props.snsTopic,
eventSelectors: this.eventSelectors
});
this.cloudTrailArn = trail.trailArn;

this.trailArn = trail.trailArn;
this.trailSnsTopicArn = trail.trailSnsTopicArn;

const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
trail.node.addDependency(s3BucketPolicy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const stack = new cdk.Stack(app, 'integ-cloudtrail');

const bucket = new s3.Bucket(stack, 'Bucket', { removalPolicy: cdk.RemovalPolicy.Destroy });

const trail = new cloudtrail.CloudTrail(stack, 'Trail');
const trail = new cloudtrail.Trail(stack, 'Trail');
trail.addS3EventSelector([bucket.arnForObjects('')]);

app.run();
Loading