Skip to content

Commit 738a8c8

Browse files
authored
Merge pull request #607 from Checkmarx/other/benalvo/update-azure-with-runtime-wrapper-1
Azure Plugin | Update Azure Plugin to use JS-Wrapper-Runtime-CLI (AST-64802)
2 parents 48bb188 + 2a02415 commit 738a8c8

File tree

10 files changed

+1468
-50
lines changed

10 files changed

+1468
-50
lines changed

cxAstScan/package-lock.json

Lines changed: 1428 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cxAstScan/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
33
"azure-pipelines-task-lib": "4.10.1",
4-
"@checkmarxdev/ast-cli-javascript-wrapper": "v0.0.113-azure.0"
4+
"@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.2"
55
}
66
}

cxAstScan/services/CleanUpRunner.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as taskLib from "azure-pipelines-task-lib/task";
22
import {promises as fs} from 'fs';
3-
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper";
4-
import { getConfiguration, getLogFilename } from "./Utils";
3+
import {getConfiguration, getLogFilename} from "./Utils";
4+
import CxWrapperFactory from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxWrapperFactory";
55

66
export class CleanUpRunner {
7+
cxWrapperFactory= new CxWrapperFactory();
8+
79
async run() {
810
console.log("Getting job status");
911
const jobStatus = taskLib.getVariable('AGENT_JOBSTATUS');
@@ -15,16 +17,16 @@ export class CleanUpRunner {
1517
}
1618

1719
const cxScanConfig = getConfiguration();
18-
const wrapper = new CxWrapper(cxScanConfig);
20+
const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig);
1921
let data: string;
2022

2123
try {
2224
data = await fs.readFile(getLogFilename(), 'utf8')
2325
} catch (err: any) {
24-
if(err.code === 'ENOENT') {
26+
if (err.code === 'ENOENT') {
2527
console.log("Log file not created. Task ended successfully")
2628
taskLib.setResult(taskLib.TaskResult.Succeeded, "");
27-
} else if ( err.code === 'EACCES') {
29+
} else if (err.code === 'EACCES') {
2830
console.log('No permissions to read log file')
2931
taskLib.setResult(taskLib.TaskResult.Failed, "")
3032
} else {
@@ -57,9 +59,9 @@ export class CleanUpRunner {
5759
try {
5860
fs.unlink(getLogFilename())
5961
//file removed
60-
} catch(err) {
62+
} catch (err) {
6163
console.log("Unable to delete log file.", err)
62-
}
64+
}
6365

6466
}
6567

cxAstScan/services/TaskRunner.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as taskLib from "azure-pipelines-task-lib/task";
22
import * as path from "path"
3-
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper";
4-
import {CxCommandOutput} from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxCommandOutput";
5-
import {CxParamType} from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxParamType";
6-
import CxScan from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/scan/CxScan";
3+
import {CxWrapper} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli";
4+
import {CxCommandOutput} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxCommandOutput";
5+
import {CxParamType} from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxParamType";
6+
import CxScan from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/scan/CxScan";
77
import {getConfiguration, getLogFilename} from "./Utils";
8+
import CxWrapperFactory from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxWrapperFactory";
89

910
export class TaskRunner {
11+
cxWrapperFactory= new CxWrapperFactory();
1012

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

34-
const wrapper = new CxWrapper(cxScanConfig, getLogFilename());
36+
const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig, getLogFilename());
3537

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

cxAstScan/services/Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as taskLib from "azure-pipelines-task-lib/task";
2-
import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxConfig";
2+
import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli/dist/main/wrapper/CxConfig";
33
import * as path from "path"
44

55
export function getLogFilename(): string {

cxAstScan/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@
6767
}
6868
],
6969
"execution": {
70-
"Node10": {
70+
"Node16": {
7171
"target": "./dist/index.js"
7272
}
7373
},
7474
"postjobexecution": {
75-
"Node10": {
75+
"Node16": {
7676
"target": "./dist/cleanup.js"
7777
}
7878
},

cxAstScan/test/_suite.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import * as path from 'path';
22
import * as ttm from 'azure-pipelines-task-lib/mock-test';
33
import * as assert from 'assert';
44

5-
5+
const nodeVersion = 16;
66
describe('Task runner test', function () {
77

88

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

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

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

3939
console.log(tr.stdout)
4040
console.log(tr.stderr)
@@ -46,7 +46,7 @@ describe('Task runner test', function () {
4646
this.timeout(3000000);
4747
const tp = path.join(__dirname, 'failure_additional_params.js');
4848
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
49-
tr.run(10);
49+
tr.run(nodeVersion);
5050
console.log(tr.stdout)
5151
console.log(tr.stderr)
5252
assert.ok(tr.failed);
@@ -57,7 +57,7 @@ describe('Task runner test', function () {
5757
this.timeout(3000000);
5858
const tp = path.join(__dirname, 'failure_wrong_preset.js');
5959
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
60-
tr.run(10);
60+
tr.run(nodeVersion);
6161

6262
console.log(tr.stdout)
6363
console.log(tr.stderr)
@@ -69,7 +69,7 @@ describe('Task runner test', function () {
6969
this.timeout(3000000);
7070
const tp = path.join(__dirname, 'success_no_cancel.js');
7171
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
72-
tr.run();
72+
tr.run(nodeVersion);
7373
console.log(tr.succeeded);
7474
assert.strictEqual(tr.succeeded, true, 'should have succeeded');
7575
console.log(tr.stdout);
@@ -83,14 +83,14 @@ describe('Task runner test', function () {
8383
this.timeout(3000000);
8484
const scan = path.join(__dirname, 'success_nowait.js');
8585
const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan);
86-
scanTestRunner.run(10);
86+
scanTestRunner.run(nodeVersion);
8787
console.log(scanTestRunner.stdout)
8888
console.log(scanTestRunner.stderr)
8989
assert.ok(scanTestRunner.succeeded);
9090

9191
const tp = path.join(__dirname, 'success_cancel.js');
9292
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
93-
tr.run(10);
93+
tr.run(nodeVersion);
9494
console.log(tr.stdout);
9595
assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0,
9696
true,
@@ -102,7 +102,7 @@ describe('Task runner test', function () {
102102
this.timeout(3000000);
103103
const tp = path.join(__dirname, 'success_cancel.js');
104104
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
105-
tr.run(10);
105+
tr.run(nodeVersion);
106106
console.log(tr.stdout);
107107
assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0,
108108
true,

cxAstScan/tsconfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
3+
"target": "ES2015",
44
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
55
"outDir": "./dist" /* Redirect output structure to the directory. */,
66

@@ -14,6 +14,12 @@
1414

1515
/* Source Map Options */
1616
"inlineSourceMap": true /* Emit a single file with source maps instead of having a separate file. */,
17-
"inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
17+
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
18+
"declaration": true,
19+
"removeComments": false,
20+
"forceConsistentCasingInFileNames": true,
21+
"noUnusedLocals": true,
22+
"pretty": true,
23+
"allowSyntheticDefaultImports": true
1824
}
1925
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"repository": "https://github.com/checkmarx/ast-azure-plugin",
77
"engines": {
8-
"node": ">=10"
8+
"node": ">=16"
99
},
1010
"scripts": {
1111
"build": "tsc -b cxAstScan/tsconfig.json && tsc -b ui/enhancer/tsconfig.json",

0 commit comments

Comments
 (0)