Skip to content

Commit

Permalink
fix: default endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Jun 4, 2024
1 parent c1359ea commit 2c3d742
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
28 changes: 11 additions & 17 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface IConfiguration {

getAdditionalCliParameters(): string | undefined;

snykOssApiEndpoint: string;
snykApiEndpoint: string;
shouldShowOssBackgroundScanNotification: boolean;

hideOssBackgroundScanNotification(): Promise<void>;
Expand Down Expand Up @@ -126,8 +126,8 @@ export interface IConfiguration {
export class Configuration implements IConfiguration {
// These attributes are used in tests
private readonly defaultSnykCodeBaseURL = 'https://deeproxy.snyk.io';
private readonly defaultAuthHost = 'https://snyk.io';
private readonly defaultOssApiEndpoint = `${this.defaultAuthHost}/api/v1`;
private readonly defaultAuthHost = 'https://api.snyk.io';
private readonly defaultApiEndpoint = this.defaultAuthHost.replace('app', 'api') + '/v1';

private featureFlag: { [key: string]: boolean } = {};

Expand Down Expand Up @@ -171,13 +171,7 @@ export class Configuration implements IConfiguration {
return this.processEnv.SNYK_VSCE_DEVELOPMENT_SNYKCODE_BASE_URL;
} else if (this.customEndpoint) {
const url = new URL(this.customEndpoint);

if (Configuration.isSingleTenant(url)) {
url.host = url.host.replace('app', 'deeproxy');
} else {
url.host = `deeproxy.${url.host}`;
}
url.pathname = url.pathname.replace('api', '');
url.host = url.host.replace('api', 'deeproxy');

return this.removeTrailingSlash(url.toString());
}
Expand All @@ -195,6 +189,7 @@ export class Configuration implements IConfiguration {
get authHost(): string {
if (this.customEndpoint) {
const url = new URL(this.customEndpoint);
url.host = url.host.replace('api', 'app');
return `${url.protocol}//${url.host}`;
}

Expand Down Expand Up @@ -223,23 +218,26 @@ export class Configuration implements IConfiguration {
return `${hostnameParts[2]}.${hostnameParts[3]}`.includes('snykgov.io');
}

get snykOssApiEndpoint(): string {
get snykApiEndpoint(): string {
if (this.customEndpoint) {
return this.customEndpoint; // E.g. https://app.eu.snyk.io/api
return this.customEndpoint + '/v1';
}

return this.defaultOssApiEndpoint;
return this.defaultApiEndpoint;
}

get snykCodeUrl(): string {
const authUrl = new URL(this.authHost);
<<<<<<< HEAD

if (Configuration.isSingleTenant(authUrl)) {
authUrl.pathname = authUrl.pathname.replace('api', '');
} else {
authUrl.host = `app.${authUrl.host}`;
}

=======
>>>>>>> 8683425 (f)
return `${authUrl.toString()}manage/snyk-code?from=vscode`;
}

Expand Down Expand Up @@ -498,10 +496,6 @@ export class Configuration implements IConfiguration {

private getConfigName = (setting: string) => setting.replace(`${CONFIGURATION_IDENTIFIER}.`, '');

private static isSingleTenant(url: URL): boolean {
return url.host.startsWith('app') && url.host.endsWith('snyk.io');
}

private removeTrailingSlash(str: string) {
return str.replace(/\/$/, '');
}
Expand Down
2 changes: 1 addition & 1 deletion src/snyk/common/languageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class LanguageServerSettings {
activateSnykIac: `${iacEnabled}`,
sendErrorReports: `${configuration.shouldReportErrors}`,
cliPath: configuration.getCliPath(),
endpoint: configuration.snykOssApiEndpoint,
endpoint: configuration.snykApiEndpoint,
organization: configuration.organization,
token: await configuration.getToken(),
automaticAuthentication: 'false',
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ suite('Configuration', () => {

const configuration = new Configuration({}, workspace);

strictEqual(configuration.snykOssApiEndpoint, customEndpoint);
strictEqual(configuration.snykApiEndpoint, customEndpoint);
});

test('Preview features: not enabled', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/common/languageServer/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ suite('Language Server: Middleware', () => {
user = { anonymousId: 'anonymous-id' } as User;
configuration = {
shouldReportErrors: false,
snykOssApiEndpoint: 'https://dev.snyk.io/api',
snykApiEndpoint: 'https://dev.snyk.io/api',
getAdditionalCliParameters: () => '',
organization: 'org',
getToken: () => Promise.resolve('token'),
Expand Down Expand Up @@ -81,7 +81,7 @@ suite('Language Server: Middleware', () => {
assert.strictEqual(serverResult.activateSnykCodeQuality, 'true');
assert.strictEqual(serverResult.activateSnykOpenSource, 'false');
assert.strictEqual(serverResult.activateSnykIac, 'true');
assert.strictEqual(serverResult.endpoint, configuration.snykOssApiEndpoint);
assert.strictEqual(serverResult.endpoint, configuration.snykApiEndpoint);
assert.strictEqual(serverResult.additionalParams, configuration.getAdditionalCliParameters());
assert.strictEqual(serverResult.sendErrorReports, `${configuration.shouldReportErrors}`);
assert.strictEqual(serverResult.organization, `${configuration.organization}`);
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/common/languageServer/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ suite('LanguageServerSettings', () => {
const mockUser = { anonymousId: 'anonymous-id' } as User;
const mockConfiguration: IConfiguration = {
shouldReportErrors: false,
snykOssApiEndpoint: 'https://dev.snyk.io/api',
snykApiEndpoint: 'https://dev.snyk.io/api',
organization: 'my-org',
// eslint-disable-next-line @typescript-eslint/require-await
getToken: async () => 'snyk-token',
Expand Down

0 comments on commit 2c3d742

Please sign in to comment.