|
1 | 1 | /* eslint-disable @typescript-eslint/naming-convention */ |
2 | 2 | import { |
3 | 3 | SpawnOptionsWithoutStdio, |
4 | | - SpawnSyncOptionsWithStringEncoding, |
5 | | - SpawnSyncReturns, |
6 | 4 | spawn, |
7 | | - spawnSync, |
8 | 5 | } from "child_process"; |
9 | | -import { workspace, window, WebviewView } from "vscode"; |
| 6 | +import { window, WebviewView } from "vscode"; |
10 | 7 | import axios from 'axios'; |
11 | 8 | import { GGShieldConfiguration } from "./ggshield-configuration"; |
12 | 9 | import { GGShieldScanResults } from "./api-types"; |
13 | 10 | import * as os from "os"; |
14 | 11 | import { apiToDashboard, dasboardToApi } from "../utils"; |
| 12 | +import { runGGShieldCommand } from "./run-ggshield"; |
15 | 13 |
|
16 | | -/** |
17 | | - * Run ggshield CLI application with specified arguments |
18 | | - * |
19 | | - * @param configuration ggshield configuration |
20 | | - * @param args arguments |
21 | | - * @returns |
22 | | - */ |
23 | | -export function runGGShieldCommand( |
24 | | - configuration: GGShieldConfiguration, |
25 | | - args: string[] |
26 | | -): SpawnSyncReturns<string> { |
27 | | - const { ggshieldPath, apiUrl, apiKey } = configuration; |
28 | | - let env: { |
29 | | - GITGUARDIAN_API_URL: string; |
30 | | - GG_USER_AGENT: string; |
31 | | - GITGUARDIAN_DONT_LOAD_ENV: string; |
32 | | - GITGUARDIAN_API_KEY?: string; |
33 | | - } = { |
34 | | - GITGUARDIAN_API_URL: apiUrl, |
35 | | - GG_USER_AGENT: "gitguardian-vscode", |
36 | | - GITGUARDIAN_DONT_LOAD_ENV: "true", |
37 | | - }; |
38 | | - |
39 | | - if (apiKey) { |
40 | | - env = { |
41 | | - ...env, |
42 | | - // eslint-disable-next-line @typescript-eslint/naming-convention |
43 | | - GITGUARDIAN_API_KEY: apiKey, |
44 | | - }; |
45 | | - } |
46 | | - |
47 | | - let options: SpawnSyncOptionsWithStringEncoding = { |
48 | | - cwd: os.tmpdir(), |
49 | | - env: env, |
50 | | - encoding: "utf-8", |
51 | | - windowsHide: true, |
52 | | - }; |
53 | | - |
54 | | - // If the command is executed in a worskpace, execute ggshield from the root folder so .gitguardian.yaml is used |
55 | | - if (workspace.workspaceFolders?.length || 0 > 0) { |
56 | | - options["cwd"] = workspace.workspaceFolders![0].uri.fsPath; |
57 | | - } |
58 | | - let proc = spawnSync(ggshieldPath, args, options); |
59 | | - |
60 | | - return proc; |
61 | | -} |
62 | 14 |
|
63 | 15 | /** |
64 | 16 | * Display API quota |
|
0 commit comments