Skip to content

Commit

Permalink
chore: minor startup improvement (#368)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
PeterSchafer authored Aug 7, 2023
1 parent 85aee48 commit b902bb4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/snyk/base/modules/snykLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { ISnykLib } from './interfaces';

export default class SnykLib extends BaseSnykModule implements ISnykLib {
private async runFullScan_(manual = false): Promise<void> {
// 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);

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

Expand Down
2 changes: 1 addition & 1 deletion src/snyk/common/commands/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class CommandController {
async initiateLogin(): Promise<void> {
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<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/snyk/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
5 changes: 3 additions & 2 deletions src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit b902bb4

Please sign in to comment.