Skip to content

ADO | Add indicative msg to add Checkmarx download domain when request through proxy failed #44

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Each line is a file pattern followed by one or more owners

# Specify the default owners for the entire repository
* @OrShamirCM @AlvoBen @pedrompflopes
* @OrShamirCM @AlvoBen @pedrompflopes @miryamfoiferCX
4 changes: 2 additions & 2 deletions src/main/client/AstClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {logger} from '../wrapper/loggerConfig';
import * as fs from 'fs';
import {finished} from 'stream/promises';
import {Client} from "./Client";
import {CxError} from "../errors/CxError";

export class AstClient {
private client: Client;
Expand All @@ -20,10 +21,9 @@ export class AstClient {
logger.info(`Download completed successfully. File saved to: ${outputPath}`);
} catch (error) {
logger.error(`Error downloading file from ${url}: ${error.message || error}`);
throw error;
throw new CxError(error.message || error);
} finally {
writer.close();
logger.info('Write stream closed.');
}
}
}
4 changes: 4 additions & 0 deletions src/main/client/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Client} from "./Client";

export class HttpClient implements Client {
private readonly axiosConfig: AxiosRequestConfig;
private readonly domainErrMsg = 'Unable to download the CLI from the URL. Try adding the domain: \'download.checkmarx.com\' to your allow list.';

constructor() {
this.axiosConfig = {
Expand Down Expand Up @@ -45,6 +46,9 @@ export class HttpClient implements Client {
return response;
} catch (error) {
logger.error(`Error sending ${method} request to ${url}: ${error.message || error}`);
if (this.axiosConfig.proxy!==undefined) {
throw new Error(`${this.domainErrMsg} \nError: ${error.message || error}`);
}
throw error;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/errors/CxError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class CxError extends Error {
constructor(message: string) {
super(message);
this.name = "CxError";
}
}
6 changes: 5 additions & 1 deletion src/main/osinstaller/CxInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as tar from 'tar';
import * as unzipper from 'unzipper';
import {logger} from "../wrapper/loggerConfig";
import {AstClient} from "../client/AstClient";
import {CxError} from "../errors/CxError";

const linuxOS = 'linux';
const macOS = 'darwin';
Expand Down Expand Up @@ -41,7 +42,7 @@ export class CxInstaller {
const platformData = CxInstaller.PLATFORMS[this.platform];

if (!platformData) {
throw new Error('Unsupported platform or architecture');
throw new CxError('Unsupported platform or architecture');
}

const architecture = this.getArchitecture();
Expand Down Expand Up @@ -103,6 +104,9 @@ export class CxInstaller {
logger.info('Extracted CLI to:', this.resourceDirPath);
} catch (error) {
logger.error('Error during installation:', error);
if (error instanceof CxError) {
process.exit(1);
}
}
}

Expand Down