Skip to content

Commit d40bf52

Browse files
kaizenccgithub-actions
andauthored
feat(cli): --no-version-reporting equals --no-telemetry for cli telemetry and library metadata exclusion (#718)
`--no-version-reporting` and `--no-telemetry` will disable cli telemetry and library metadata for that specific command execution. to disable cli telemetry permanently see options [here](https://github.com/aws/aws-cdk-rfcs/blob/main/text/0732-cdk-cli-telemetry.md#opt-out) --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent 12aa647 commit d40bf52

File tree

10 files changed

+27
-18
lines changed

10 files changed

+27
-18
lines changed

packages/aws-cdk/lib/cli/cdk-toolkit.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ export class CdkToolkit {
208208
await this.props.configuration.saveContext();
209209
}
210210

211-
public async cliTelemetryStatus() {
212-
const canCollect = canCollectTelemetry(this.props.configuration.context);
211+
public async cliTelemetryStatus(versionReporting: boolean = true) {
212+
// recreate the version-reporting property in args rather than bring the entire args object over
213+
const args = { ['version-reporting']: versionReporting };
214+
const canCollect = canCollectTelemetry(args, this.props.configuration.context);
213215
if (canCollect) {
214216
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.');
215217
} else {

packages/aws-cdk/lib/cli/cli-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function makeConfig(): Promise<CliConfig> {
3232
'proxy': { type: 'string', desc: 'Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified', requiresArg: true },
3333
'ca-bundle-path': { type: 'string', desc: 'Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified', requiresArg: true },
3434
'ec2creds': { type: 'boolean', alias: 'i', default: undefined, desc: 'Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status' },
35-
'version-reporting': { type: 'boolean', desc: 'Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)', default: undefined },
35+
'version-reporting': { type: 'boolean', desc: 'Disable CLI telemetry and do not include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)', default: undefined, alias: 'telemetry' },
3636
'path-metadata': { type: 'boolean', desc: 'Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)', default: undefined },
3737
'asset-metadata': { type: 'boolean', desc: 'Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default)', default: undefined },
3838
'role-arn': { type: 'string', alias: 'r', desc: 'ARN of Role to use when invoking CloudFormation', default: undefined, requiresArg: true },

packages/aws-cdk/lib/cli/cli-type-registry.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
},
7979
"version-reporting": {
8080
"type": "boolean",
81-
"desc": "Include the \"AWS::CDK::Metadata\" resource in synthesized templates (enabled by default)"
81+
"desc": "Disable CLI telemetry and do not include the \"AWS::CDK::Metadata\" resource in synthesized templates (enabled by default)",
82+
"alias": "telemetry"
8283
},
8384
"path-metadata": {
8485
"type": "boolean",

packages/aws-cdk/lib/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
501501
}
502502

503503
if (args.status) {
504-
return cli.cliTelemetryStatus();
504+
return cli.cliTelemetryStatus(args['version-reporting']);
505505
} else {
506506
const enable = args.enable ?? !args.disable;
507507
return cli.cliTelemetry(enable);

packages/aws-cdk/lib/cli/io-host/cli-io-host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class CliIoHost implements IIoHost {
181181
});
182182
}
183183
// TODO: uncomment this at launch
184-
// if (canCollectTelemetry(context)) {
184+
// if (canCollectTelemetry(args, context)) {
185185
// sink = new EndpointTelemetrySink({
186186
// ioHost: this,
187187
// agent: proxyAgent,

packages/aws-cdk/lib/cli/parse-command-line-arguments.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export function parseCommandLineArguments(args: Array<string>): any {
102102
.option('version-reporting', {
103103
default: undefined,
104104
type: 'boolean',
105-
desc: 'Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)',
105+
desc: 'Disable CLI telemetry and do not include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)',
106+
alias: 'telemetry',
106107
})
107108
.option('path-metadata', {
108109
default: undefined,

packages/aws-cdk/lib/cli/telemetry/collect-telemetry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import type { Context } from '../../api/context';
33
/**
44
* Whether or not we collect telemetry
55
*/
6-
export function canCollectTelemetry(context: Context): boolean {
7-
if ((['true', '1'].includes(process.env.CDK_DISABLE_CLI_TELEMETRY ?? '')) || ['false', false].includes(context.get('cli-telemetry'))) {
6+
export function canCollectTelemetry(args: any, context: Context): boolean {
7+
if ((['true', '1'].includes(process.env.CDK_DISABLE_CLI_TELEMETRY ?? '')) ||
8+
['false', false].includes(context.get('cli-telemetry')) ||
9+
(args['version-reporting'] !== undefined && !args['version-reporting'])) /* aliased with telemetry option */ {
810
return false;
911
}
1012

packages/aws-cdk/lib/cli/user-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export interface GlobalOptions {
252252
readonly ec2creds?: boolean;
253253

254254
/**
255-
* Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)
255+
* Disable CLI telemetry and do not include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)
256256
*
257257
* @default - undefined
258258
*/

packages/aws-cdk/lib/cli/version.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* c8 ignore start */
21
import * as path from 'path';
32
import { cliRootDir } from './root-dir';
43

packages/aws-cdk/test/cli/telemetry/collect-telemetry.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,42 @@ describe(canCollectTelemetry, () => {
1010
});
1111

1212
test('returns true by default', async () => {
13-
expect(canCollectTelemetry(context)).toBeTruthy();
13+
expect(canCollectTelemetry({}, context)).toBeTruthy();
1414
});
1515

1616
test('returns false if env variable is set to true', async () => {
1717
await withEnv(async () => {
18-
expect(canCollectTelemetry(context)).toBeFalsy();
18+
expect(canCollectTelemetry({}, context)).toBeFalsy();
1919
}, {
2020
CDK_DISABLE_CLI_TELEMETRY: 'true',
2121
});
2222
});
2323

2424
test('returns false if env variable is set to 1', async () => {
2525
await withEnv(async () => {
26-
expect(canCollectTelemetry(context)).toBeFalsy();
26+
expect(canCollectTelemetry({}, context)).toBeFalsy();
2727
}, {
2828
CDK_DISABLE_CLI_TELEMETRY: '1',
2929
});
3030
});
3131

3232
test('returns false if context is set to false', async () => {
3333
context.set('cli-telemetry', false);
34-
expect(canCollectTelemetry(context)).toBeFalsy();
34+
expect(canCollectTelemetry({}, context)).toBeFalsy();
3535

3636
context.set('cli-telemetry', 'false');
37-
expect(canCollectTelemetry(context)).toBeFalsy();
37+
expect(canCollectTelemetry({}, context)).toBeFalsy();
3838
});
3939

4040
test('returns true if context is set to true', async () => {
4141
context.set('cli-telemetry', true);
42-
expect(canCollectTelemetry(context)).toBeTruthy();
42+
expect(canCollectTelemetry({}, context)).toBeTruthy();
4343

4444
context.set('cli-telemetry', 'true');
45-
expect(canCollectTelemetry(context)).toBeTruthy();
45+
expect(canCollectTelemetry({}, context)).toBeTruthy();
46+
});
47+
48+
test('returns false if no-version-reporting is set', async () => {
49+
expect(canCollectTelemetry({ 'version-reporting': false }, context)).toBeFalsy();
4650
});
4751
});

0 commit comments

Comments
 (0)