From 9fc7006208331b31a04ba9e638ca9a2671d66389 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 29 Apr 2019 17:07:50 -0700 Subject: [PATCH] Get rid of the old shit. --- .../cross-account-region-token.ts | 42 --------- packages/@aws-cdk/cdk/lib/index.ts | 1 - packages/@aws-cdk/cdk/lib/resource.ts | 42 --------- .../test.cross-account-region-token.ts | 92 ------------------- 4 files changed, 177 deletions(-) delete mode 100644 packages/@aws-cdk/cdk/lib/cloudformation/cross-account-region-token.ts delete mode 100644 packages/@aws-cdk/cdk/test/cloudformation/test.cross-account-region-token.ts diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/cross-account-region-token.ts b/packages/@aws-cdk/cdk/lib/cloudformation/cross-account-region-token.ts deleted file mode 100644 index f8b8caa27882c..0000000000000 --- a/packages/@aws-cdk/cdk/lib/cloudformation/cross-account-region-token.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { IResource, ResolveContext, Stack } from '..'; -import { Token } from '../token'; - -export abstract class CrossAccountRegionToken extends Token { - private readonly owningStack: Stack; - - /** - * @param regularValue the value used when this is referenced NOT from a cross account and/or region Stack - * @param crossAccountRegionValue the value used when this is referenced from a cross account and/or region Stack - * @param scope the scope this reference is mastered in. Used to determine the owning Stack - * @param displayName a short name to be used in Token display - */ - protected constructor(private readonly regularValue: any, private readonly crossAccountRegionValue: any, - scope: IResource, displayName: string) { - super(undefined, displayName); - - this.owningStack = scope.node.stack; - } - - public resolve(context: ResolveContext): any { - const consumingStack = context.scope.node.stack; - - if (consumingStack.env.account !== this.owningStack.env.account || - consumingStack.env.region !== this.owningStack.env.region) { - return this.crossAccountRegionValue; - } else { - return this.regularValue; - } - } -} - -export class CrossAccountRegionPhysicalArnToken extends CrossAccountRegionToken { - constructor(regularValue: any, crossAccountRegionValue: any, resource: IResource, displayName: string = 'Arn') { - super(regularValue, crossAccountRegionValue, resource, displayName); - } -} - -export class CrossAccountRegionPhysicalNameToken extends CrossAccountRegionToken { - constructor(regularValue: any, resource: IResource, displayName: string = 'Ref') { - super(regularValue, new Token(() => resource.physicalName), resource, displayName); - } -} diff --git a/packages/@aws-cdk/cdk/lib/index.ts b/packages/@aws-cdk/cdk/lib/index.ts index 2210d3904a533..b531fdb7eebd9 100644 --- a/packages/@aws-cdk/cdk/lib/index.ts +++ b/packages/@aws-cdk/cdk/lib/index.ts @@ -8,7 +8,6 @@ export * from './tag-manager'; export * from './dependency'; export * from './cloudformation-json'; -export * from './cloudformation/cross-account-region-token'; export * from './reference'; export * from './cfn-condition'; export * from './fn'; diff --git a/packages/@aws-cdk/cdk/lib/resource.ts b/packages/@aws-cdk/cdk/lib/resource.ts index 21cce232df202..fe69adea7a5dd 100644 --- a/packages/@aws-cdk/cdk/lib/resource.ts +++ b/packages/@aws-cdk/cdk/lib/resource.ts @@ -5,12 +5,6 @@ import { PhysicalNameGenerator } from "./util/physical-name-generator"; * Interface for the Resource construct. */ export interface IResource extends IConstruct { - readonly physicalName: string; - - readonly tryPhysicalName?: string - - assignPhysicalNameIfNotSet(name?: string): boolean; - physicalNameGenerator(): PhysicalNameGenerator; } @@ -18,42 +12,6 @@ export interface IResource extends IConstruct { * A construct which represents an AWS resource. */ export abstract class Resource extends Construct implements IResource { - private _physicalName?: string; - - public get physicalName(): string { - if (this._physicalName === undefined) { - throw new Error(`Construct '${this.node.uniqueId}' has been used in a cross account and/or region fashion, ' + - 'but does not have a physical name. Constructs have to have a physical name in order to be used cross account and/or region`); - } else { - return this._physicalName; - } - } - - public get tryPhysicalName(): string | undefined { - return this._physicalName; - } - - /** - * Assigns a physical name if the Construct does not have one already set. - * - * @param name the physical name to assign to this Construct. - * If not provided, the name will be generated by the object - * returned from {@link #physicalNameGenerator()} - * @returns true if the name was assigned - * (that is, the Construct did not have a physical name set), - * false otherwise - */ - public assignPhysicalNameIfNotSet(name?: string): boolean { - if (this._physicalName) { - return false; - } - - name = name || this.physicalNameGenerator().generate(); - - this._physicalName = name; - return true; - } - /** * Returns the {@link PhysicalNameGenerator} for this Construct, * which will be used in {@link #assignPhysicalNameIfNotSet()} diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.cross-account-region-token.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.cross-account-region-token.ts deleted file mode 100644 index 17b2001e8923a..0000000000000 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.cross-account-region-token.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { Test } from 'nodeunit'; -import { - App, - CfnOutput, - Construct, - CrossAccountRegionPhysicalArnToken, - CrossAccountRegionPhysicalNameToken, Resource, - Stack -} from '../../lib'; - -// tslint:disable:object-literal-key-quotes - -export = { - 'CrossAccountRegionToken': { - 'can reference an ARN directly in a different account'(test: Test) { - // GIVEN - const app = new App(); - const stack1 = new Stack(app, 'Stack1', { - env: { - account: '123456789012', - }, - }); - const construct = new MyResource(stack1, 'MyResource', 'PhysicalName'); - - const stack2 = new Stack(app, 'Stack2', { - env: { - account: '234567890123', - }, - }); - - // WHEN - const token = new CrossAccountRegionPhysicalArnToken(stack1.stackId, 'Literal-ARN', construct); - new CfnOutput(stack2, 'Output', { - value: token, - }); - - // THEN - app.node.prepareTree(); - test.deepEqual(stack2._toCloudFormation(), { - Outputs: { - Output: { - Value: 'Literal-ARN' - } - } - }); - - test.done(); - }, - - 'can reference a physical name directly in a different account'(test: Test) { - // GIVEN - const app = new App(); - const stack1 = new Stack(app, 'Stack1', { - env: { - account: '123456789012', - }, - }); - const stack2 = new Stack(app, 'Stack2', { - env: { - account: '234567890123', - }, - }); - - // WHEN - const construct = new MyResource(stack1, 'MyResource', 'PhysicalName'); - const token = new CrossAccountRegionPhysicalNameToken(stack1.stackId, construct); - new CfnOutput(stack2, 'Output', { - value: token, - }); - - // THEN - app.node.prepareTree(); - test.deepEqual(stack2._toCloudFormation(), { - Outputs: { - Output: { - Value: 'PhysicalName' - } - } - }); - - test.done(); - }, - }, -}; - -class MyResource extends Resource { - constructor(scope: Construct, id: string, physicalName: string) { - super(scope, id); - - this.assignPhysicalNameIfNotSet(physicalName); - } -}