@@ -2,6 +2,7 @@ import * as path from "path";
2
2
import * as fs from "fs" ;
3
3
import * as tar from "tar" ;
4
4
import axios , { AxiosRequestConfig } from "axios" ;
5
+ import { Agent } from "https" ;
5
6
6
7
const AdmZip = require ( "adm-zip" ) ;
7
8
import { ExtensionContext , OutputChannel } from "vscode" ;
@@ -23,7 +24,8 @@ export async function getGGShield(
23
24
platform : NodeJS . Platform ,
24
25
arch : string ,
25
26
context : ExtensionContext ,
26
- outputChannel : OutputChannel
27
+ outputChannel : OutputChannel ,
28
+ ignoreSSLErrors : boolean
27
29
) : Promise < string > {
28
30
const version = fs
29
31
. readFileSync ( path . join ( context . extensionPath , "ggshield_version" ) , "utf8" )
@@ -54,7 +56,7 @@ export async function getGGShield(
54
56
}
55
57
fs . mkdirSync ( ggshieldFolder ) ;
56
58
// install GGShield
57
- await installGGShield ( platform , arch , ggshieldFolder , version ) ;
59
+ await installGGShield ( platform , arch , ggshieldFolder , version , ignoreSSLErrors ) ;
58
60
outputChannel . appendLine (
59
61
`Updated to GGShield v${ version } . Checkout https://github.com/GitGuardian/ggshield for more info.`
60
62
) ;
@@ -132,7 +134,8 @@ export async function installGGShield(
132
134
platform : NodeJS . Platform ,
133
135
arch : string ,
134
136
ggshieldFolder : string ,
135
- version : string
137
+ version : string ,
138
+ ignoreSSLErrors : boolean ,
136
139
) : Promise < void > {
137
140
let extension : string = "" ;
138
141
switch ( platform ) {
@@ -153,7 +156,7 @@ export async function installGGShield(
153
156
version
154
157
) } .${ extension } `;
155
158
const downloadUrl : string = `https://github.com/GitGuardian/ggshield/releases/download/v${ version } /${ fileName } ` ;
156
- await downloadGGShieldFromGitHub ( fileName , downloadUrl , ggshieldFolder ) ;
159
+ await downloadGGShieldFromGitHub ( fileName , downloadUrl , ggshieldFolder , ignoreSSLErrors ) ;
157
160
extractGGShieldBinary ( path . join ( ggshieldFolder , fileName ) , ggshieldFolder ) ;
158
161
}
159
162
@@ -189,12 +192,21 @@ export function extractGGShieldBinary(
189
192
async function downloadGGShieldFromGitHub (
190
193
fileName : string ,
191
194
downloadUrl : string ,
192
- ggshieldFolder : string
195
+ ggshieldFolder : string ,
196
+ ignoreSSLErrors : boolean
193
197
) : Promise < void > {
194
198
console . log ( `Downloading GGShield from ${ downloadUrl } ` ) ;
199
+
200
+ const instance = ignoreSSLErrors
201
+ ? new Agent ( {
202
+ rejectUnauthorized : false ,
203
+ } )
204
+ : undefined ;
205
+
195
206
const { data } = await axios . get ( downloadUrl , {
196
207
...defaultRequestConfig ,
197
- responseType : 'arraybuffer'
208
+ responseType : 'arraybuffer' ,
209
+ httpsAgent : instance
198
210
} ) ;
199
211
200
212
fs . writeFileSync ( path . join ( ggshieldFolder , fileName ) , data ) ;
0 commit comments