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(awslint): construct-base-is-private, resource-attribute #2349

Merged
merged 7 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 25 additions & 15 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface RestApiImportProps {
* 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 IResource {
Expand All @@ -20,6 +25,11 @@ export interface IRestApi extends IResource {
*/
readonly restApiId: string;

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

/**
* Exports a REST API resource from this stack.
* @returns REST API props that can be imported to another stack.
Expand Down Expand Up @@ -162,14 +172,28 @@ export class RestApi extends Resource implements IRestApi {
* @param props Imported rest API properties
*/
public static import(scope: Construct, id: string, props: RestApiImportProps): IRestApi {
return new ImportedRestApi(scope, id, props);
class Import extends Construct implements IRestApi {
public restApiId = props.restApiId;
public get restApiRootResourceId() {
if (!props.restApiRootResourceId) { throw new Error(`Imported REST API does not have "restApiRootResourceId"`); }
return props.restApiRootResourceId;
}
public export() { return props; }
}

return new Import(scope, id);
}

/**
* The ID of this API Gateway RestApi.
*/
public readonly restApiId: string;

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

/**
* API Gateway deployment that represents the latest changes of the API.
* This resource will be automatically updated every time the REST API model changes.
Expand Down Expand Up @@ -377,20 +401,6 @@ export enum EndpointType {
Private = 'PRIVATE'
}

class ImportedRestApi extends Construct implements IRestApi {
public restApiId: string;

constructor(scope: Construct, id: string, private readonly props: RestApiImportProps) {
super(scope, id);

this.restApiId = props.restApiId;
}

public export() {
return this.props;
}
}

class RootResource extends ResourceBase {
public readonly parentResource?: IRestApiResource;
public readonly resourceApi: RestApi;
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements route53.
const originProperty: CfnDistribution.OriginProperty = {
id: originId,
domainName: originConfig.s3OriginSource
? originConfig.s3OriginSource.s3BucketSource.domainName
? originConfig.s3OriginSource.s3BucketSource.bucketDomainName
: originConfig.customOriginSource!.domainName,
originPath: originConfig.originPath,
originCustomHeaders: originHeaders.length > 0 ? originHeaders : undefined,
Expand Down Expand Up @@ -660,7 +660,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements route53.
distributionConfig = {
...distributionConfig,
logging: {
bucket: this.loggingBucket.domainName,
bucket: this.loggingBucket.bucketDomainName,
includeCookies: props.loggingConfig.includeCookies || false,
prefix: props.loggingConfig.prefix
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cdk = require("@aws-cdk/cdk");
import { CfnApplication } from "../codedeploy.generated";
import { applicationNameToArn } from "../utils";
import { arnForApplication } from "../utils";

/**
* Represents a reference to a CodeDeploy Application deploying to AWS Lambda.
Expand Down Expand Up @@ -60,7 +60,7 @@ export class LambdaApplication extends cdk.Construct implements ILambdaApplicati
});

this.applicationName = resource.ref;
this.applicationArn = applicationNameToArn(this.applicationName, this);
this.applicationArn = arnForApplication(this.applicationName);
}

public export(): LambdaApplicationImportProps {
Expand Down Expand Up @@ -92,7 +92,7 @@ class ImportedLambdaApplication extends cdk.Construct implements ILambdaApplicat
super(scope, id);

this.applicationName = props.applicationName;
this.applicationArn = applicationNameToArn(props.applicationName, this);
this.applicationArn = arnForApplication(props.applicationName);
}

public export(): LambdaApplicationImportProps {
Expand Down
67 changes: 22 additions & 45 deletions packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cdk = require('@aws-cdk/cdk');
import { arnForDeploymentConfigName } from '../utils';
import { arnForDeploymentConfig } from '../utils';

/**
* The Deployment Configuration of a Lambda Deployment Group.
Expand All @@ -12,19 +12,7 @@ import { arnForDeploymentConfigName } from '../utils';
*/
export interface ILambdaDeploymentConfig {
readonly deploymentConfigName: string;
deploymentConfigArn(scope: cdk.IConstruct): string;
}

class DefaultLambdaDeploymentConfig implements ILambdaDeploymentConfig {
public readonly deploymentConfigName: string;

constructor(deploymentConfigName: string) {
this.deploymentConfigName = `CodeDeployDefault.Lambda${deploymentConfigName}`;
}

public deploymentConfigArn(scope: cdk.IConstruct): string {
return arnForDeploymentConfigName(this.deploymentConfigName, scope);
}
readonly deploymentConfigArn: string;
}

/**
Expand All @@ -41,24 +29,6 @@ export interface LambdaDeploymentConfigImportProps {
readonly deploymentConfigName: string;
}

class ImportedLambdaDeploymentConfig extends cdk.Construct implements ILambdaDeploymentConfig {
public readonly deploymentConfigName: string;

constructor(scope: cdk.Construct, id: string, private readonly props: LambdaDeploymentConfigImportProps) {
super(scope, id);

this.deploymentConfigName = props.deploymentConfigName;
}

public deploymentConfigArn(scope: cdk.IConstruct): string {
return arnForDeploymentConfigName(this.deploymentConfigName, scope);
}

public export() {
return this.props;
}
}

/**
* A custom Deployment Configuration for a Lambda Deployment Group.
*
Expand All @@ -67,29 +37,36 @@ class ImportedLambdaDeploymentConfig extends cdk.Construct implements ILambdaDep
* (private constructor) and does not extend {@link cdk.Construct}
*/
export class LambdaDeploymentConfig {
public static readonly AllAtOnce: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('AllAtOnce');
public static readonly Canary10Percent30Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent30Minutes');
public static readonly Canary10Percent5Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent5Minutes');
public static readonly Canary10Percent10Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent10Minutes');
public static readonly Canary10Percent15Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent15Minutes');
public static readonly Linear10PercentEvery10Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery10Minutes');
public static readonly Linear10PercentEvery1Minute: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery1Minute');
public static readonly Linear10PercentEvery2Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery2Minutes');
public static readonly Linear10PercentEvery3Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery3Minutes');
public static readonly AllAtOnce = deploymentConfig('CodeDeployDefault.LambdaAllAtOnce');
public static readonly Canary10Percent30Minutes = deploymentConfig('CodeDeployDefault.LambdaCanary10Percent30Minutes');
public static readonly Canary10Percent5Minutes = deploymentConfig('CodeDeployDefault.LambdaCanary10Percent5Minutes');
public static readonly Canary10Percent10Minutes = deploymentConfig('CodeDeployDefault.LambdaCanary10Percent10Minutes');
public static readonly Canary10Percent15Minutes = deploymentConfig('CodeDeployDefault.LambdaCanary10Percent15Minutes');
public static readonly Linear10PercentEvery10Minutes = deploymentConfig('CodeDeployDefault.LambdaLinear10PercentEvery10Minutes');
public static readonly Linear10PercentEvery1Minute = deploymentConfig('CodeDeployDefault.LambdaLinear10PercentEvery1Minute');
public static readonly Linear10PercentEvery2Minutes = deploymentConfig('CodeDeployDefault.LambdaLinear10PercentEvery2Minutes');
public static readonly Linear10PercentEvery3Minutes = deploymentConfig('CodeDeployDefault.LambdaLinear10PercentEvery3Minutes');

/**
* Import a custom Deployment Configuration for a Lambda Deployment Group defined outside the CDK.
*
* @param scope the parent Construct for this new Construct
* @param id the logical ID of this new Construct
* @param _scope the parent Construct for this new Construct
* @param _id the logical ID of this new Construct
* @param props the properties of the referenced custom Deployment Configuration
* @returns a Construct representing a reference to an existing custom Deployment Configuration
*/
public static import(scope: cdk.Construct, id: string, props: LambdaDeploymentConfigImportProps): ILambdaDeploymentConfig {
return new ImportedLambdaDeploymentConfig(scope, id, props);
public static import(_scope: cdk.Construct, _id: string, props: LambdaDeploymentConfigImportProps): ILambdaDeploymentConfig {
return deploymentConfig(props.deploymentConfigName);
}

private constructor() {
// nothing to do until CFN supports custom lambda deployment configurations
}
}

function deploymentConfig(name: string): ILambdaDeploymentConfig {
return {
deploymentConfigName: name,
deploymentConfigArn: arnForDeploymentConfig(name)
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cdk = require('@aws-cdk/cdk');

import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { deploymentGroupNameToArn, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils';
import { ILambdaApplication, LambdaApplication } from './application';
import { ILambdaDeploymentConfig, LambdaDeploymentConfig } from './deployment-config';

Expand Down Expand Up @@ -156,7 +156,7 @@ export class LambdaDeploymentGroup extends cdk.Construct implements ILambdaDeplo
});

this.deploymentGroupName = resource.deploymentGroupName;
this.deploymentGroupArn = deploymentGroupNameToArn(this.application.applicationName, this.deploymentGroupName, this);
this.deploymentGroupArn = arnForDeploymentGroup(this.application.applicationName, this.deploymentGroupName);

if (props.preHook) {
this.onPreHook(props.preHook);
Expand Down Expand Up @@ -264,8 +264,7 @@ class ImportedLambdaDeploymentGroup extends cdk.Construct implements ILambdaDepl
super(scope, id);
this.application = props.application;
this.deploymentGroupName = props.deploymentGroupName;
this.deploymentGroupArn = deploymentGroupNameToArn(props.application.applicationName,
props.deploymentGroupName, this);
this.deploymentGroupArn = arnForDeploymentGroup(props.application.applicationName, props.deploymentGroupName);
}

public export() {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-codedeploy/lib/server/application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cdk = require('@aws-cdk/cdk');
import { CfnApplication } from '../codedeploy.generated';
import { applicationNameToArn } from '../utils';
import { arnForApplication } from '../utils';

/**
* Represents a reference to a CodeDeploy Application deploying to EC2/on-premise instances.
Expand Down Expand Up @@ -41,7 +41,7 @@ class ImportedServerApplication extends cdk.Construct implements IServerApplicat
super(scope, id);

this.applicationName = props.applicationName;
this.applicationArn = applicationNameToArn(this.applicationName, this);
this.applicationArn = arnForApplication(this.applicationName);
}

public export(): ServerApplicationImportProps {
Expand Down Expand Up @@ -90,7 +90,7 @@ export class ServerApplication extends cdk.Construct implements IServerApplicati
});

this.applicationName = resource.ref;
this.applicationArn = applicationNameToArn(this.applicationName, this);
this.applicationArn = arnForApplication(this.applicationName);
}

public export(): ServerApplicationImportProps {
Expand Down
73 changes: 23 additions & 50 deletions packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cdk = require('@aws-cdk/cdk');
import { CfnDeploymentConfig } from '../codedeploy.generated';
import { arnForDeploymentConfigName } from '../utils';
import { arnForDeploymentConfig } from '../utils';

/**
* The Deployment Configuration of an EC2/on-premise Deployment Group.
Expand All @@ -11,7 +11,7 @@ import { arnForDeploymentConfigName } from '../utils';
*/
export interface IServerDeploymentConfig {
readonly deploymentConfigName: string;
deploymentConfigArn(scope: cdk.IConstruct): string;
readonly deploymentConfigArn: string;
export(): ServerDeploymentConfigImportProps;
}

Expand All @@ -29,42 +29,9 @@ export interface ServerDeploymentConfigImportProps {
readonly deploymentConfigName: string;
}

class ImportedServerDeploymentConfig extends cdk.Construct implements IServerDeploymentConfig {
public readonly deploymentConfigName: string;

constructor(scope: cdk.Construct, id: string, private readonly props: ServerDeploymentConfigImportProps) {
super(scope, id);

this.deploymentConfigName = props.deploymentConfigName;
}

public deploymentConfigArn(scope: cdk.IConstruct): string {
return arnForDeploymentConfigName(this.deploymentConfigName, scope);
}

public export() {
return this.props;
}
}

class DefaultServerDeploymentConfig implements IServerDeploymentConfig {
public readonly deploymentConfigName: string;

constructor(deploymentConfigName: string) {
this.deploymentConfigName = deploymentConfigName;
}

public deploymentConfigArn(scope: cdk.IConstruct): string {
return arnForDeploymentConfigName(this.deploymentConfigName, scope);
}

public export(): ServerDeploymentConfigImportProps {
return {
deploymentConfigName: this.deploymentConfigName
};
}
}

/**
* Minimum number of healthy hosts for a server deployment.
*/
export class MinimumHealthyHosts {

/**
Expand Down Expand Up @@ -117,25 +84,26 @@ export interface ServerDeploymentConfigProps {
/**
* A custom Deployment Configuration for an EC2/on-premise Deployment Group.
*/
export class ServerDeploymentConfig extends cdk.Construct implements IServerDeploymentConfig {
public static readonly OneAtATime: IServerDeploymentConfig = new DefaultServerDeploymentConfig('CodeDeployDefault.OneAtATime');
public static readonly HalfAtATime: IServerDeploymentConfig = new DefaultServerDeploymentConfig('CodeDeployDefault.HalfAtATime');
public static readonly AllAtOnce: IServerDeploymentConfig = new DefaultServerDeploymentConfig('CodeDeployDefault.AllAtOnce');
export class ServerDeploymentConfig extends cdk.Resource implements IServerDeploymentConfig {
public static readonly OneAtATime = deploymentConfig('CodeDeployDefault.OneAtATime');
public static readonly HalfAtATime = deploymentConfig('CodeDeployDefault.HalfAtATime');
public static readonly AllAtOnce = deploymentConfig('CodeDeployDefault.AllAtOnce');

/**
* Import a custom Deployment Configuration for an EC2/on-premise Deployment Group defined either outside the CDK,
* or in a different CDK Stack and exported using the {@link #export} method.
*
* @param scope the parent Construct for this new Construct
* @param id the logical ID of this new Construct
* @param _scope the parent Construct for this new Construct
* @param _id the logical ID of this new Construct
* @param props the properties of the referenced custom Deployment Configuration
* @returns a Construct representing a reference to an existing custom Deployment Configuration
*/
public static import(scope: cdk.Construct, id: string, props: ServerDeploymentConfigImportProps): IServerDeploymentConfig {
return new ImportedServerDeploymentConfig(scope, id, props);
public static import(_scope: cdk.Construct, _id: string, props: ServerDeploymentConfigImportProps): IServerDeploymentConfig {
return deploymentConfig(props.deploymentConfigName);
}

public readonly deploymentConfigName: string;
public readonly deploymentConfigArn: string;

constructor(scope: cdk.Construct, id: string, props: ServerDeploymentConfigProps) {
super(scope, id);
Expand All @@ -146,10 +114,7 @@ export class ServerDeploymentConfig extends cdk.Construct implements IServerDepl
});

this.deploymentConfigName = resource.ref.toString();
}

public deploymentConfigArn(scope: cdk.IConstruct): string {
return arnForDeploymentConfigName(this.deploymentConfigName, scope);
this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName);
}

public export(): ServerDeploymentConfigImportProps {
Expand All @@ -160,3 +125,11 @@ export class ServerDeploymentConfig extends cdk.Construct implements IServerDepl
};
}
}

function deploymentConfig(name: string): IServerDeploymentConfig {
return {
deploymentConfigName: name,
deploymentConfigArn: arnForDeploymentConfig(name),
export() { return { deploymentConfigName: name }; }
};
}
Loading