Skip to content

Commit c3b9fda

Browse files
authored
CM-27187 - Migrate to the new architecture that auto-manages the CLI (#74)
1 parent 06437e0 commit c3b9fda

26 files changed

+989
-412
lines changed

.vscodeignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
.vscode/**
22
.vscode-test/**
3+
.idea/**
4+
.github/**
35
out/**
46
node_modules/**
57
src/**
68
.gitignore
9+
.eslintignore
710
.yarnrc
811
webpack.config.js
9-
vsc-extension-quickstart.md
12+
*.md
1013
**/tsconfig.json
1114
**/.eslintrc.json
1215
**/*.map
1316
**/*.ts
17+
CODEOWNERS

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [v1.5.0]
4+
5+
- Migrate to the new architecture that auto-manages the CLI
6+
37
## [v1.4.0]
48

59
- Add the on-demand scan of an entire project for Secrets
@@ -38,6 +42,8 @@
3842

3943
The first stable release with the support of Secrets, SCA, TreeView, Violation Card, and more.
4044

45+
[v1.5.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.5.0
46+
4147
[v1.4.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.4.0
4248

4349
[v1.3.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.3.0

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/cycodehq/vscode-extension"
99
},
1010
"homepage": "https://cycode.com/",
11-
"version": "1.4.0",
11+
"version": "1.5.0",
1212
"publisher": "cycode",
1313
"engines": {
1414
"vscode": "^1.63.0"
@@ -84,11 +84,17 @@
8484
"title": "Cycode",
8585
"id": "cycode",
8686
"properties": {
87+
"cycode.cliAutoManaged": {
88+
"type": "boolean",
89+
"default": "true",
90+
"description": "Enable executable auto-management.",
91+
"markdownDescription": "Enable executable auto-management."
92+
},
8793
"cycode.cliPath": {
8894
"type": "string",
8995
"default": "",
90-
"description": "Path to the Cycode CLI executable. Run `which cycode` in your terminal to find the path.",
91-
"markdownDescription": "Path to the Cycode CLI executable. Run `which cycode` in your terminal to find the path."
96+
"description": "Path to the Cycode CLI executable.",
97+
"markdownDescription": "Path to the Cycode CLI executable."
9298
},
9399
"cycode.scanOnSave": {
94100
"type": "boolean",
@@ -218,6 +224,7 @@
218224
"test": "node ./out/test/runTest.js"
219225
},
220226
"devDependencies": {
227+
"@types/decompress": "^4.2.7",
221228
"@types/glob": "8.1.0",
222229
"@types/mocha": "10.0.1",
223230
"@types/node": "16.x",
@@ -238,6 +245,7 @@
238245
"webpack-cli": "5.0.1"
239246
},
240247
"dependencies": {
248+
"decompress": "^4.2.1",
241249
"semver": "7.5.4",
242250
"shelljs": "0.8.5",
243251
"showdown": "^2.1.0"

src/cli-wrapper/cli-wrapper.ts

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import * as vscode from 'vscode';
21
import {IgnoreCommandConfig} from '../types/commands';
32
import {CliCommands, CommandParameters, getScanTypeCliValue} from './constants';
43
import {IConfig, RunCliResult, UserAgent} from './types';
54
import {getRunnableCliCommand} from './runner';
6-
import {experimentalScaSyncFlowProperty, extensionId} from '../utils/texts';
75

8-
export const generateUserAgentCommandParam = (config: IConfig) => {
6+
const generateUserAgentCommandParam = (config: IConfig) => {
97
const userAgent: UserAgent = {
108
app_name: config.agentName,
119
app_version: config.agentVersion,
@@ -19,33 +17,22 @@ export const generateUserAgentCommandParam = (config: IConfig) => {
1917
};
2018

2119
export const cliWrapper = {
22-
getRunnableGetVersionLegacyCommand: (params: {
23-
config: IConfig;
24-
workspaceFolderPath: string;
25-
}): RunCliResult => {
26-
// support for legacy versions of the CLI (< 1.0.0)
27-
const {config, workspaceFolderPath} = params;
28-
const {cliPath, cliEnv} = config;
29-
30-
return getRunnableCliCommand({
31-
cliPath,
32-
workspaceFolderPath,
33-
commandParams: [CommandParameters.Version],
34-
cliEnv,
35-
printToOutput: true,
36-
});
37-
},
3820
getRunnableGetVersionCommand: (params: {
3921
config: IConfig;
4022
workspaceFolderPath?: string;
4123
}): RunCliResult => {
4224
const {config, workspaceFolderPath} = params;
4325
const {cliPath, cliEnv} = config;
4426

27+
const commandParams: string[] = [];
28+
commandParams.push(generateUserAgentCommandParam(config));
29+
commandParams.push(CommandParameters.OutputFormatJson);
30+
commandParams.push(CliCommands.Version);
31+
4532
return getRunnableCliCommand({
4633
cliPath,
4734
workspaceFolderPath,
48-
commandParams: [CliCommands.Version],
35+
commandParams,
4936
cliEnv,
5037
printToOutput: true,
5138
});
@@ -96,9 +83,7 @@ export const cliWrapper = {
9683
commandParams.push(CommandParameters.scanType);
9784
commandParams.push(CommandParameters.SCAScanType);
9885

99-
const experimentalScaSyncFlowPropertyEnabled =
100-
vscode.workspace.getConfiguration(extensionId).get(experimentalScaSyncFlowProperty);
101-
if (experimentalScaSyncFlowPropertyEnabled) {
86+
if (config.experimentalScaSyncFlow) {
10287
// TODO(MarshalX): remove experimental setting if stable
10388
commandParams.push(CommandParameters.Sync);
10489
commandParams.push(CommandParameters.NoRestore);
@@ -145,40 +130,6 @@ export const cliWrapper = {
145130

146131
return getRunnableCliCommand({cliPath, cliEnv, commandParams});
147132
},
148-
getRunnablePipInstallCommand: (params: {
149-
config: IConfig;
150-
workspaceFolderPath?: string;
151-
}): RunCliResult => {
152-
const commandParams: string[] = [];
153-
const {config, workspaceFolderPath} = params;
154-
const {cliEnv} = config;
155-
commandParams.push('install');
156-
commandParams.push('--upgrade');
157-
commandParams.push('cycode');
158-
159-
return getRunnableCliCommand({
160-
cliPath: 'pip',
161-
workspaceFolderPath,
162-
commandParams,
163-
cliEnv,
164-
printToOutput: true,
165-
});
166-
},
167-
getRunnablePipUninstallCommand: (params: {
168-
config: IConfig;
169-
workspaceFolderPath?: string;
170-
}): RunCliResult => {
171-
const {config, workspaceFolderPath} = params;
172-
const {cliEnv} = config;
173-
174-
return getRunnableCliCommand({
175-
cliPath: 'pip3',
176-
workspaceFolderPath,
177-
commandParams: ['uninstall', '-y', 'cycode'],
178-
cliEnv,
179-
printToOutput: true,
180-
});
181-
},
182133
getRunnableIgnoreCommand: (params: {
183134
config: IConfig;
184135
workspaceFolderPath?: string;

src/cli-wrapper/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export enum CommandParameters {
2424
NoRestore = '--no-restore',
2525
}
2626

27-
export const MinCLIVersion = '1.9.0';
28-
2927
const SCAN_TYPE_TO_SCAN_TYPE_CLI_FLAG_VALUE = {
3028
[ScanType.Secrets]: 'secret',
3129
[ScanType.Sca]: 'sca',

src/cli-wrapper/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ export type CommandResult = {
88

99
export interface IConfig {
1010
cliPath: string;
11+
cliAutoManaged: boolean;
1112
additionalParams: string[];
1213
cliEnv: { [key: string]: string };
1314
agentName: string;
1415
agentVersion: string;
1516
envName: string;
1617
envVersion: string;
18+
scanOnSaveEnabled: boolean;
19+
experimentalScaSyncFlow: boolean;
1720
}
1821

1922
export type CliConfig = {

src/constants.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as path from 'path';
2+
import {getContext} from './utils/context';
3+
14
// keep in lowercase.
25
// eslint-disable-next-line max-len
36
// source: https://github.com/cycodehq/cycode-cli/blob/ec8333707ab2590518fd0f36454c8636ccbf1061/cycode/cli/consts.py#L50-L82
@@ -56,7 +59,7 @@ const _SCA_CONFIGURATION_SCAN_LOCK_FILE_TO_PACKAGE_FILE: { [key: string]: string
5659
};
5760

5861
const _SCA_CONFIGURATION_SCAN_SUPPORTED_LOCK_FILES: ReadonlyArray<string> =
59-
Object.keys(_SCA_CONFIGURATION_SCAN_LOCK_FILE_TO_PACKAGE_FILE);
62+
Object.keys(_SCA_CONFIGURATION_SCAN_LOCK_FILE_TO_PACKAGE_FILE);
6063

6164
export const isSupportedPackageFile = (fileName: string): boolean => {
6265
const lowerCaseFileName = fileName.toLowerCase();
@@ -110,3 +113,30 @@ export const getScanTypeDisplayName = (scanType: string): string => {
110113
};
111114

112115
export const DIAGNOSTIC_CODE_SEPARATOR = '::';
116+
117+
export const REQUIRED_CLI_VERSION = '1.9.1';
118+
119+
export const CLI_GITHUB = {
120+
OWNER: 'cycodehq',
121+
REPO: 'cycode-cli',
122+
TAG: `v${REQUIRED_CLI_VERSION}`,
123+
};
124+
125+
export const CLI_CHECK_NEW_VERSION_EVERY_SEC = 24 * 60 * 60; // 24 hours
126+
127+
export const getPluginPath = (): string => {
128+
return path.join(getContext().extensionPath, 'cycode-vscode-extension');
129+
};
130+
131+
export const getDefaultCliPath = (): string => {
132+
if (process.platform === 'win32') {
133+
return path.join(getPluginPath(), 'cycode.exe');
134+
}
135+
136+
if (process.platform === 'darwin') {
137+
// on macOS, we are always using onedir mode because of gatekeeper
138+
return path.join(getPluginPath(), 'cycode-cli', 'cycode-cli');
139+
}
140+
141+
return path.join(getPluginPath(), 'cycode');
142+
};

0 commit comments

Comments
 (0)