Skip to content

Commit

Permalink
Merge pull request #607 from Checkmarx/other/benalvo/update-azure-wit…
Browse files Browse the repository at this point in the history
…h-runtime-wrapper-1

Azure Plugin | Update Azure Plugin to use JS-Wrapper-Runtime-CLI (AST-64802)
  • Loading branch information
AlvoBen authored Oct 8, 2024
2 parents 48bb188 + 2a02415 commit 738a8c8
Show file tree
Hide file tree
Showing 10 changed files with 1,468 additions and 50 deletions.
1,448 changes: 1,428 additions & 20 deletions cxAstScan/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cxAstScan/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"azure-pipelines-task-lib": "4.10.1",
"@checkmarxdev/ast-cli-javascript-wrapper": "v0.0.113-azure.0"
"@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.2"
}
}
16 changes: 9 additions & 7 deletions cxAstScan/services/CleanUpRunner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as taskLib from "azure-pipelines-task-lib/task";
import {promises as fs} from 'fs';
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper";
import { getConfiguration, getLogFilename } from "./Utils";
import {getConfiguration, getLogFilename} from "./Utils";
import CxWrapperFactory from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxWrapperFactory";

export class CleanUpRunner {
cxWrapperFactory= new CxWrapperFactory();

async run() {
console.log("Getting job status");
const jobStatus = taskLib.getVariable('AGENT_JOBSTATUS');
Expand All @@ -15,16 +17,16 @@ export class CleanUpRunner {
}

const cxScanConfig = getConfiguration();
const wrapper = new CxWrapper(cxScanConfig);
const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig);
let data: string;

try {
data = await fs.readFile(getLogFilename(), 'utf8')
} catch (err: any) {
if(err.code === 'ENOENT') {
if (err.code === 'ENOENT') {
console.log("Log file not created. Task ended successfully")
taskLib.setResult(taskLib.TaskResult.Succeeded, "");
} else if ( err.code === 'EACCES') {
} else if (err.code === 'EACCES') {
console.log('No permissions to read log file')
taskLib.setResult(taskLib.TaskResult.Failed, "")
} else {
Expand Down Expand Up @@ -57,9 +59,9 @@ export class CleanUpRunner {
try {
fs.unlink(getLogFilename())
//file removed
} catch(err) {
} catch (err) {
console.log("Unable to delete log file.", err)
}
}

}

Expand Down
12 changes: 7 additions & 5 deletions cxAstScan/services/TaskRunner.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as taskLib from "azure-pipelines-task-lib/task";
import * as path from "path"
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper";
import {CxCommandOutput} from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxCommandOutput";
import {CxParamType} from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxParamType";
import CxScan from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/scan/CxScan";
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli";
import {CxCommandOutput} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxCommandOutput";
import {CxParamType} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxParamType";
import CxScan from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/scan/CxScan";
import {getConfiguration, getLogFilename} from "./Utils";
import CxWrapperFactory from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxWrapperFactory";

export class TaskRunner {
cxWrapperFactory= new CxWrapperFactory();

async run() {
const cxScanConfig = getConfiguration();
Expand All @@ -31,7 +33,7 @@ export class TaskRunner {
try {
//Write to file to test if possible to read from file in cleanup post execution event

const wrapper = new CxWrapper(cxScanConfig, getLogFilename());
const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig, getLogFilename());

const cxCommandOutput: CxCommandOutput = await wrapper.scanCreate(params);

Expand Down
2 changes: 1 addition & 1 deletion cxAstScan/services/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as taskLib from "azure-pipelines-task-lib/task";
import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxConfig";
import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxConfig";
import * as path from "path"

export function getLogFilename(): string {
Expand Down
4 changes: 2 additions & 2 deletions cxAstScan/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
}
],
"execution": {
"Node10": {
"Node16": {
"target": "./dist/index.js"
}
},
"postjobexecution": {
"Node10": {
"Node16": {
"target": "./dist/cleanup.js"
}
},
Expand Down
20 changes: 10 additions & 10 deletions cxAstScan/test/_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as path from 'path';
import * as ttm from 'azure-pipelines-task-lib/mock-test';
import * as assert from 'assert';


const nodeVersion = 16;
describe('Task runner test', function () {


it('should be success with api key', function (done) {
this.timeout(3000000);
const tp = path.join(__dirname, 'success_api_key.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);

console.log(tr.stdout)
console.log(tr.stderr)
Expand All @@ -22,7 +22,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'success_waitmode.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);

console.log(tr.stdout)
console.log(tr.stderr)
Expand All @@ -34,7 +34,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'success_nowait.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);

console.log(tr.stdout)
console.log(tr.stderr)
Expand All @@ -46,7 +46,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'failure_additional_params.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);
console.log(tr.stdout)
console.log(tr.stderr)
assert.ok(tr.failed);
Expand All @@ -57,7 +57,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'failure_wrong_preset.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);

console.log(tr.stdout)
console.log(tr.stderr)
Expand All @@ -69,7 +69,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'success_no_cancel.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
tr.run(nodeVersion);
console.log(tr.succeeded);
assert.strictEqual(tr.succeeded, true, 'should have succeeded');
console.log(tr.stdout);
Expand All @@ -83,14 +83,14 @@ describe('Task runner test', function () {
this.timeout(3000000);
const scan = path.join(__dirname, 'success_nowait.js');
const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan);
scanTestRunner.run(10);
scanTestRunner.run(nodeVersion);
console.log(scanTestRunner.stdout)
console.log(scanTestRunner.stderr)
assert.ok(scanTestRunner.succeeded);

const tp = path.join(__dirname, 'success_cancel.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);
console.log(tr.stdout);
assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0,
true,
Expand All @@ -102,7 +102,7 @@ describe('Task runner test', function () {
this.timeout(3000000);
const tp = path.join(__dirname, 'success_cancel.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run(10);
tr.run(nodeVersion);
console.log(tr.stdout);
assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0,
true,
Expand Down
10 changes: 8 additions & 2 deletions cxAstScan/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "ES2015",
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,

Expand All @@ -14,6 +14,12 @@

/* Source Map Options */
"inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
"inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
"declaration": true,
"removeComments": false,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": true,
"pretty": true,
"allowSyntheticDefaultImports": true
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"repository": "https://github.com/checkmarx/ast-azure-plugin",
"engines": {
"node": ">=10"
"node": ">=16"
},
"scripts": {
"build": "tsc -b cxAstScan/tsconfig.json && tsc -b ui/enhancer/tsconfig.json",
Expand Down

0 comments on commit 738a8c8

Please sign in to comment.