Skip to content

Commit

Permalink
chore: cleanup redundant files [HEAD-1020] (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong committed Nov 23, 2023
1 parent 85ca7e4 commit 05cc6fa
Show file tree
Hide file tree
Showing 37 changed files with 196 additions and 1,601 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"activationEvents": [
"onWebviewPanel:snyk.views.suggestion.code",
"onWebviewPanel:snyk.views.suggestion.oss",
"onWebviewPanel:snyk.views.suggestion.oss.languageServer",
"*"
],
"main": "./out/extension.js",
Expand Down Expand Up @@ -236,11 +235,6 @@
"name": "Snyk",
"when": "!snyk:loggedIn || snyk:error || !snyk:workspaceFound"
},
{
"id": "snyk.views.analysis.oss.languageServer",
"name": "Open Source Security (LS)",
"when": "snyk:initialized && snyk:loggedIn && snyk:workspaceFound && !snyk:error"
},
{
"id": "snyk.views.analysis.oss",
"name": "Open Source Security",
Expand Down
10 changes: 3 additions & 7 deletions src/snyk/base/modules/baseSnykModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import { IMarkdownStringAdapter, MarkdownStringAdapter } from '../../common/vsco
import { IWatcher } from '../../common/watchers/interfaces';
import { ICodeSettings } from '../../snykCode/codeSettings';
import SnykEditorsWatcher from '../../snykCode/watchers/editorsWatcher';
import { OssServiceLanguageServer } from '../../snykOss/ossServiceLanguageServer';
import { OssService } from '../../snykOss/services/ossService';
import { OssVulnerabilityCountServiceLS } from '../../snykOss/services/vulnerabilityCount/ossVulnerabilityCountServiceLS';
import { OssService } from '../../snykOss/ossService';
import { OssVulnerabilityCountService } from '../../snykOss/services/vulnerabilityCount/ossVulnerabilityCountService';
import { IAuthenticationService } from '../services/authenticationService';
import { ScanModeService } from '../services/scanModeService';
import SnykStatusBarItem, { IStatusBarItem } from '../statusBarItem/statusBarItem';
Expand All @@ -46,11 +45,10 @@ export default abstract class BaseSnykModule implements IBaseSnykModule {
protected authService: IAuthenticationService;
protected downloadService: DownloadService;
protected ossService?: OssService;
protected ossServiceLanguageServer?: OssServiceLanguageServer;
protected advisorService?: AdvisorProvider;
protected commandController: CommandController;
protected scanModeService: ScanModeService;
protected ossVulnerabilityCountServiceLanguageServer: OssVulnerabilityCountServiceLS;
protected ossVulnerabilityCountService: OssVulnerabilityCountService;
protected advisorScoreDisposable: AdvisorService;
protected languageServer: ILanguageServer;

Expand Down Expand Up @@ -87,6 +85,4 @@ export default abstract class BaseSnykModule implements IBaseSnykModule {
}

abstract runScan(): Promise<void>;

abstract runOssScan(): Promise<void>;
}
1 change: 0 additions & 1 deletion src/snyk/base/modules/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface IBaseSnykModule {

// Abstract methods
runScan(): Promise<void>;
runOssScan(manual?: boolean): Promise<void>;
}

export interface ISnykLib {
Expand Down
34 changes: 1 addition & 33 deletions src/snyk/base/modules/snykLib.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as _ from 'lodash';
import { firstValueFrom } from 'rxjs';
import { CliError } from '../../cli/services/cliService';
import { SupportedAnalysisProperties } from '../../common/analytics/itly';
import { configuration } from '../../common/configuration/instance';
import { DEFAULT_SCAN_DEBOUNCE_INTERVAL, IDE_NAME, OSS_SCAN_DEBOUNCE_INTERVAL } from '../../common/constants/general';
import { DEFAULT_SCAN_DEBOUNCE_INTERVAL, IDE_NAME } from '../../common/constants/general';
import { SNYK_CONTEXT } from '../../common/constants/views';
import { ErrorHandler } from '../../common/error/errorHandler';
import { Logger } from '../../common/logger/logger';
Expand All @@ -23,7 +21,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
return;
}

// Only starts OSS scan. Code & IaC scans are managed by LS
Logger.info('Starting full scan');

await this.contextService.setContext(SNYK_CONTEXT.AUTHENTICATING, false);
Expand All @@ -39,7 +36,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
const workspacePaths = vsCodeWorkspace.getWorkspaceFolders();
if (workspacePaths.length) {
this.logFullAnalysisIsTriggered(manual);
void this.startOssAnalysis(manual, false);
}
} catch (err) {
await ErrorHandler.handleGlobal(err, Logger, this.contextService, this.loadingBadge);
Expand All @@ -48,11 +44,8 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {

// This function is called by commands, error handlers, etc.
// We should avoid having duplicate parallel executions.
// Only starts OSS scan. Code & IaC scans are managed by LS
public runScan = _.debounce(this.runFullScan_.bind(this), DEFAULT_SCAN_DEBOUNCE_INTERVAL, { leading: true });

public runOssScan = _.debounce(this.startOssAnalysis.bind(this), OSS_SCAN_DEBOUNCE_INTERVAL, { leading: true });

async enableCode(): Promise<void> {
Logger.info('Enabling Snyk Code');
const wasEnabled = await this.codeSettings.enable();
Expand All @@ -66,12 +59,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
}
}

onDidChangeOssTreeVisibility(visible: boolean): void {
if (this.ossService) {
this.ossService.setVulnerabilityTreeVisibility(visible);
}
}

async checkAdvancedMode(): Promise<void> {
await this.contextService.setContext(SNYK_CONTEXT.ADVANCED, configuration.shouldShowAdvancedView);
}
Expand All @@ -81,25 +68,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
await this.contextService.setContext(SNYK_CONTEXT.WORKSPACE_FOUND, workspaceFound);
}

private async startOssAnalysis(manual = false, reportTriggeredEvent = true): Promise<void> {
if (!configuration.getFeaturesConfiguration()?.ossEnabled) return;
if (!this.ossService) throw new Error('OSS service is not initialized.');

// wait until Snyk Language Server is downloaded
await firstValueFrom(this.downloadService.downloadReady$);

try {
const result = await this.ossService.test(manual, reportTriggeredEvent);

if (result instanceof CliError || !result) {
return;
}
} catch (err) {
// catch unhandled error cases by reporting test failure
this.ossService.finalizeTest(new CliError(err));
}
}

private isSnykCodeAutoscanSuspended(manual: boolean) {
return !manual && !this.scanModeService.isCodeAutoScanAllowed();
}
Expand Down
4 changes: 2 additions & 2 deletions src/snyk/common/commands/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createDCIgnore } from '../../snykCode/utils/ignoreFileUtils';
import { IssueUtils } from '../../snykCode/utils/issueUtils';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { IacIssueCommandArg } from '../../snykIac/views/interfaces';
import { OssServiceLanguageServer } from '../../snykOss/ossServiceLanguageServer';
import { OssService } from '../../snykOss/ossService';
import { IAnalytics } from '../analytics/itly';
import {
SNYK_INITIATE_LOGIN_COMMAND,
Expand Down Expand Up @@ -39,7 +39,7 @@ export class CommandController {
private authService: IAuthenticationService,
private snykCode: IProductService<CodeIssueData>,
private iacService: IProductService<IacIssueData>,
private ossService: OssServiceLanguageServer,
private ossService: OssService,
private scanModeService: ScanModeService,
private workspace: IVSCodeWorkspace,
private commands: IVSCodeCommands,
Expand Down
12 changes: 2 additions & 10 deletions src/snyk/common/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { completeFileSuggestionType } from '../../snykCode/interfaces';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { IacIssueCommandArg } from '../../snykIac/views/interfaces';
import { OssIssueCommandArgLanguageServer } from '../../snykOss/interfaces';
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { CodeIssueData, Issue } from '../languageServer/types';

export enum OpenCommandIssueType {
Expand All @@ -12,20 +11,13 @@ export enum OpenCommandIssueType {
}

export type OpenIssueCommandArg = {
issue: CodeIssueCommandArg | OssIssueCommandArg | IacIssueCommandArg | OssIssueCommandArgLanguageServer;
issue: CodeIssueCommandArg | IacIssueCommandArg | OssIssueCommandArgLanguageServer;
issueType: OpenCommandIssueType;
};

export const isCodeIssue = (
_issue: completeFileSuggestionType | Issue<CodeIssueData> | OssIssueCommandArg | OssIssueCommandArgLanguageServer,
_issue: completeFileSuggestionType | Issue<CodeIssueData> | OssIssueCommandArgLanguageServer,
issueType: OpenCommandIssueType,
): _issue is Issue<CodeIssueData> => {
return issueType === OpenCommandIssueType.CodeIssue;
};

export const isOssIssue = (
_issue: completeFileSuggestionType | Issue<CodeIssueData> | OssIssueCommandArg | OssIssueCommandArgLanguageServer,
issueType: OpenCommandIssueType,
): _issue is OssIssueCommandArg => {
return issueType === OpenCommandIssueType.OssVulnerability;
};
1 change: 0 additions & 1 deletion src/snyk/common/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const IDE_NAME_SHORT = 'vscode';
export const COMMAND_DEBOUNCE_INTERVAL = 200; // 200 milliseconds
export const DEFAULT_SCAN_DEBOUNCE_INTERVAL = 1000; // 1 second
export const DEFAULT_LS_DEBOUNCE_INTERVAL = 1000; // 1 second
export const OSS_SCAN_DEBOUNCE_INTERVAL = 10000; // 10 seconds
export const EXECUTION_THROTTLING_INTERVAL = 1000 * 10; // * 60 * 30; // 30 minutes
export const EXECUTION_PAUSE_INTERVAL = 1000 * 60 * 30; // 30 minutes
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200; // 200 milliseconds
Expand Down
2 changes: 0 additions & 2 deletions src/snyk/common/constants/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ export const SNYK_VIEW_ANALYSIS_CODE_ENABLEMENT = 'snyk.views.analysis.code.enab
export const SNYK_VIEW_ANALYSIS_CODE_SECURITY = 'snyk.views.analysis.code.security';
export const SNYK_VIEW_ANALYSIS_CODE_QUALITY = 'snyk.views.analysis.code.quality';
export const SNYK_VIEW_ANALYSIS_OSS = 'snyk.views.analysis.oss';
export const SNYK_VIEW_ANALYSIS_OSS_LANGUAGE_SERVER = 'snyk.views.analysis.oss.languageServer';
export const SNYK_VIEW_SUPPORT = 'snyk.views.support';
export const SNYK_VIEW_SUGGESTION_CODE = 'snyk.views.suggestion.code';
export const SNYK_VIEW_SUGGESTION_OSS = 'snyk.views.suggestion.oss';
export const SNYK_VIEW_SUGGESTION_OSS_LANGUAGE_SERVER = 'snyk.views.suggestion.oss.languageServer';
export const SNYK_VIEW_SUGGESTION_IAC = 'snyk.views.suggestion.iac';
export const SNYK_VIEW_ANALYSIS_IAC = 'snyk.views.analysis.configuration';

Expand Down
23 changes: 0 additions & 23 deletions src/snyk/common/services/learnService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { SNYK_GET_LESSON_COMMAND } from '../constants/commands';
import { CodeIssueData, Issue } from '../languageServer/types';
import { IVSCodeCommands } from '../vscode/commands';
Expand All @@ -11,28 +10,6 @@ export type Lesson = {
export class LearnService {
constructor(private commandExecutor: IVSCodeCommands) {}

async getOssLesson(vulnerability: OssIssueCommandArg): Promise<Lesson | undefined> {
const cwe = vulnerability.identifiers?.CWE;
let cweElement = '';
if (cwe && cwe.length > 0) {
cweElement = cwe[0];
}

const cve = vulnerability.identifiers?.CWE;
let cveElement = '';
if (cve && cve.length > 0) {
cveElement = cve[0];
}
return this.commandExecutor.executeCommand(
SNYK_GET_LESSON_COMMAND,
vulnerability.id,
vulnerability.packageManager,
cweElement,
cveElement,
4,
);
}

async getCodeLesson(issue: Issue<CodeIssueData>): Promise<Lesson | undefined> {
const ruleSplit = issue.additionalData.ruleId.split('/');
const rule = ruleSplit[ruleSplit.length - 1];
Expand Down
Loading

0 comments on commit 05cc6fa

Please sign in to comment.