From 7e7c8c98a5393f4c5624de8c581499a725d1db21 Mon Sep 17 00:00:00 2001 From: Michel Kaporin Date: Tue, 27 Jul 2021 10:49:03 +0200 Subject: [PATCH] feat: remove codeEnabled setting (#31) --- package.json | 6 ------ src/snyk/configuration.ts | 20 -------------------- src/snyk/constants/settings.ts | 1 - src/snyk/lib/modules/code.ts | 12 ------------ src/snyk/lib/watchers/SnykSettingsWatcher.ts | 5 ----- src/test/integration/configuration.test.ts | 9 +++++++-- 6 files changed, 7 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 16f042026..b90e173e5 100644 --- a/package.json +++ b/package.json @@ -79,12 +79,6 @@ "description": "Allows the user to configure if Snyk analysis is run automatically, manually or every 30 minutes. Default is automatically on save.", "scope": "application" }, - "snyk.advanced.codeEnabled": { - "type": "boolean", - "markdownDescription": "Mirrors if Snyk Code is enabled or disabled for [your Snyk organisation](https://app.snyk.io/manage/snyk-code). Please do not manually edit this configuration as it might cause unpredictable behaviour.", - "scope": "window", - "default": null - }, "snyk.features.codeSecurity": { "type": "boolean", "title": "Snyk Code security issues", diff --git a/src/snyk/configuration.ts b/src/snyk/configuration.ts index e81053522..b46ec7bcb 100644 --- a/src/snyk/configuration.ts +++ b/src/snyk/configuration.ts @@ -2,7 +2,6 @@ import { URL } from 'url'; import * as vscode from 'vscode'; import { IDE_NAME } from './constants/general'; import { - ADVANCED_ADVANCED_CODE_ENABLED_SETTING, ADVANCED_ADVANCED_MODE_SETTING, CODE_QUALITY_ENABLED_SETTING, CODE_SECURITY_ENABLED_SETTING, @@ -26,10 +25,8 @@ export interface IConfiguration { snykCodeUrl: string; token: string | undefined; setToken(token: string): Promise; - codeEnabled: boolean | undefined; shouldReportErrors: boolean; shouldReportEvents: boolean; - setCodeEnabled(value: boolean): Promise; } export class Configuration implements IConfiguration { @@ -37,7 +34,6 @@ export class Configuration implements IConfiguration { private staticToken = ''; private defaultBaseURL = 'https://deeproxy.snyk.io'; private defaultAuthHost = 'https://snyk.io'; - private staticCodeEnabled = false; constructor( private processEnv: NodeJS.ProcessEnv = process.env, @@ -108,22 +104,6 @@ export class Configuration implements IConfiguration { .update(this.getConfigName(CODE_QUALITY_ENABLED_SETTING), config.codeQualityEnabled, true); } - get codeEnabled(): boolean | undefined { - return ( - this.staticCodeEnabled || - this.source !== IDE_NAME || - this.vscodeWorkspace - .getConfiguration(CONFIGURATION_IDENTIFIER) - .get(this.getConfigName(ADVANCED_ADVANCED_CODE_ENABLED_SETTING)) - ); - } - - async setCodeEnabled(value = true): Promise { - await this.vscodeWorkspace - .getConfiguration(CONFIGURATION_IDENTIFIER) - .update(this.getConfigName(ADVANCED_ADVANCED_CODE_ENABLED_SETTING), value, true); - } - get shouldReportErrors(): boolean { return !!this.vscodeWorkspace .getConfiguration(CONFIGURATION_IDENTIFIER) diff --git a/src/snyk/constants/settings.ts b/src/snyk/constants/settings.ts index 68870e72a..b81930ba8 100644 --- a/src/snyk/constants/settings.ts +++ b/src/snyk/constants/settings.ts @@ -11,4 +11,3 @@ 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 ADVANCED_ADVANCED_MODE_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.advancedMode`; -export const ADVANCED_ADVANCED_CODE_ENABLED_SETTING = `${CONFIGURATION_IDENTIFIER}.advanced.codeEnabled`; diff --git a/src/snyk/lib/modules/code.ts b/src/snyk/lib/modules/code.ts index 319be11a3..85988adfd 100644 --- a/src/snyk/lib/modules/code.ts +++ b/src/snyk/lib/modules/code.ts @@ -65,23 +65,13 @@ export class SnykCode implements ISnykCode { } async isEnabled(): Promise { - // Code was disabled explicitly - if (this.config.codeEnabled === false) { - return false; - } - const settings = await getSastSettings(); - if (this.config.codeEnabled !== settings.sastEnabled) { - await this.config.setCodeEnabled(settings.sastEnabled); - } - return settings.sastEnabled; } async enable(): Promise { let settings = await getSastSettings(); if (settings.sastEnabled) { - await this.config.setCodeEnabled(true); return true; } @@ -95,12 +85,10 @@ export class SnykCode implements ISnykCode { settings = await getSastSettings(); if (settings.sastEnabled) { - await this.config.setCodeEnabled(true); return true; } } - await this.config.setCodeEnabled(false); return false; } diff --git a/src/snyk/lib/watchers/SnykSettingsWatcher.ts b/src/snyk/lib/watchers/SnykSettingsWatcher.ts index 858c7a4f4..39c4bebad 100644 --- a/src/snyk/lib/watchers/SnykSettingsWatcher.ts +++ b/src/snyk/lib/watchers/SnykSettingsWatcher.ts @@ -1,7 +1,6 @@ import * as vscode from 'vscode'; import { ExtensionInterface, SnykWatcherInterface } from '../../../interfaces/SnykInterfaces'; import { - ADVANCED_ADVANCED_CODE_ENABLED_SETTING, ADVANCED_ADVANCED_MODE_SETTING, CODE_QUALITY_ENABLED_SETTING, CODE_SECURITY_ENABLED_SETTING, @@ -15,9 +14,6 @@ class SnykSettingsWatcher implements SnykWatcherInterface { private async onChangeConfiguration(extension: ExtensionInterface, key: string): Promise { if (key === ADVANCED_ADVANCED_MODE_SETTING) { return extension.checkAdvancedMode(); - } else if (key === ADVANCED_ADVANCED_CODE_ENABLED_SETTING) { - void extension.checkCodeEnabled(); - return; } else if (key === YES_TELEMETRY_SETTING) { return extension.analytics.setShouldReportEvents(configuration.shouldReportEvents); } else if (key === CODE_SECURITY_ENABLED_SETTING || key === CODE_QUALITY_ENABLED_SETTING) { @@ -41,7 +37,6 @@ class SnykSettingsWatcher implements SnykWatcherInterface { async (event: vscode.ConfigurationChangeEvent): Promise => { const change = [ TOKEN_SETTING, - ADVANCED_ADVANCED_CODE_ENABLED_SETTING, ADVANCED_ADVANCED_MODE_SETTING, YES_TELEMETRY_SETTING, CODE_SECURITY_ENABLED_SETTING, diff --git a/src/test/integration/configuration.test.ts b/src/test/integration/configuration.test.ts index 779d21ff5..33335c188 100644 --- a/src/test/integration/configuration.test.ts +++ b/src/test/integration/configuration.test.ts @@ -14,12 +14,17 @@ suite('Configuration', () => { test('configuration change is reflected', async () => { const token = 'fake-token'; + const featuresConfig = { + codeSecurityEnabled: true, + codeQualityEnabled: false, + }; + await configuration.setToken(token); - await configuration.setCodeEnabled(false); + await configuration.setFeaturesConfiguration(featuresConfig); await configuration.setShouldReportEvents(false); strictEqual(configuration.token, token); - strictEqual(configuration.codeEnabled, false); + strictEqual(configuration.getFeaturesConfiguration(), featuresConfig); strictEqual(configuration.shouldReportEvents, false); await configuration.setToken(''); });