forked from CheckmarxDev/ast-cli-javascript-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 1
AzureDevops | Add Seamless Proxy Ability (AST-67328) #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
abbc713
change test execution to be synchronized
BenAlvo1 418a7cc
add cliInstalledVersion
BenAlvo1 b2a16cb
add proxy support
BenAlvo1 5ee1481
implemented httpClient and Client interface. Added arm support for li…
BenAlvo1 9e55956
refactor getArchitecture
BenAlvo1 f1896dd
refactor
BenAlvo1 0ff7ac8
add tupe to client feild in CxInstaller.ts
BenAlvo1 70caeb6
remove unnecessary log
BenAlvo1 39b7de9
refactor
BenAlvo1 0163621
Added unit tests
BenAlvo1 e919b62
update test
BenAlvo1 914f9ff
fix tests
BenAlvo1 520dba8
added astClient
BenAlvo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {logger} from '../wrapper/loggerConfig'; | ||
import * as fs from 'fs'; | ||
import {finished} from 'stream/promises'; | ||
import {Client} from "./Client"; | ||
|
||
export class AstClient { | ||
private client: Client; | ||
|
||
constructor(client: Client) { | ||
this.client = client; | ||
} | ||
|
||
public async downloadFile(url: string, outputPath: string): Promise<void> { | ||
logger.info(`Starting download from URL: ${url}`); | ||
const writer = fs.createWriteStream(outputPath); | ||
try { | ||
const response = await this.client.request(url, 'GET', null); | ||
response.data.pipe(writer); | ||
await finished(writer); | ||
logger.info(`Download completed successfully. File saved to: ${outputPath}`); | ||
} catch (error) { | ||
logger.error(`Error downloading file from ${url}: ${error.message || error}`); | ||
throw error; | ||
} finally { | ||
writer.close(); | ||
logger.info('Write stream closed.'); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {AxiosResponse} from "axios"; | ||
|
||
export interface Client { | ||
getProxyConfig(): any; | ||
request(url: string, method: string, data: any): Promise<AxiosResponse<any, any>>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import axios, {AxiosRequestConfig, AxiosResponse} from 'axios'; | ||
import {logger} from '../wrapper/loggerConfig'; | ||
import {Client} from "./Client"; | ||
|
||
export class HttpClient implements Client { | ||
private readonly axiosConfig: AxiosRequestConfig; | ||
|
||
constructor() { | ||
this.axiosConfig = { | ||
responseType: 'stream', | ||
proxy: this.getProxyConfig(), | ||
}; | ||
} | ||
|
||
public getProxyConfig() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to save this value to avoid parsing the URL every time it’s called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's being call once every httpClient object creation |
||
const proxyUrl = process.env.HTTP_PROXY; | ||
if (proxyUrl) { | ||
logger.info(`Detected proxy configuration in HTTP_PROXY`); | ||
const parsedProxy = new URL(proxyUrl); | ||
|
||
return { | ||
host: parsedProxy.hostname, | ||
port: parseInt(parsedProxy.port, 10), | ||
protocol: parsedProxy.protocol.replace(':', ''), // remove the colon | ||
auth: parsedProxy.username && parsedProxy.password | ||
? {username: parsedProxy.username, password: parsedProxy.password} | ||
: undefined, | ||
}; | ||
} | ||
logger.info('No proxy configuration detected.'); | ||
return undefined; | ||
} | ||
|
||
public async request(url: string, method: string, data: any): Promise<AxiosResponse<any, any>> { | ||
logger.info(`Sending ${method} request to URL: ${url}`); | ||
if (this.axiosConfig.proxy) { | ||
logger.info( | ||
`Using proxy - Host: ${this.axiosConfig.proxy.host}, Port: ${this.axiosConfig.proxy.port},` + | ||
`Protocol: ${this.axiosConfig.proxy.protocol}, Auth: ${this.axiosConfig.proxy.auth ? 'Yes' : 'No'}` | ||
); | ||
} | ||
try { | ||
const response = await axios({...this.axiosConfig, url, method, data}); | ||
logger.info(`Request completed successfully.`); | ||
return response; | ||
} catch (error) { | ||
logger.error(`Error sending ${method} request to ${url}: ${error.message || error}`); | ||
throw error; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the naming convention in TS is without "I" for interfaces. I believe it needs to be IClient ( that says that it's an interface)