@@ -2,6 +2,7 @@ import * as path from "path";
22import * as fs from "fs" ;
33import * as tar from "tar" ;
44import axios , { AxiosRequestConfig } from "axios" ;
5+ import { Agent } from "https" ;
56
67const AdmZip = require ( "adm-zip" ) ;
78import { ExtensionContext , OutputChannel } from "vscode" ;
@@ -23,7 +24,8 @@ export async function getGGShield(
2324 platform : NodeJS . Platform ,
2425 arch : string ,
2526 context : ExtensionContext ,
26- outputChannel : OutputChannel
27+ outputChannel : OutputChannel ,
28+ ignoreSSLErrors : boolean
2729) : Promise < string > {
2830 const version = fs
2931 . readFileSync ( path . join ( context . extensionPath , "ggshield_version" ) , "utf8" )
@@ -54,7 +56,7 @@ export async function getGGShield(
5456 }
5557 fs . mkdirSync ( ggshieldFolder ) ;
5658 // install GGShield
57- await installGGShield ( platform , arch , ggshieldFolder , version ) ;
59+ await installGGShield ( platform , arch , ggshieldFolder , version , ignoreSSLErrors ) ;
5860 outputChannel . appendLine (
5961 `Updated to GGShield v${ version } . Checkout https://github.com/GitGuardian/ggshield for more info.`
6062 ) ;
@@ -132,7 +134,8 @@ export async function installGGShield(
132134 platform : NodeJS . Platform ,
133135 arch : string ,
134136 ggshieldFolder : string ,
135- version : string
137+ version : string ,
138+ ignoreSSLErrors : boolean ,
136139) : Promise < void > {
137140 let extension : string = "" ;
138141 switch ( platform ) {
@@ -153,7 +156,7 @@ export async function installGGShield(
153156 version
154157 ) } .${ extension } `;
155158 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 ) ;
157160 extractGGShieldBinary ( path . join ( ggshieldFolder , fileName ) , ggshieldFolder ) ;
158161}
159162
@@ -189,12 +192,21 @@ export function extractGGShieldBinary(
189192async function downloadGGShieldFromGitHub (
190193 fileName : string ,
191194 downloadUrl : string ,
192- ggshieldFolder : string
195+ ggshieldFolder : string ,
196+ ignoreSSLErrors : boolean
193197) : Promise < void > {
194198 console . log ( `Downloading GGShield from ${ downloadUrl } ` ) ;
199+
200+ const instance = ignoreSSLErrors
201+ ? new Agent ( {
202+ rejectUnauthorized : false ,
203+ } )
204+ : undefined ;
205+
195206 const { data } = await axios . get ( downloadUrl , {
196207 ...defaultRequestConfig ,
197- responseType : 'arraybuffer'
208+ responseType : 'arraybuffer' ,
209+ httpsAgent : instance
198210 } ) ;
199211
200212 fs . writeFileSync ( path . join ( ggshieldFolder , fileName ) , data ) ;
0 commit comments