Skip to content

Commit 6e0b7f2

Browse files
authored
feat(toolkit-lib): can disable cloud assembly version and enum checks for sources (#202)
Fixes #201 Feature request was for `cli-lib-alpha`, however we are instead adding this to the new package that should be used going forward. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent a3160a7 commit 6e0b7f2

File tree

10 files changed

+583
-10
lines changed

10 files changed

+583
-10
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ToolkitServices } from '../../../toolkit/private';
1111
import { CODES } from '../../io/private';
1212
import { ActionAwareIoHost } from '../../shared-private';
1313
import { ToolkitError } from '../../shared-public';
14-
import type { AppSynthOptions } from '../source-builder';
14+
import type { AppSynthOptions, LoadAssemblyOptions } from '../source-builder';
1515

1616
export { guessExecutable } from '../../../api/aws-cdk';
1717

@@ -149,9 +149,11 @@ export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly,
149149
/**
150150
* Safely create an assembly from a cloud assembly directory
151151
*/
152-
export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionAwareIoHost) {
152+
export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionAwareIoHost, loadOptions: LoadAssemblyOptions = {}) {
153153
try {
154154
const assembly = new cxapi.CloudAssembly(assemblyDir, {
155+
skipVersionCheck: !(loadOptions.checkVersion ?? true),
156+
skipEnumCheck: !(loadOptions.checkEnums ?? true),
155157
// We sort as we deploy
156158
topoSort: false,
157159
});

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as cxapi from '@aws-cdk/cx-api';
22
import * as fs from 'fs-extra';
3-
import type { AssemblySourceProps, ICloudAssemblySource } from '../';
3+
import type { AssemblyDirectoryProps, AssemblySourceProps, ICloudAssemblySource } from '../';
44
import { ContextAwareCloudAssembly, ContextAwareCloudAssemblyProps } from './context-aware-source';
55
import { execInChildProcess } from './exec';
66
import { assemblyFromDirectory, changeDir, determineOutputDirectory, guessExecutable, prepareDefaultEnvironment, withContext, withEnv } from './prepare-source';
@@ -52,7 +52,7 @@ export abstract class CloudAssemblySourceBuilder {
5252
return assembly;
5353
}
5454

55-
return new cxapi.CloudAssembly(assembly.directory);
55+
return assemblyFromDirectory(assembly.directory, services.ioHost, props.loadAssemblyOptions);
5656
},
5757
},
5858
contextAssemblyProps,
@@ -64,7 +64,7 @@ export abstract class CloudAssemblySourceBuilder {
6464
* @param directory the directory of a already produced Cloud Assembly.
6565
* @returns the CloudAssembly source
6666
*/
67-
public async fromAssemblyDirectory(directory: string): Promise<ICloudAssemblySource> {
67+
public async fromAssemblyDirectory(directory: string, props: AssemblyDirectoryProps = {}): Promise<ICloudAssemblySource> {
6868
const services: ToolkitServices = await this.sourceBuilderServices();
6969
const contextAssemblyProps: ContextAwareCloudAssemblyProps = {
7070
services,
@@ -77,7 +77,7 @@ export abstract class CloudAssemblySourceBuilder {
7777
produce: async () => {
7878
// @todo build
7979
await services.ioHost.notify(CODES.CDK_ASSEMBLY_I0150.msg('--app points to a cloud assembly, so we bypass synth'));
80-
return assemblyFromDirectory(directory, services.ioHost);
80+
return assemblyFromDirectory(directory, services.ioHost, props.loadAssemblyOptions);
8181
},
8282
},
8383
contextAssemblyProps,
@@ -136,7 +136,7 @@ export abstract class CloudAssemblySourceBuilder {
136136
extraEnv: envWithContext,
137137
cwd: props.workingDirectory,
138138
});
139-
return assemblyFromDirectory(outdir, services.ioHost);
139+
return assemblyFromDirectory(outdir, services.ioHost, props.loadAssemblyOptions);
140140
});
141141
} finally {
142142
await lock?.release();

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/source-builder.ts

+40
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ export interface AssemblyBuilderProps {
1717

1818
export type AssemblyBuilder = (props: AssemblyBuilderProps) => Promise<cxschema.ICloudAssembly>;
1919

20+
/**
21+
* Configuration for creating a CLI from an AWS CDK App directory
22+
*/
23+
export interface AssemblyDirectoryProps {
24+
/**
25+
* Options to configure loading of the assembly after it has been synthesized
26+
*/
27+
readonly loadAssemblyOptions?: LoadAssemblyOptions;
28+
}
29+
2030
/**
2131
* Configuration for creating a CLI from an AWS CDK App directory
2232
*/
@@ -59,6 +69,11 @@ export interface AssemblySourceProps {
5969
* Options that are passed through the context to a CDK app on synth
6070
*/
6171
readonly synthOptions?: AppSynthOptions;
72+
73+
/**
74+
* Options to configure loading of the assembly after it has been synthesized
75+
*/
76+
readonly loadAssemblyOptions?: LoadAssemblyOptions;
6277
}
6378

6479
/**
@@ -123,3 +138,28 @@ export interface AppSynthOptions {
123138
*/
124139
readonly bundlingForStacks?: string;
125140
}
141+
142+
/**
143+
* Options to configure loading of the assembly after it has been synthesized
144+
*/
145+
export interface LoadAssemblyOptions {
146+
/**
147+
* Check the Toolkit supports the Cloud Assembly Schema version
148+
*
149+
* When disabled, allows to Toolkit to read a newer cloud assembly than the CX API is designed
150+
* to support. Your application may not be aware of all features that in use in the Cloud Assembly.
151+
*
152+
* @default true
153+
*/
154+
readonly checkVersion?: boolean;
155+
156+
/**
157+
* Validate enums to only have known values
158+
*
159+
* When disabled, the Toolkit may read enum values it doesn't know about yet.
160+
* You will have to make sure to always check the values of enums you encounter in the manifest.
161+
*
162+
* @default true
163+
*/
164+
readonly checkEnums?: boolean;
165+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "39.0.0",
3+
"files": {
4+
"6cf0c6d5d33f7914e048b4435b7ffc1909cdec43efb95fcde227762c2f0effd1": {
5+
"source": {
6+
"path": "Stack1.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "6cf0c6d5d33f7914e048b4435b7ffc1909cdec43efb95fcde227762c2f0effd1.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}

0 commit comments

Comments
 (0)