Skip to content

Commit

Permalink
chore: revert introduction of "Construct.construct" member (#9637)
Browse files Browse the repository at this point in the history
The addition of the new `construct` member leads to problems in the C# code generation, where it would properly be called `Construct.Construct`: a member may not have the same name as the class, because that is the name of the class constructor (see aws/jsii#1880).

Our build is currently broken because of this. Revert the renames to unblock the build, giving us the opportunity to tackle this problem afresh next week.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Aug 12, 2020
1 parent 398f872 commit ce34c03
Show file tree
Hide file tree
Showing 260 changed files with 701 additions and 709 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class PipelineDeployStackAction implements codepipeline.IAction {

constructor(props: PipelineDeployStackActionProps) {
this.stack = props.stack;
const assets = this.stack.construct.metadata.filter(md => md.type === cxschema.ArtifactMetadataEntryType.ASSET);
const assets = this.stack.node.metadata.filter(md => md.type === cxschema.ArtifactMetadataEntryType.ASSET);
if (assets.length > 0) {
// FIXME: Implement the necessary actions to publish assets
throw new Error(`Cannot deploy the stack ${this.stack.stackName} because it references ${assets.length} asset(s)`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export = nodeunit.testCase({

const deployedStack = new cdk.Stack(app, 'DeployedStack');
for (let i = 0 ; i < assetCount ; i++) {
deployedStack.construct.addMetadata(cxschema.ArtifactMetadataEntryType.ASSET, {});
deployedStack.node.addMetadata(cxschema.ArtifactMetadataEntryType.ASSET, {});
}

test.throws(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/lib/synth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class SynthUtils {
* Synthesizes the app in which a stack resides and returns the cloud assembly object.
*/
function synthesizeApp(stack: core.Stack, options: core.SynthesisOptions) {
const root = stack.construct.root;
const root = stack.node.root;
if (!core.Stage.isStage(root)) {
throw new Error('unexpected: all stacks must be part of a Stage or an App');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets/test/test.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export = {
'staging can be disabled through context'(test: Test) {
// GIVEN
const stack = new Stack();
stack.construct.setContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT, true);
stack.node.setContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT, true);
const sourcePath = path.join(__dirname, 'fs', 'fixtures', 'test1');

// WHEN
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-amplify/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
description: props.description,
environmentVariables: Lazy.anyValue({ produce: () => renderEnvironmentVariables(this.environmentVariables) }, { omitEmptyArray: true }),
iamServiceRole: role.roleArn,
name: props.appName || this.construct.id,
name: props.appName || this.node.id,
oauthToken: sourceCodeProviderOptions?.oauthToken?.toString(),
repository: sourceCodeProviderOptions?.repository,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface LambdaAuthorizerProps {
/**
* An optional human friendly name for the authorizer. Note that, this is not the primary identifier of the authorizer.
*
* @default this.construct.uniqueId
* @default this.node.uniqueId
*/
readonly authorizerName?: string;

Expand Down Expand Up @@ -96,7 +96,7 @@ abstract class LambdaAuthorizer extends Authorizer implements IAuthorizer {
*/
protected setupPermissions() {
if (!this.role) {
this.handler.addPermission(`${this.construct.uniqueId}:Permissions`, {
this.handler.addPermission(`${this.node.uniqueId}:Permissions`, {
principal: new iam.ServicePrincipal('apigateway.amazonaws.com'),
sourceArn: this.authorizerArn,
});
Expand All @@ -120,7 +120,7 @@ abstract class LambdaAuthorizer extends Authorizer implements IAuthorizer {
return Lazy.stringValue({
produce: () => {
if (!this.restApiId) {
throw new Error(`Authorizer (${this.construct.path}) must be attached to a RestApi`);
throw new Error(`Authorizer (${this.node.path}) must be attached to a RestApi`);
}
return this.restApiId;
},
Expand Down Expand Up @@ -167,7 +167,7 @@ export class TokenAuthorizer extends LambdaAuthorizer {

const restApiId = this.lazyRestApiId();
const resource = new CfnAuthorizer(this, 'Resource', {
name: props.authorizerName ?? this.construct.uniqueId,
name: props.authorizerName ?? this.node.uniqueId,
restApiId,
type: 'TOKEN',
authorizerUri: lambdaAuthorizerArn(props.handler),
Expand Down Expand Up @@ -229,7 +229,7 @@ export class RequestAuthorizer extends LambdaAuthorizer {

const restApiId = this.lazyRestApiId();
const resource = new CfnAuthorizer(this, 'Resource', {
name: props.authorizerName ?? this.construct.uniqueId,
name: props.authorizerName ?? this.node.uniqueId,
restApiId,
type: 'REQUEST',
authorizerUri: lambdaAuthorizerArn(props.handler),
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 @@ -118,7 +118,7 @@ export class Deployment extends Resource {
// and the `AWS::Lambda::Permission` resources (children under Method),
// causing cyclic dependency errors. Hence, falling back to declaring
// dependencies between the underlying CfnResources.
this.construct.addDependency(method.construct.defaultChild as CfnResource);
this.node.addDependency(method.node.defaultChild as CfnResource);
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ class LatestDeploymentResource extends CfnDeployment {
public addToLogicalId(data: unknown) {
// if the construct is locked, it means we are already synthesizing and then
// we can't modify the hash because we might have already calculated it.
if (this.construct.locked) {
if (this.node.locked) {
throw new Error('Cannot modify the logical ID when the construct is locked');
}

Expand All @@ -163,7 +163,7 @@ class LatestDeploymentResource extends CfnDeployment {
if (this.api instanceof RestApi || this.api instanceof SpecRestApi) { // Ignore IRestApi that are imported

// Add CfnRestApi to the logical id so a new deployment is triggered when any of its properties change.
const cfnRestApiCF = (this.api.construct.defaultChild as any)._toCloudFormation();
const cfnRestApiCF = (this.api.node.defaultChild as any)._toCloudFormation();
hash.push(this.stack.resolve(cfnRestApiCF));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/domain-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class DomainName extends Resource implements IDomainName {
*/
public addBasePathMapping(targetApi: IRestApi, options: BasePathMappingOptions = { }) {
const basePath = options.basePath || '/';
const id = `Map:${basePath}=>${targetApi.construct.uniqueId}`;
const id = `Map:${basePath}=>${targetApi.node.uniqueId}`;
return new BasePathMapping(this, id, {
domainName: this,
restApi: targetApi,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class GatewayResponse extends Resource implements IGatewayResponse {
statusCode: props.statusCode,
});

this.construct.defaultChild = resource;
this.node.defaultChild = resource;
}

private buildResponseParameters(responseHeaders?: { [key: string]: string }): { [key: string]: string } | undefined {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class LambdaIntegration extends AwsIntegration {
const bindResult = super.bind(method);
const principal = new iam.ServicePrincipal('apigateway.amazonaws.com');

const desc = `${method.api.construct.uniqueId}.${method.httpMethod}.${method.resource.path.replace(/\//g, '.')}`;
const desc = `${method.api.node.uniqueId}.${method.httpMethod}.${method.resource.path.replace(/\//g, '.')}`;

this.handler.addPermission(`ApiPermission.${desc}`, {
principal,
Expand All @@ -78,7 +78,7 @@ export class LambdaIntegration extends AwsIntegration {
if (this.handler instanceof lambda.Function) {
// if not imported, extract the name from the CFN layer to reach
// the literal value if it is given (rather than a token)
functionName = (this.handler.construct.defaultChild as lambda.CfnFunction).functionName;
functionName = (this.handler.node.defaultChild as lambda.CfnFunction).functionName;
} else {
// imported, just take the function name.
functionName = this.handler.functionName;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class Method extends Resource {

const deployment = props.resource.api.latestDeployment;
if (deployment) {
deployment.construct.addDependency(resource);
deployment.node.addDependency(resource);
deployment.addToLogicalId({
method: {
...methodProps,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class Model extends Resource implements IModel {

const deployment = (props.restApi instanceof RestApi) ? props.restApi.latestDeployment : undefined;
if (deployment) {
deployment.construct.addDependency(resource);
deployment.node.addDependency(resource);
deployment.addToLogicalId({ model: modelProps });
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/requestvalidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class RequestValidator extends Resource implements IRequestValidator {

const deployment = (props.restApi instanceof RestApi) ? props.restApi.latestDeployment : undefined;
if (deployment) {
deployment.construct.addDependency(resource);
deployment.node.addDependency(resource);
deployment.addToLogicalId({ validator: validatorProps });
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class Resource extends ResourceBase {

const deployment = props.parent.api.latestDeployment;
if (deployment) {
deployment.construct.addDependency(resource);
deployment.node.addDependency(resource);
deployment.addToLogicalId({ resource: resourceProps });
}

Expand Down Expand Up @@ -488,7 +488,7 @@ export class ProxyResource extends Resource {
// the root so that empty paths are proxied as well.
if (this.parentResource && this.parentResource.path === '/') {
// skip if the root resource already has this method defined
if (!(this.parentResource.construct.tryFindChild(httpMethod) instanceof Method)) {
if (!(this.parentResource.node.tryFindChild(httpMethod) instanceof Method)) {
this.parentResource.addMethod(httpMethod, integration, options);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
cloudWatchRoleArn: role.roleArn,
});

resource.construct.addDependency(apiResource);
resource.node.addDependency(apiResource);
}

protected configureDeployment(props: RestApiOptions) {
Expand Down Expand Up @@ -492,7 +492,7 @@ export class SpecRestApi extends RestApiBase {
endpointConfiguration: this._configureEndpoints(props),
parameters: props.parameters,
});
this.construct.defaultChild = resource;
this.node.defaultChild = resource;
this.restApiId = resource.ref;
this.restApiRootResourceId = resource.attrRootResourceId;
this.root = new RootResource(this, {}, this.restApiRootResourceId);
Expand Down Expand Up @@ -597,7 +597,7 @@ export class RestApi extends RestApiBase {
cloneFrom: props.cloneFrom ? props.cloneFrom.restApiId : undefined,
parameters: props.parameters,
});
this.construct.defaultChild = resource;
this.node.defaultChild = resource;
this.restApiId = resource.ref;

const cloudWatchRole = props.cloudWatchRole !== undefined ? props.cloudWatchRole : true;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class UsagePlan extends Resource {
const prefix = 'UsagePlanKeyResource';

// Postfixing apikey id only from the 2nd child, to keep physicalIds of UsagePlanKey for existing CDK apps unmodifed.
const id = this.construct.tryFindChild(prefix) ? `${prefix}:${apiKey.construct.uniqueId}` : prefix;
const id = this.node.tryFindChild(prefix) ? `${prefix}:${apiKey.node.uniqueId}` : prefix;

new CfnUsagePlanKey(this, id, {
keyId: apiKey.keyId,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class VpcLink extends Resource implements IVpcLink {
constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
super(scope, id, {
physicalName: props.vpcLinkName ||
Lazy.stringValue({ produce: () => this.construct.uniqueId }),
Lazy.stringValue({ produce: () => this.node.uniqueId }),
});

const cfnResource = new CfnVpcLink(this, 'Resource', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DeployStack extends NestedStack {
const deployment = new Deployment(this, 'Deployment', {
api: RestApi.fromRestApiId(this, 'RestApi', props.restApiId),
});
(props.methods ?? []).forEach((method) => deployment.construct.addDependency(method));
(props.methods ?? []).forEach((method) => deployment.node.addDependency(method));
new Stage(this, 'Stage', { deployment });
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export = {
const dep = new CfnResource(stack, 'MyResource', { type: 'foo' });

// WHEN
deployment.construct.addDependency(dep);
deployment.node.addDependency(dep);

expect(stack).to(haveResource('AWS::ApiGateway::Deployment', {
DependsOn: [
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export = {
expect(stack).to(haveResource('AWS::ApiGateway::Method', {
HttpMethod: 'GET',
RequestModels: {
'application/json': { Ref: stack.getLogicalId(model.construct.findChild('Resource') as cdk.CfnElement) },
'application/json': { Ref: stack.getLogicalId(model.node.findChild('Resource') as cdk.CfnElement) },
},
}));

Expand Down Expand Up @@ -539,7 +539,7 @@ export = {
ResponseModels: {
'application/json': 'Empty',
'text/plain': 'Error',
'text/html': { Ref: stack.getLogicalId(htmlModel.construct.findChild('Resource') as cdk.CfnElement) },
'text/html': { Ref: stack.getLogicalId(htmlModel.node.findChild('Resource') as cdk.CfnElement) },
},
},
],
Expand Down Expand Up @@ -568,10 +568,10 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Method', {
RequestValidatorId: { Ref: stack.getLogicalId(validator.construct.findChild('Resource') as cdk.CfnElement) },
RequestValidatorId: { Ref: stack.getLogicalId(validator.node.findChild('Resource') as cdk.CfnElement) },
}));
expect(stack).to(haveResource('AWS::ApiGateway::RequestValidator', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as cdk.CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) },
ValidateRequestBody: true,
ValidateRequestParameters: false,
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/test/test.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Model', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as cdk.CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) },
Schema: {
$schema: 'http://json-schema.org/draft-04/schema#',
title: 'test',
Expand Down Expand Up @@ -61,7 +61,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Model', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as cdk.CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) },
Schema: {
$schema: 'http://json-schema.org/draft-04/schema#',
title: 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::RequestValidator', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as cdk.CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) },
ValidateRequestBody: true,
ValidateRequestParameters: false,
}));
Expand All @@ -49,7 +49,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::RequestValidator', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as cdk.CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as cdk.CfnElement) },
Name: 'my-model',
ValidateRequestBody: false,
ValidateRequestParameters: true,
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 @@ -103,7 +103,7 @@ export = {
'defaultChild is set correctly'(test: Test) {
const stack = new Stack();
const api = new apigw.RestApi(stack, 'my-api');
test.ok(api.construct.defaultChild instanceof apigw.CfnRestApi);
test.ok(api.node.defaultChild instanceof apigw.CfnRestApi);
test.done();
},

Expand Down Expand Up @@ -570,7 +570,7 @@ export = {
const resource = new CfnResource(stack, 'DependsOnRestApi', { type: 'My::Resource' });

// WHEN
resource.construct.addDependency(api);
resource.node.addDependency(api);

// THEN
expect(stack).to(haveResource('My::Resource', {
Expand Down Expand Up @@ -713,7 +713,7 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Model', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) },
Schema: {
$schema: 'http://json-schema.org/draft-04/schema#',
title: 'test',
Expand Down Expand Up @@ -745,14 +745,14 @@ export = {

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::RequestValidator', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) },
Name: 'Parameters',
ValidateRequestBody: false,
ValidateRequestParameters: true,
}));

expect(stack).to(haveResource('AWS::ApiGateway::RequestValidator', {
RestApiId: { Ref: stack.getLogicalId(api.construct.findChild('Resource') as CfnElement) },
RestApiId: { Ref: stack.getLogicalId(api.node.findChild('Resource') as CfnElement) },
Name: 'Body',
ValidateRequestBody: true,
ValidateRequestParameters: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigatewayv2/lib/http/api-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export class HttpApiMapping extends Resource implements IApiMapping {

// ensure the dependency on the provided stage
if (props.stage) {
this.construct.addDependency(props.stage);
this.node.addDependency(props.stage);
}

// if stage not specified, we ensure the default stage is ready before we create the api mapping
if (!props.stage?.stageName && props.api.defaultStage) {
this.construct.addDependency(props.api.defaultStage!);
this.node.addDependency(props.api.defaultStage!);
}

this.apiMappingId = resource.ref;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigatewayv2/lib/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class HttpApi extends Resource implements IHttpApi {

// to ensure the domain is ready before creating the default stage
if(props?.defaultDomainMapping) {
this.defaultStage.construct.addDependency(props.defaultDomainMapping.domainName);
this.defaultStage.node.addDependency(props.defaultDomainMapping.domainName);
}
}

Expand Down
Loading

0 comments on commit ce34c03

Please sign in to comment.