diff --git a/package.json b/package.json index 6cd2dd0ce..a1223d5b5 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,13 @@ { "title": "Snyk Security - Code and Open Source Dependencies", "properties": { + "snyk.yesAnalyticsReport": { + "//": "Name starts with y to put it at the end, as configs are sorted alphbetically", + "type": "boolean", + "default": true, + "markdownDescription": "Send usage statistics to Snyk", + "scope": "application" + }, "snyk.yesCrashReport": { "//": "Name starts with y to put it at the end, as configs are sorted alphbetically", "type": "boolean", diff --git a/src/snyk/common/configuration/configuration.ts b/src/snyk/common/configuration/configuration.ts index 602f3ba40..30d1d9ce4 100644 --- a/src/snyk/common/configuration/configuration.ts +++ b/src/snyk/common/configuration/configuration.ts @@ -20,6 +20,7 @@ import { SCANNING_MODE, SEVERITY_FILTER_SETTING, TRUSTED_FOLDERS, + YES_ANALYTICS_REPORT, YES_BACKGROUND_OSS_NOTIFICATION_SETTING, YES_CRASH_REPORT_SETTING, YES_TELEMETRY_SETTING, @@ -81,6 +82,7 @@ export interface IConfiguration { shouldReportErrors: boolean; shouldReportEvents: boolean; + shouldReportAnalytics: boolean; shouldShowWelcomeNotification: boolean; hideWelcomeNotification(): Promise; @@ -342,6 +344,22 @@ export class Configuration implements IConfiguration { ); } + get shouldReportAnalytics(): boolean { + return !!this.workspace.getConfiguration( + CONFIGURATION_IDENTIFIER, + this.getConfigName(YES_ANALYTICS_REPORT), + ); + } + + async setShouldReportAnalytics(yesAnalyticsReport: boolean): Promise { + await this.workspace.updateConfiguration( + CONFIGURATION_IDENTIFIER, + this.getConfigName(YES_ANALYTICS_REPORT), + yesAnalyticsReport, + true, + ); + } + get shouldReportErrors(): boolean { return !!this.workspace.getConfiguration( CONFIGURATION_IDENTIFIER, diff --git a/src/snyk/common/constants/settings.ts b/src/snyk/common/constants/settings.ts index 4e831c765..83b6f85a3 100644 --- a/src/snyk/common/constants/settings.ts +++ b/src/snyk/common/constants/settings.ts @@ -12,6 +12,7 @@ export const YES_CRASH_REPORT_SETTING = `${CONFIGURATION_IDENTIFIER}.yesCrashRep export const YES_TELEMETRY_SETTING = `${CONFIGURATION_IDENTIFIER}.yesTelemetry`; export const YES_WELCOME_NOTIFICATION_SETTING = `${CONFIGURATION_IDENTIFIER}.yesWelcomeNotification`; export const YES_BACKGROUND_OSS_NOTIFICATION_SETTING = `${CONFIGURATION_IDENTIFIER}.yesBackgroundOssNotification`; +export const YES_ANALYTICS_REPORT = `${CONFIGURATION_IDENTIFIER}.yesAnalyticsReport`; export const ADVANCED_ADVANCED_MODE_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.advancedMode`; export const ADVANCED_AUTOSCAN_OSS_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.autoScanOpenSourceSecurity`; diff --git a/src/snyk/common/languageServer/settings.ts b/src/snyk/common/languageServer/settings.ts index 7fbe9024b..200499b8e 100644 --- a/src/snyk/common/languageServer/settings.ts +++ b/src/snyk/common/languageServer/settings.ts @@ -24,6 +24,7 @@ export type ServerSettings = { // Reporting and telemetry sendErrorReports?: string; enableTelemetry?: string; + enableAnalytics?: boolean; // Security and scanning settings filterSeverity?: SeverityFilter; @@ -78,6 +79,7 @@ export class LanguageServerSettings { sendErrorReports: `${configuration.shouldReportErrors}`, enableTelemetry: `${configuration.shouldReportEvents}`, + enableAnalytics: configuration.shouldReportAnalytics, filterSeverity: configuration.severityFilter, scanningMode: configuration.scanningMode, diff --git a/src/test/unit/common/languageServer/languageServer.test.ts b/src/test/unit/common/languageServer/languageServer.test.ts index 6155e161c..32151a863 100644 --- a/src/test/unit/common/languageServer/languageServer.test.ts +++ b/src/test/unit/common/languageServer/languageServer.test.ts @@ -47,6 +47,7 @@ suite('Language Server', () => { }, shouldReportEvents: true, shouldReportErrors: true, + shouldReportAnalytics: true, getSnykLanguageServerPath(): string { return path; }, @@ -206,6 +207,7 @@ suite('Language Server', () => { token: 'testToken', cliPath: 'testPath', enableTelemetry: 'true', + enableAnalytics: true, sendErrorReports: 'true', integrationName: 'VS_CODE', integrationVersion: '0.0.0', diff --git a/src/test/unit/common/languageServer/settings.test.ts b/src/test/unit/common/languageServer/settings.test.ts index a85a486f3..8abf7b9ed 100644 --- a/src/test/unit/common/languageServer/settings.test.ts +++ b/src/test/unit/common/languageServer/settings.test.ts @@ -24,6 +24,7 @@ suite('LanguageServerSettings', () => { const mockConfiguration: IConfiguration = { shouldReportEvents: true, shouldReportErrors: false, + shouldReportAnalytics: true, snykOssApiEndpoint: 'https://dev.snyk.io/api', organization: 'my-org', // eslint-disable-next-line @typescript-eslint/require-await @@ -47,6 +48,8 @@ suite('LanguageServerSettings', () => { assert.strictEqual(serverSettings.enableTelemetry, 'true'); assert.strictEqual(serverSettings.sendErrorReports, 'false'); + assert.strictEqual(serverSettings.enableAnalytics, true); + assert.strictEqual(serverSettings.cliPath, '/path/to/cli'); assert.strictEqual(serverSettings.token, 'snyk-token');