Skip to content

Commit

Permalink
Merge branch 'main' into TheRealAmazonKendra/disableExecuteApiEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 20, 2022
2 parents 871743a + 35b2806 commit 0e0c456
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 278 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/instance-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ export class MysqlEngineVersion {
public static readonly VER_8_0_27 = MysqlEngineVersion.of('8.0.27', '8.0');
/** Version "8.0.28". */
public static readonly VER_8_0_28 = MysqlEngineVersion.of('8.0.28', '8.0');
/** Version "8.0.30". */
public static readonly VER_8_0_30 = MysqlEngineVersion.of('8.0.30', '8.0');

/**
* Create a new MysqlEngineVersion with an arbitrary version.
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomResource, Reference, Lazy, CfnResource, Stack, ArnFormat } from '@aws-cdk/core';
import { ArnFormat, CfnResource, CustomResource, Lazy, Reference, Stack } from '@aws-cdk/core';
import { Construct, IConstruct } from 'constructs';
import { EqualsAssertion } from './assertions';
import { ExpectedResult, ActualResult } from './common';
import { ActualResult, ExpectedResult } from './common';
import { AssertionsProvider, SDK_RESOURCE_TYPE_PREFIX } from './providers';

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ export interface AwsApiCallOptions {
/**
* Options for creating an SDKQuery provider
*/
export interface AwsApiCallProps extends AwsApiCallOptions {}
export interface AwsApiCallProps extends AwsApiCallOptions { }

/**
* Construct that creates a custom resource that will perform
Expand Down Expand Up @@ -142,7 +142,7 @@ export class AwsApiCall extends Construct implements IAwsApiCall {
flattenResponse: Lazy.string({ produce: () => this.flattenResponse }),
salt: Date.now().toString(),
},
resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`,
resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`.substring(0, 60),
});

// Needed so that all the policies set up by the provider should be available before the custom resource is provisioned.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Template } from '@aws-cdk/assertions';
import { App, Stack } from '@aws-cdk/core';
import { LogType, InvocationType, ExpectedResult, ActualResult } from '../../lib/assertions';
import { ActualResult, ExpectedResult, InvocationType, LogType } from '../../lib/assertions';
import { DeployAssert } from '../../lib/assertions/private/deploy-assert';

describe('DeployAssert', () => {
Expand Down Expand Up @@ -145,5 +145,22 @@ describe('DeployAssert', () => {
template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi1', 1);
template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi2', 1);
});

test('custom resource type length is truncated when greater than 60 characters', () => {
// GIVEN
const app = new App();

// WHEN
const deplossert = new DeployAssert(app);
deplossert.awsApiCall('Pangram', 'TheQuickBrownFoxJumpsOverTheLazyDog');

// THEN
const truncatedType = 'Custom::DeployAssert@SdkCallPangramTheQuickBrownFoxJumpsOver';
expect(truncatedType.length).toEqual(60);

const template = Template.fromStack(deplossert.scope);
template.resourceCountIs('AWS::Lambda::Function', 1);
template.resourceCountIs(truncatedType, 1);
});
});
});
90 changes: 90 additions & 0 deletions packages/aws-cdk/lib/init-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as path from 'path';
import { shell } from './os';

export type SubstitutePlaceholders = (...fileNames: string[]) => Promise<void>;

/**
* Helpers passed to hook functions
*/
export interface HookContext {
/**
* Callback function to replace placeholders on arbitrary files
*
* This makes token substitution available to non-`.template` files.
*/
readonly substitutePlaceholdersIn: SubstitutePlaceholders;

/**
* Return a single placeholder
*/
placeholder(name: string): string;
}

export type InvokeHook = (targetDirectory: string, context: HookContext) => Promise<void>;

export interface HookTarget {
readonly targetDirectory: string;
readonly templateName: string;
readonly language: string;
}

/**
* Invoke hooks for the given init template
*
* Sometimes templates need more complex logic than just replacing tokens. A 'hook' can be
* used to do additional processing other than copying files.
*
* Hooks used to be defined externally to the CLI, by running arbitrarily
* substituted shell scripts in the target directory.
*
* In practice, they're all TypeScript files and all the same, and the dynamism
* that the original solution allowed wasn't used at all. Worse, since the CLI
* is now bundled the hooks can't even reuse code from the CLI libraries at all
* anymore, so all shared code would have to be copy/pasted.
*
* Bundle hooks as built-ins into the CLI, so they get bundled and can take advantage
* of all shared code.
*/
export async function invokeBuiltinHooks(target: HookTarget, context: HookContext) {
switch (target.language) {
case 'csharp':
if (['app', 'sample-app'].includes(target.templateName)) {
return dotnetAddProject(target.targetDirectory, context);
}
break;

case 'fsharp':
if (['app', 'sample-app'].includes(target.templateName)) {
return dotnetAddProject(target.targetDirectory, context, 'fsproj');
}
break;

case 'python':
// We can't call this file 'requirements.template.txt' because Dependabot needs to be able to find it.
// Therefore, keep the in-repo name but still substitute placeholders.
await context.substitutePlaceholdersIn('requirements.txt');
break;

case 'java':
// We can't call this file 'pom.template.xml'... for the same reason as Python above.
await context.substitutePlaceholdersIn('pom.xml');
break;

case 'javascript':
case 'typescript':
// See above, but for 'package.json'.
await context.substitutePlaceholdersIn('package.json');

}
}

async function dotnetAddProject(targetDirectory: string, context: HookContext, ext = 'csproj') {
const pname = context.placeholder('name.PascalCased');
const slnPath = path.join(targetDirectory, 'src', `${pname}.sln`);
const csprojPath = path.join(targetDirectory, 'src', pname, `${pname}.${ext}`);
try {
await shell(['dotnet', 'sln', slnPath, 'add', csprojPath]);
} catch (e) {
throw new Error(`Could not add project ${pname}.${ext} to solution ${pname}.sln. ${e.message}`);
}
};
33 changes: 0 additions & 33 deletions packages/aws-cdk/lib/init-templates/app/csharp/add-project.hook.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/aws-cdk/lib/init-templates/app/fsharp/add-project.hook.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0e0c456

Please sign in to comment.