Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove url and authHost setting [ROAD-123] #20

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@
"description": "Toggle advanced tools for expert users",
"scope": "application"
},
"snyk.url": {
"type": "string",
"default": "",
"description": "In order to use custom Snyk API, update the instance url below:",
"scope": "application"
},
"snyk.authHost": {
"type": "string",
"default": "",
"description": "In order to use a custom Snyk authentication server, update the instance url below:",
"scope": "application"
},
"snyk.token": {
"type": "string",
"default": "",
Expand Down
4 changes: 1 addition & 3 deletions src/snyk/analytics/itly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ export class Iteratively {
return;
}

const userId = this.userId ?? '';

itly.welcomeIsViewed(
userId,
'',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fix for merge-itly-anonymous-user story, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavel-snyk i've just removed the redundant code because this.userId will never be set at this point, as this event is fired only when a user is not authenticated.

{
ide: this.ide,
},
Expand Down
21 changes: 7 additions & 14 deletions src/snyk/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { IDE_NAME } from './constants/general';
export interface IConfiguration {
isDevelopment: boolean;
source: string;
staticToken: string;
defaultBaseURL: string;
baseURL: string;
authHost: string;
termsConditionsUrl: string;
snykCodeUrl: string;
token: string | undefined;
setToken(token: string): Promise<void>;
Expand All @@ -22,30 +19,26 @@ export interface IConfiguration {

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

constructor(
private processEnv: NodeJS.ProcessEnv = process.env,
private vscodeWorkspace: typeof vscode.workspace = vscode.workspace,
) {}

get isDevelopment(): boolean {
return process.env.SNYK_VSCE_DEVELOPMENT ? true : false;
return !!process.env.SNYK_VSCE_DEVELOPMENT;
}

get baseURL(): string {
return this.vscodeWorkspace.getConfiguration('snyk').get('url') || this.defaultBaseURL;
return this.isDevelopment ? 'https://deeproxy.dev.snyk.io' : this.defaultBaseURL;
}

get authHost(): string {
return this.vscodeWorkspace.getConfiguration('snyk').get('authHost') || this.defaultAuthHost;
}

get termsConditionsUrl(): string {
return `${this.authHost}/policies/terms-of-service/?utm_source=${this.source}`; // todo: unused?
return this.isDevelopment ? 'https://dev.snyk.io' : this.defaultAuthHost;
}

get snykCodeUrl(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/snyk/lib/modules/ReportModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class ReportModule extends BaseSnykModule implements ReportModuleInterf
// return true;

// disabling request sending in dev mode or to self-managed instances.
return configuration.baseURL === configuration.defaultBaseURL || true;
return !configuration.isDevelopment;
}

resetTransientErrors(): void {
Expand Down
11 changes: 5 additions & 6 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import { ExtensionInterface } from '../../interfaces/SnykInterfaces';
import { configuration } from '../../snyk/configuration';

const testToken = '23';
const mockedTestFilesDirPath = __dirname.replace('out/test', 'src/test');
// const mockedTestFilesDirPath = __dirname.replace('out/test', 'src/test');
// const mockedFolderPath = vscode.Uri.parse('scheme:' + nodePath.join(mockedTestFilesDirPath, '/../mocked_data'), true)
// .fsPath;

// pre test configuring extension
const preTestConfigureExtension = () => {
const preTestConfigureExtension = async () => {
// pre-test extension changes before performing tests
const testExtension = extension.getExtension();

// set test token and backend host
configuration.staticCodeEnabled = true;
configuration.staticToken = testToken;
await configuration.setToken(testToken);

// // set workspace path for tests
// testExtension.workspacesPaths = [mockedFolderPath];
Expand All @@ -34,8 +33,8 @@ const preTestConfigureExtension = () => {

suite('Snyk Extension Tests', () => {
let testExtension: ExtensionInterface;
test('Pre-test configuring', () => {
testExtension = preTestConfigureExtension();
test('Pre-test configuring', async () => {
testExtension = await preTestConfigureExtension();
assert.equal(configuration.token, testToken);
assert.equal(configuration.baseURL, 'https://www.deepcoded.com');
// assert.equal(
Expand Down