Skip to content

Commit

Permalink
Merge branch 'master' into neta/allow-empty-label
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 3, 2022
2 parents 5d104f7 + 2df6dab commit d378bcc
Show file tree
Hide file tree
Showing 166 changed files with 3,025 additions and 577 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/issue-label-assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: "Set Issue Label and Assignee"
on:
issues:
types: [opened, edited]
pull_request:
types: [opened]
pull_request_target:
types: [opened]

Expand Down Expand Up @@ -48,7 +46,7 @@ jobs:
steps:
- uses: aws-github-ops/aws-issue-triage-manager@main
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
github-token: "${{ secrets.PROJEN_GITHUB_TOKEN }}"
target: "pull-requests"
area-is-keyword: true
default-area: >
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assertions/lib/private/cyclic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function analyzeSubPattern(pattern: string): SubFragment[] {
}

if (start < pattern.length - 1) {
ret.push({ type: 'literal', content: pattern.substr(start) });
ret.push({ type: 'literal', content: pattern.slice(start) });
}

return ret;
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export abstract class ResourceBase extends ResourceConstruct implements IResourc
}

// trim trailing "/"
return this.resourceForPath(path.substr(1));
return this.resourceForPath(path.slice(1));
}

const parts = path.split('/');
Expand Down Expand Up @@ -544,11 +544,11 @@ export class ProxyResource extends Resource {
function validateResourcePathPart(part: string) {
// strip {} which indicate this is a parameter
if (part.startsWith('{') && part.endsWith('}')) {
part = part.substr(1, part.length - 2);
part = part.slice(1, -1);

// proxy resources are allowed to end with a '+'
if (part.endsWith('+')) {
part = part.substr(0, part.length - 1);
part = part.slice(0, -1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function parseMethodOptionsPath(originalPath: string): { resourcePath: st
throw new Error(`Method options path must start with '/': ${originalPath}`);
}

const path = originalPath.substr(1); // trim trailing '/'
const path = originalPath.slice(1); // trim trailing '/'

const components = path.split('/');

Expand Down Expand Up @@ -60,7 +60,7 @@ export function parseAwsApiCall(path?: string, action?: string, actionParams?: {

if (action) {
if (actionParams) {
action += '&' + formatUrl({ query: actionParams }).substr(1);
action += '&' + formatUrl({ query: actionParams }).slice(1);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const requestCertificate = async function (requestId, domainName, subjectAlterna
const reqCertResponse = await acm.requestCertificate({
DomainName: domainName,
SubjectAlternativeNames: subjectAlternativeNames,
IdempotencyToken: crypto.createHash('sha256').update(requestId).digest('hex').substr(0, 32),
IdempotencyToken: crypto.createHash('sha256').update(requestId).digest('hex').slice(0, 32),
ValidationMethod: 'DNS'
}).promise();

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM alpine
FROM public.ecr.aws/docker/library/alpine:latest
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class OriginAccessIdentity extends OriginAccessIdentityBase implements IO
super(scope, id);

// Comment has a max length of 128.
const comment = (props?.comment ?? 'Allows CloudFront to reach the bucket').substr(0, 128);
const comment = (props?.comment ?? 'Allows CloudFront to reach the bucket').slice(0, 128);
this.resource = new CfnCloudFrontOriginAccessIdentity(this, 'Resource', {
cloudFrontOriginAccessIdentityConfig: { comment },
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/origin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export abstract class OriginBase implements IOrigin {
if (originPath === undefined) { return undefined; }
let path = originPath;
if (!path.startsWith('/')) { path = '/' + path; }
if (path.endsWith('/')) { path = path.substr(0, path.length - 1); }
if (path.endsWith('/')) { path = path.slice(0, -1); }
return path;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
// Comments have an undocumented limit of 128 characters
const trimmedComment =
props.comment && props.comment.length > 128
? `${props.comment.substr(0, 128 - 3)}...`
? `${props.comment.slice(0, 128 - 3)}...`
: props.comment;

let distributionConfig: CfnDistribution.DistributionConfigProperty = {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ export class Project extends ProjectBase {
// If the parameter name starts with / the resource name is not separated with a double '/'
// arn:aws:ssm:region:1111111111:parameter/PARAM_NAME
resourceName: envVariableValue.startsWith('/')
? envVariableValue.substr(1)
? envVariableValue.slice(1)
: envVariableValue,
}));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/test/demo-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6
FROM public.ecr.aws/lambda/python:3.6
EXPOSE 8000
WORKDIR /src
ADD . /src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
{
"Ref": "AWS::URLSuffix"
},
"/aws-cdk/assets:4af07cfea2e112710555eb86325bfd4d7d4b97e4fa9f1bf6c053c72f992c7fe5"
"/aws-cdk/assets:73ee9c3cafd103104e2a42ee76961a90a2410d0dcad42110343c5fd85ad6db78"
]
]
},
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/lib/ecs/application.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArnFormat, IResource, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication } from '../utils';
import { arnForApplication, validateName } from '../utils';

/**
* Represents a reference to a CodeDeploy Application deploying to Amazon ECS.
Expand Down Expand Up @@ -77,4 +77,8 @@ export class EcsApplication extends Resource implements IEcsApplication {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
}

protected validate(): string[] {
return validateName('Application', this.physicalName);
}
}
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArnFormat, IResource, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication } from '../utils';
import { arnForApplication, validateName } from '../utils';

/**
* Represents a reference to a CodeDeploy Application deploying to AWS Lambda.
Expand Down Expand Up @@ -77,4 +77,8 @@ export class LambdaApplication extends Resource implements ILambdaApplication {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
}

protected validate(): string[] {
return validateName('Application', this.physicalName);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Duration, Names, Resource } from '@aws-cdk/core';
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from '@aws-cdk/custom-resources';
import { Construct } from 'constructs';
import { arnForDeploymentConfig } from '../utils';
import { arnForDeploymentConfig, validateName } from '../utils';
import { ILambdaDeploymentConfig } from './deployment-config';

/**
Expand Down Expand Up @@ -143,6 +143,10 @@ export class CustomLambdaDeploymentConfig extends Resource implements ILambdaDep
});
}

protected validate(): string[] {
return validateName('Deployment config', this.deploymentConfigName);
}

// Validate the inputs. The percentage/interval limits come from CodeDeploy
private validateParameters(props: CustomLambdaDeploymentConfigProps): void {
if ( !(1 <= props.percentage && props.percentage <= 99) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils';
import { ILambdaApplication, LambdaApplication } from './application';
import { ILambdaDeploymentConfig, LambdaDeploymentConfig } from './deployment-config';

Expand Down Expand Up @@ -254,6 +254,10 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
actions: ['codedeploy:PutLifecycleEventHookExecutionStatus'],
});
}

protected validate(): string[] {
return validateName('Deployment group', this.physicalName);
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/lib/server/application.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArnFormat, IResource, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication } from '../utils';
import { arnForApplication, validateName } from '../utils';

/**
* Represents a reference to a CodeDeploy Application deploying to EC2/on-premise instances.
Expand Down Expand Up @@ -78,4 +78,8 @@ export class ServerApplication extends Resource implements IServerApplication {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
}

protected validate(): string[] {
return validateName('Application', this.physicalName);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDeploymentConfig } from '../codedeploy.generated';
import { arnForDeploymentConfig } from '../utils';
import { arnForDeploymentConfig, validateName } from '../utils';

/**
* The Deployment Configuration of an EC2/on-premise Deployment Group.
Expand Down Expand Up @@ -119,6 +119,10 @@ export class ServerDeploymentConfig extends cdk.Resource implements IServerDeplo
this.deploymentConfigName = resource.ref;
this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName);
}

protected validate(): string[] {
return validateName('Deployment config', this.physicalName);
}
}

function deploymentConfig(name: string): IServerDeploymentConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ArnFormat } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../utils';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils';
import { IServerApplication, ServerApplication } from './application';
import { IServerDeploymentConfig, ServerDeploymentConfig } from './deployment-config';
import { LoadBalancer, LoadBalancerGeneration } from './load-balancer';
Expand Down Expand Up @@ -341,6 +341,10 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
return this._autoScalingGroups.slice();
}

protected validate(): string[] {
return validateName('Deployment group', this.physicalName);
}

private addCodeDeployAgentInstallUserData(asg: autoscaling.IAutoScalingGroup): void {
if (!this.installAgent) {
return;
Expand Down
17 changes: 16 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { Aws } from '@aws-cdk/core';
import { Aws, Token } from '@aws-cdk/core';
import { CfnDeploymentGroup } from './codedeploy.generated';
import { AutoRollbackConfig } from './rollback-config';

Expand Down Expand Up @@ -65,3 +65,18 @@ CfnDeploymentGroup.AutoRollbackConfigurationProperty | undefined {
}
: undefined;
}

export function validateName(type: 'Application' | 'Deployment group' | 'Deployment config', name: string): string[] {
const ret = [];

if (!Token.isUnresolved(name) && name !== undefined) {
if (name.length > 100) {
ret.push(`${type} name: "${name}" can be a max of 100 characters.`);
}
if (!/^[a-z0-9._+=,@-]+$/i.test(name)) {
ret.push(`${type} name: "${name}" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).`);
}
}

return ret;
}
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-codedeploy/test/ecs/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,24 @@ describe('CodeDeploy ECS Application', () => {
ComputePlatform: 'ECS',
});
});

test('fail with more than 100 characters in name', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app);
new codedeploy.EcsApplication(stack, 'MyApp', {
applicationName: 'a'.repeat(101),
});

expect(() => app.synth()).toThrow(`Application name: "${'a'.repeat(101)}" can be a max of 100 characters.`);
});

test('fail with unallowed characters in name', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app);
new codedeploy.EcsApplication(stack, 'MyApp', {
applicationName: 'my name',
});

expect(() => app.synth()).toThrow('Application name: "my name" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).');
});
});
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-codedeploy/test/lambda/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,24 @@ describe('CodeDeploy Lambda Application', () => {
ComputePlatform: 'Lambda',
});
});

test('fail with more than 100 characters in name', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app);
new codedeploy.LambdaApplication(stack, 'MyApp', {
applicationName: 'a'.repeat(101),
});

expect(() => app.synth()).toThrow(`Application name: "${'a'.repeat(101)}" can be a max of 100 characters.`);
});

test('fail with unallowed characters in name', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app);
new codedeploy.LambdaApplication(stack, 'MyApp', {
applicationName: 'my name',
});

expect(() => app.synth()).toThrow('Application name: "my name" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ test('custom resource created with specific name', () => {
});
});

test('fail with more than 100 characters in name', () => {
const app = new cdk.App();
const stackWithApp = new cdk.Stack(app);
new codedeploy.CustomLambdaDeploymentConfig(stackWithApp, 'CustomConfig', {
type: codedeploy.CustomLambdaDeploymentConfigType.CANARY,
interval: cdk.Duration.minutes(1),
percentage: 5,
deploymentConfigName: 'a'.repeat(101),
});

expect(() => app.synth()).toThrow(`Deployment config name: "${'a'.repeat(101)}" can be a max of 100 characters.`);
});

test('fail with unallowed characters in name', () => {
const app = new cdk.App();
const stackWithApp = new cdk.Stack(app);
new codedeploy.CustomLambdaDeploymentConfig(stackWithApp, 'CustomConfig', {
type: codedeploy.CustomLambdaDeploymentConfigType.CANARY,
interval: cdk.Duration.minutes(1),
percentage: 5,
deploymentConfigName: 'my name',
});

expect(() => app.synth()).toThrow('Deployment config name: "my name" can only contain letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), + (plus signs), = (equals signs), , (commas), @ (at signs), - (minus signs).');
});

test('can create linear custom config', () => {
// WHEN
const config = new codedeploy.CustomLambdaDeploymentConfig(stack, 'CustomConfig', {
Expand Down
Loading

0 comments on commit d378bcc

Please sign in to comment.