Skip to content

Commit f827a88

Browse files
stephankaagRomainMuller
authored andcommitted
fix: Don't collect runtime information when versionReporting is disabled (#1890)
1 parent 72d2535 commit f827a88

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

packages/@aws-cdk/cdk/lib/app.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ export class App extends Root {
4545

4646
const result: cxapi.SynthesizeResponse = {
4747
version: cxapi.PROTO_RESPONSE_VERSION,
48-
stacks: this.synthesizeStacks(Object.keys(this.stacks)),
49-
runtime: this.collectRuntimeInformation()
48+
stacks: this.synthesizeStacks(Object.keys(this.stacks))
5049
};
5150

51+
const disableVersionReporting = this.node.getContext(cxapi.DISABLE_VERSION_REPORTING);
52+
if (!disableVersionReporting) {
53+
result.runtime = this.collectRuntimeInformation();
54+
}
55+
5256
const outfile = path.join(outdir, cxapi.OUTFILE_NAME);
5357
fs.writeFileSync(outfile, JSON.stringify(result, undefined, 2));
5458
}

packages/@aws-cdk/cdk/test/test.app.ts

+13
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ export = {
268268
test.done();
269269
},
270270

271+
'runtime library versions disabled'(test: Test) {
272+
const context: any = {};
273+
context[cxapi.DISABLE_VERSION_REPORTING] = true;
274+
275+
const response = withApp(context, app => {
276+
const stack = new Stack(app, 'stack1');
277+
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
278+
});
279+
280+
test.equals(response.runtime, undefined);
281+
test.done();
282+
},
283+
271284
'runtime library versions'(test: Test) {
272285
const response = withApp({}, app => {
273286
const stack = new Stack(app, 'stack1');

packages/@aws-cdk/cx-api/lib/cxapi.ts

+5
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ export const PATH_METADATA_KEY = 'aws:cdk:path';
133133
* Enables the embedding of the "aws:cdk:path" in CloudFormation template metadata.
134134
*/
135135
export const PATH_METADATA_ENABLE_CONTEXT = 'aws:cdk:enable-path-metadata';
136+
137+
/**
138+
* Disable the collection and reporting of version information.
139+
*/
140+
export const DISABLE_VERSION_REPORTING = 'aws:cdk:disable-version-reporting';

packages/aws-cdk/lib/api/cxapp/exec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ export async function execProgram(aws: SDK, config: Configuration): Promise<cxap
3333
context[cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT] = true;
3434
}
3535

36+
let versionReporting: boolean = config.get(['versionReporting']);
37+
if (versionReporting === undefined) {
38+
versionReporting = true; // defaults to true
39+
}
40+
41+
if (!versionReporting) {
42+
context[cxapi.DISABLE_VERSION_REPORTING] = true;
43+
}
44+
3645
debug('context:', context);
3746

3847
env[cxapi.CONTEXT_ENV] = JSON.stringify(context);

0 commit comments

Comments
 (0)