Skip to content

Commit

Permalink
fix: Don't collect runtime information when versionReporting is disab…
Browse files Browse the repository at this point in the history
…led (#1890)
  • Loading branch information
stephankaag authored and RomainMuller committed Feb 28, 2019
1 parent 72d2535 commit f827a88
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/@aws-cdk/cdk/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ export class App extends Root {

const result: cxapi.SynthesizeResponse = {
version: cxapi.PROTO_RESPONSE_VERSION,
stacks: this.synthesizeStacks(Object.keys(this.stacks)),
runtime: this.collectRuntimeInformation()
stacks: this.synthesizeStacks(Object.keys(this.stacks))
};

const disableVersionReporting = this.node.getContext(cxapi.DISABLE_VERSION_REPORTING);
if (!disableVersionReporting) {
result.runtime = this.collectRuntimeInformation();
}

const outfile = path.join(outdir, cxapi.OUTFILE_NAME);
fs.writeFileSync(outfile, JSON.stringify(result, undefined, 2));
}
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/cdk/test/test.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ export = {
test.done();
},

'runtime library versions disabled'(test: Test) {
const context: any = {};
context[cxapi.DISABLE_VERSION_REPORTING] = true;

const response = withApp(context, app => {
const stack = new Stack(app, 'stack1');
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
});

test.equals(response.runtime, undefined);
test.done();
},

'runtime library versions'(test: Test) {
const response = withApp({}, app => {
const stack = new Stack(app, 'stack1');
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/cx-api/lib/cxapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ export const PATH_METADATA_KEY = 'aws:cdk:path';
* Enables the embedding of the "aws:cdk:path" in CloudFormation template metadata.
*/
export const PATH_METADATA_ENABLE_CONTEXT = 'aws:cdk:enable-path-metadata';

/**
* Disable the collection and reporting of version information.
*/
export const DISABLE_VERSION_REPORTING = 'aws:cdk:disable-version-reporting';
9 changes: 9 additions & 0 deletions packages/aws-cdk/lib/api/cxapp/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export async function execProgram(aws: SDK, config: Configuration): Promise<cxap
context[cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT] = true;
}

let versionReporting: boolean = config.get(['versionReporting']);
if (versionReporting === undefined) {
versionReporting = true; // defaults to true
}

if (!versionReporting) {
context[cxapi.DISABLE_VERSION_REPORTING] = true;
}

debug('context:', context);

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

0 comments on commit f827a88

Please sign in to comment.