@@ -2,7 +2,7 @@ import * as fsPromises from 'fs/promises';
22import * as fs from 'fs' ;
33import * as path from 'path' ;
44import * as tar from 'tar' ;
5- import axios from 'axios' ;
5+ import axios , { AxiosRequestConfig } from 'axios' ;
66import * as unzipper from 'unzipper' ;
77import { logger } from "../wrapper/loggerConfig" ;
88import { finished } from 'stream/promises' ;
@@ -57,7 +57,7 @@ export class CxInstaller {
5757 return ;
5858 }
5959 }
60-
60+
6161 await this . cleanDirectoryContents ( this . resourceDirPath ) ;
6262 const url = await this . getDownloadURL ( ) ;
6363 const zipPath = path . join ( this . resourceDirPath , this . getCompressFolderName ( ) ) ;
@@ -92,7 +92,7 @@ export class CxInstaller {
9292 const fileStat = await fsPromises . stat ( filePath ) ;
9393
9494 if ( fileStat . isDirectory ( ) ) {
95- await fsPromises . rm ( filePath , { recursive : true , force : true } ) ;
95+ await fsPromises . rm ( filePath , { recursive : true , force : true } ) ;
9696 logger . info ( `Directory ${ filePath } deleted.` ) ;
9797 } else {
9898 await fsPromises . unlink ( filePath ) ;
@@ -148,22 +148,58 @@ export class CxInstaller {
148148 }
149149
150150 private async downloadFile ( url : string , outputPath : string ) {
151- logger . info ( 'Downloading file from:' , url ) ;
151+ logger . info ( `Starting download from URL: ${ url } ` ) ;
152152 const writer = fs . createWriteStream ( outputPath ) ;
153153
154154 try {
155- const response = await axios ( { url, responseType : 'stream' } ) ;
155+ // Create base Axios configuration
156+ const axiosConfig : AxiosRequestConfig = {
157+ url,
158+ responseType : 'stream' ,
159+ } ;
160+
161+ // Configure proxy if HTTP_PROXY environment variable is set
162+ const proxyUrl = process . env . HTTP_PROXY ;
163+ if ( proxyUrl ) {
164+ logger . info ( `Detected proxy configuration in HTTP_PROXY` ) ;
165+ const parsedProxy = new URL ( proxyUrl ) ;
166+
167+ axiosConfig . proxy = {
168+ host : parsedProxy . hostname ,
169+ port : parseInt ( parsedProxy . port , 10 ) ,
170+ protocol : parsedProxy . protocol . replace ( ':' , '' ) , // remove the colon
171+ auth : parsedProxy . username && parsedProxy . password
172+ ? { username : parsedProxy . username , password : parsedProxy . password }
173+ : undefined , // Only include auth if credentials are provided
174+ } ;
175+
176+ logger . info (
177+ `Using proxy - Host: ${ axiosConfig . proxy . host } , Port: ${ axiosConfig . proxy . port } , ` +
178+ `Protocol: ${ axiosConfig . proxy . protocol } , Auth: ${ axiosConfig . proxy . auth ? 'Yes' : 'No' } `
179+ ) ;
180+ } else {
181+ logger . info ( 'No proxy configuration detected.' ) ;
182+ }
183+
184+ // Perform the download request
185+ logger . info ( `Initiating download request to: ${ url } ` ) ;
186+ const response = await axios ( axiosConfig ) ;
187+
188+ // Pipe the response data to the output file
156189 response . data . pipe ( writer ) ;
157190
158- await finished ( writer ) ; // Use stream promises to await the writer
159- logger . info ( 'Download finished' ) ;
191+ // Await the completion of the write stream
192+ await finished ( writer ) ;
193+ logger . info ( `Download completed successfully. File saved to: ${ outputPath } ` ) ;
160194 } catch ( error ) {
161- logger . error ( ' Error downloading file:' , error . message || error ) ;
195+ logger . error ( ` Error downloading file from ${ url } : ${ error . message || error } ` ) ;
162196 } finally {
163197 writer . close ( ) ;
198+ logger . info ( 'Write stream closed.' ) ;
164199 }
165200 }
166-
201+
202+
167203 private checkExecutableExists ( ) : boolean {
168204 return fs . existsSync ( this . getExecutablePath ( ) ) ;
169205 }
@@ -183,7 +219,7 @@ export class CxInstaller {
183219 }
184220
185221 private getVersionFilePath ( ) : string {
186- return path . join ( __dirname , '../../../checkmarx-ast-cli.version' ) ;
222+ return path . join ( __dirname , '../../../checkmarx-ast-cli.version' ) ;
187223 }
188224
189225 private getCompressFolderName ( ) : string {
0 commit comments