Skip to content

Commit

Permalink
feat: remove codeEnabled setting (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelkaporin authored Jul 27, 2021
1 parent ee32af9 commit 7e7c8c9
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 46 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 0 additions & 20 deletions src/snyk/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,18 +25,15 @@ export interface IConfiguration {
snykCodeUrl: string;
token: string | undefined;
setToken(token: string): Promise<void>;
codeEnabled: boolean | undefined;
shouldReportErrors: boolean;
shouldReportEvents: boolean;
setCodeEnabled(value: boolean): Promise<void>;
}

export class Configuration implements IConfiguration {
// These attributes are used in tests
private staticToken = '';
private defaultBaseURL = 'https://deeproxy.snyk.io';
private defaultAuthHost = 'https://snyk.io';
private staticCodeEnabled = false;

constructor(
private processEnv: NodeJS.ProcessEnv = process.env,
Expand Down Expand Up @@ -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<boolean | undefined>(this.getConfigName(ADVANCED_ADVANCED_CODE_ENABLED_SETTING))
);
}

async setCodeEnabled(value = true): Promise<void> {
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)
Expand Down
1 change: 0 additions & 1 deletion src/snyk/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
12 changes: 0 additions & 12 deletions src/snyk/lib/modules/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,13 @@ export class SnykCode implements ISnykCode {
}

async isEnabled(): Promise<boolean> {
// 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<boolean> {
let settings = await getSastSettings();
if (settings.sastEnabled) {
await this.config.setCodeEnabled(true);
return true;
}

Expand All @@ -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;
}

Expand Down
5 changes: 0 additions & 5 deletions src/snyk/lib/watchers/SnykSettingsWatcher.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,9 +14,6 @@ class SnykSettingsWatcher implements SnykWatcherInterface {
private async onChangeConfiguration(extension: ExtensionInterface, key: string): Promise<void> {
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) {
Expand All @@ -41,7 +37,6 @@ class SnykSettingsWatcher implements SnykWatcherInterface {
async (event: vscode.ConfigurationChangeEvent): Promise<void> => {
const change = [
TOKEN_SETTING,
ADVANCED_ADVANCED_CODE_ENABLED_SETTING,
ADVANCED_ADVANCED_MODE_SETTING,
YES_TELEMETRY_SETTING,
CODE_SECURITY_ENABLED_SETTING,
Expand Down
9 changes: 7 additions & 2 deletions src/test/integration/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
Expand Down

0 comments on commit 7e7c8c9

Please sign in to comment.