@@ -27,10 +27,12 @@ export function runGGShieldCommand(
2727 let env : {
2828 GITGUARDIAN_API_URL : string ;
2929 GG_USER_AGENT : string ;
30+ GITGUARDIAN_DONT_LOAD_ENV : string ;
3031 GITGUARDIAN_API_KEY ?: string ; // Note the ? to indicate this property is optional
31- } = {
32+ } = {
3233 GITGUARDIAN_API_URL : apiUrl ,
3334 GG_USER_AGENT : "gitguardian-vscode" ,
35+ GITGUARDIAN_DONT_LOAD_ENV : "true" ,
3436 } ;
3537
3638 if ( apiKey ) {
@@ -43,6 +45,7 @@ export function runGGShieldCommand(
4345
4446 let options : SpawnSyncOptionsWithStringEncoding = {
4547 cwd : os . tmpdir ( ) ,
48+ env : env ,
4649 encoding : "utf-8" ,
4750 windowsHide : true ,
4851 } ;
@@ -273,6 +276,11 @@ export function ggshieldAuthStatus(
273276 }
274277}
275278
279+ /**
280+ * Get ggshield API key from ggshield config list
281+ *
282+ * Search for the correct instance section and return the token
283+ * */
276284export function ggshieldApiKey (
277285 configuration : GGShieldConfiguration ,
278286) : string | undefined {
@@ -292,8 +300,13 @@ export function ggshieldApiKey(
292300 const instanceSection = instanceSectionMatch [ 0 ] ;
293301 const regexToken = / t o k e n : \s ( [ a - z A - Z 0 - 9 ] + ) / ;
294302 const matchToken = instanceSection . match ( regexToken ) ;
303+
304+ // if the token is not found, or is not a valid token, return undefined
305+ if ( ! matchToken || matchToken [ 1 ] . trim ( ) . length !== 71 ) {
306+ return undefined ;
307+ }
295308
296- return matchToken ? matchToken [ 1 ] . trim ( ) : undefined ;
309+ return matchToken [ 1 ] . trim ( ) ;
297310 }
298311 }
299312}
0 commit comments