From b902bb4cb35dca4340f90d1f7e1cef2e8da78bed Mon Sep 17 00:00:00 2001 From: PeterSchafer <101886095+PeterSchafer@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:46:49 +0200 Subject: [PATCH] chore: minor startup improvement (#368) * chore: remove isDevelopment usage * chore: run scan only after LS start to avoid broken states * chore: move log message to be less confusing * chore: re-add support SNYK_VSCE_DEVELOPMENT_SNYKCODE_BASE_URL fix test * fix: asking for trusting a folder twice [HEAD-286] when authenticating --- src/snyk/base/modules/snykLib.ts | 6 +++--- src/snyk/common/commands/commandController.ts | 2 +- src/snyk/common/configuration/configuration.ts | 4 ++-- src/snyk/extension.ts | 6 +++--- src/test/unit/common/configuration.test.ts | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/snyk/base/modules/snykLib.ts b/src/snyk/base/modules/snykLib.ts index fe744b62b..e96ef1ee1 100644 --- a/src/snyk/base/modules/snykLib.ts +++ b/src/snyk/base/modules/snykLib.ts @@ -14,9 +14,6 @@ import { ISnykLib } from './interfaces'; export default class SnykLib extends BaseSnykModule implements ISnykLib { private async runFullScan_(manual = false): Promise { - // Only starts OSS scan. Code & IaC scans are managed by LS - Logger.info('Starting full scan'); - await this.contextService.setContext(SNYK_CONTEXT.ERROR, false); this.loadingBadge.setLoadingBadge(false); @@ -26,6 +23,9 @@ 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); await this.contextService.setContext(SNYK_CONTEXT.LOGGEDIN, true); diff --git a/src/snyk/common/commands/commandController.ts b/src/snyk/common/commands/commandController.ts index 0acb8edba..cb2f31a28 100644 --- a/src/snyk/common/commands/commandController.ts +++ b/src/snyk/common/commands/commandController.ts @@ -57,8 +57,8 @@ export class CommandController { async initiateLogin(): Promise { this.logger.info('Initiating login'); await this.executeCommand(SNYK_INITIATE_LOGIN_COMMAND, this.authService.initiateLogin.bind(this.authService)); - await this.commands.executeCommand(SNYK_LOGIN_COMMAND); await this.commands.executeCommand(SNYK_TRUST_WORKSPACE_FOLDERS_COMMAND); + await this.commands.executeCommand(SNYK_LOGIN_COMMAND); } async setToken(): Promise { diff --git a/src/snyk/common/configuration/configuration.ts b/src/snyk/common/configuration/configuration.ts index 70a7f102e..62db63731 100644 --- a/src/snyk/common/configuration/configuration.ts +++ b/src/snyk/common/configuration/configuration.ts @@ -146,8 +146,8 @@ export class Configuration implements IConfiguration { } get snykCodeBaseURL(): string { - if (this.isDevelopment) { - return this.processEnv.SNYK_VSCE_DEVELOPMENT_SNYKCODE_BASE_URL ?? 'https://deeproxy.dev.snyk.io'; + if (this.processEnv.SNYK_VSCE_DEVELOPMENT_SNYKCODE_BASE_URL) { + return this.processEnv.SNYK_VSCE_DEVELOPMENT_SNYKCODE_BASE_URL; } else if (this.customEndpoint) { const url = new URL(this.customEndpoint); diff --git a/src/snyk/extension.ts b/src/snyk/extension.ts index 6e7e28974..71716fd2d 100644 --- a/src/snyk/extension.ts +++ b/src/snyk/extension.ts @@ -398,13 +398,13 @@ class SnykExtension extends SnykLib implements IExtension { // noinspection ES6MissingAwait void this.advisorScoreDisposable.activate(); - // Actually start analysis - this.runScan(); - // Wait for LS startup to finish before updating the codeEnabled context // The codeEnabled context depends on an LS command await this.languageServer.start(); await this.codeSettings.updateIsCodeEnabled(); + + // Actually start analysis + this.runScan(); } public async deactivate(): Promise { diff --git a/src/test/unit/common/configuration.test.ts b/src/test/unit/common/configuration.test.ts index 29783f385..456b5fb6f 100644 --- a/src/test/unit/common/configuration.test.ts +++ b/src/test/unit/common/configuration.test.ts @@ -61,13 +61,14 @@ suite('Configuration', () => { }); test('Snyk Code: development base url is returned when in development', () => { + const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, undefined); const configuration = new Configuration( { SNYK_VSCE_DEVELOPMENT: '1', }, - workspaceStub, + workspace, ); - strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.dev.snyk.io'); + strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.snyk.io'); }); test('Snyk Code: base url respects custom endpoint configuration', () => {