Skip to content

Commit

Permalink
chore: disable snyk token
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Mar 21, 2024
1 parent 352c27e commit 5ecff49
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 53 deletions.
16 changes: 1 addition & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
"command": "rhda.stackLogs",
"title": "Debug logs",
"category": "Red Hat Dependency Analytics"
},
{
"command": "rhda.setSnykToken",
"title": "Set Snyk Token",
"category": "Red Hat Dependency Analytics"
}
],
"menus": {
Expand Down Expand Up @@ -173,15 +168,6 @@
"default": "off",
"description": "Traces the communication between VSCode and the Red Hat Dependency Analytics Language Server."
},
"redHatDependencyAnalytics.snykTokenStorage": {
"type": "string",
"enum": [
"Always use VS Code's secret storage"
],
"default": "Always use VS Code's secret storage",
"markdownDescription": "Red Hat Dependency Analytics uses VS Code's [secret storage](https://code.visualstudio.com/api/references/vscode-api#SecretStorage) to safely store the authentication token for Snyk. To set the token, run the VS Code command [RHDA: Set Snyk Token](command:rhda.setSnykToken).",
"scope": "window"
},
"redHatDependencyAnalytics.matchManifestVersions": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -318,4 +304,4 @@
"path": "^0.12.7",
"vscode-languageclient": "^8.1.0"
}
}
}
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class Config {
process.env['VSCEXT_EXHORT_PIP_PATH'] = this.exhortPipPath;
process.env['VSCEXT_TELEMETRY_ID'] = this.telemetryId;

const token = await this.getSnykToken();
process.env['VSCEXT_EXHORT_SNYK_TOKEN'] = token;
// const token = await this.getSnykToken();
// process.env['VSCEXT_EXHORT_SNYK_TOKEN'] = token;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/exhortServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function stackAnalysisService(pathToManifest, options): Promise<any> {
/**
* Performes RHDA token validation based on the provided options and displays messages based on the validation status.
* @param options The options for token validation.
* @param source The source for which the token is being validated. Example values: 'Snyk', 'OSS Index'.
* @param source The source for which the token is being validated.
* @returns A promise resolving after validating the token.
*/
async function tokenValidationService(options, source): Promise<string> {
Expand Down
56 changes: 28 additions & 28 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
} from 'vscode-languageclient/node';

import * as commands from './commands';
import { GlobalState, EXTENSION_QUALIFIED_ID, REDHAT_MAVEN_REPOSITORY, REDHAT_MAVEN_REPOSITORY_DOCUMENTATION_URL, SNYK_TOKEN_KEY } from './constants';
import { GlobalState, EXTENSION_QUALIFIED_ID, REDHAT_MAVEN_REPOSITORY, REDHAT_MAVEN_REPOSITORY_DOCUMENTATION_URL } from './constants';
import { generateRHDAReport } from './stackAnalysis';
import { globalConfig } from './config';
import { StatusMessages, PromptText } from './constants';
import { caStatusBarProvider } from './caStatusBarProvider';
import { CANotification } from './caNotification';
import { DepOutputChannel } from './depOutputChannel';
import { record, startUp, TelemetryActions } from './redhatTelemetry';
import { validateSnykToken } from './tokenValidation';
// import { validateSnykToken } from './tokenValidation';
import { applySettingNameMappings } from './utils';

let lspClient: LanguageClient;
Expand Down Expand Up @@ -75,25 +75,25 @@ export function activate(context: vscode.ExtensionContext) {
}
);

const disposableSetSnykToken = vscode.commands.registerCommand(
commands.SET_SNYK_TOKEN_COMMAND,
async () => {
const token = await vscode.window.showInputBox({
prompt: 'Please enter your Snyk Token:',
placeHolder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
password: true,
validateInput: validateSnykToken
});

if (token === undefined) {
return;
} else if (token === '') {
await globalConfig.clearSnykToken(true);
} else {
await globalConfig.setSnykToken(token);
}
}
);
// const disposableSetSnykToken = vscode.commands.registerCommand(
// commands.SET_SNYK_TOKEN_COMMAND,
// async () => {
// const token = await vscode.window.showInputBox({
// prompt: 'Please enter your Snyk Token:',
// placeHolder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// password: true,
// validateInput: validateSnykToken
// });

// if (token === undefined) {
// return;
// } else if (token === '') {
// await globalConfig.clearSnykToken(true);
// } else {
// await globalConfig.setSnykToken(token);
// }
// }
// );

registerStackAnalysisCommands(context);

Expand Down Expand Up @@ -178,7 +178,7 @@ export function activate(context: vscode.ExtensionContext) {
disposableStackAnalysisCommand,
disposableStackLogsCommand,
rhRepositoryRecommendationNotification,
disposableSetSnykToken,
// disposableSetSnykToken,
caStatusBarProvider,
);
})
Expand All @@ -191,12 +191,12 @@ export function activate(context: vscode.ExtensionContext) {
globalConfig.loadData();
});

context.secrets.onDidChange(async (e) => {
if (e.key === SNYK_TOKEN_KEY) {
const token = await globalConfig.getSnykToken();
lspClient.sendNotification('snykTokenModified', token);
}
});
// context.secrets.onDidChange(async (e) => {
// if (e.key === SNYK_TOKEN_KEY) {
// const token = await globalConfig.getSnykToken();
// lspClient.sendNotification('snykTokenModified', token);
// }
// });
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/stackAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ async function executeStackAnalysis(manifestFilePath): Promise<string> {
'EXHORT_PIP_PATH': globalConfig.exhortPipPath
};

const snykToken = await globalConfig.getSnykToken();
/* istanbul ignore else */
if (snykToken !== '') {
options['EXHORT_SNYK_TOKEN'] = snykToken;
}
// const snykToken = await globalConfig.getSnykToken();
// /* istanbul ignore else */
// if (snykToken !== '') {
// options['EXHORT_SNYK_TOKEN'] = snykToken;
// }

// execute stack analysis
await stackAnalysisService(manifestFilePath, options)
Expand Down
3 changes: 1 addition & 2 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ suite('Config module', () => {
expect(process.env['VSCEXT_STACK_ANALYSIS_COMMAND']).to.eq(commands.STACK_ANALYSIS_COMMAND);
expect(process.env['VSCEXT_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND']).to.eq(commands.REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND);
expect(process.env['VSCEXT_UTM_SOURCE']).to.eq(GlobalState.UTM_SOURCE);
expect(process.env['VSCEXT_EXHORT_SNYK_TOKEN']).to.eq('');
expect(process.env['VSCEXT_MATCH_MANIFEST_VERSIONS']).to.eq('true');
expect(process.env['VSCEXT_USE_PYTHON_VIRTUAL_ENVIRONMENT']).to.eq('false');
expect(process.env['VSCEXT_USE_GO_MVS']).to.eq('false');
Expand All @@ -81,7 +80,7 @@ suite('Config module', () => {
expect(process.env['VSCEXT_EXHORT_PYTHON_PATH']).to.eq('python');
expect(process.env['VSCEXT_EXHORT_PIP_PATH']).to.eq('pip');
expect(process.env['VSCEXT_TELEMETRY_ID']).to.equal(mockId);
expect(process.env['VSCEXT_EXHORT_SNYK_TOKEN']).to.equal('');
// expect(process.env['VSCEXT_EXHORT_SNYK_TOKEN']).to.equal('');
});

test('should set Snyk token in VSCode SecretStorage', async () => {
Expand Down

0 comments on commit 5ecff49

Please sign in to comment.