|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<unload unload_date="2023-12-05 10:05:24"> |
| 3 | +<sys_script_include action="INSERT_OR_UPDATE"> |
| 4 | +<access>package_private</access> |
| 5 | +<active>true</active> |
| 6 | +<api_name>x_chec3_chexone.CheckmarxOneDevOpsIntegration</api_name> |
| 7 | +<caller_access/> |
| 8 | +<client_callable>false</client_callable> |
| 9 | +<description>Integration script for DevOps and Checkmarx One integration to get scan summaries</description> |
| 10 | +<name>CheckmarxOneDevOpsIntegration</name> |
| 11 | +<script><![CDATA[var CheckmarxOneDevOpsIntegration = Class.create(); |
| 12 | +CheckmarxOneDevOpsIntegration.prototype = Object.extendsObject(sn_vul.DevOpsVulnerabilityIntegrationBase, { |
| 13 | + UTIL: new x_chec3_chexone.CheckmarxOneUtil(), |
| 14 | +
|
| 15 | + retrieveData: function() { |
| 16 | + try { |
| 17 | + var body = null; |
| 18 | + var processParams = this._getParameters(); |
| 19 | + processParams = this._validateAndUpdateParams(processParams); |
| 20 | +
|
| 21 | +
|
| 22 | + //validate scan status, if results are not ready defer it to next run |
| 23 | + if (processParams.scanId && processParams.scanStatus == "false") { |
| 24 | + this._updateDevOpsIntegrationRunState([processParams.sysId], 'new', 'success', gs.getMessage('Scan is still in progress, deferring to next run.')); |
| 25 | + return; |
| 26 | + } |
| 27 | +
|
| 28 | + var response = this.UTIL.getLastScanInfo(this.IMPLEMENTATION, processParams.appId, processParams.scanId); |
| 29 | + body = JSON.parse(response.getBody()); |
| 30 | +
|
| 31 | + if (gs.nil(body)) |
| 32 | + throw gs.getMessage("Invalid API response for process: {}", [this.PROCESS.getDisplayValue()]); |
| 33 | +
|
| 34 | +
|
| 35 | +
|
| 36 | + body.totalVulnerabilities = this.UTIL.getTotal_SAST_KICS_Vulcount(this.IMPLEMENTATION, body.id); |
| 37 | + body.Query = JSON.stringify(this.UTIL.processQueryData(this.IMPLEMENTATION, body.id)); |
| 38 | +
|
| 39 | +
|
| 40 | + var fileName = this.integrationGr.name + "_" + new GlideDateTime().toString() + ".json"; |
| 41 | + return { |
| 42 | + contents: new GlideSysAttachment().write(this.PROCESS, fileName, "json", JSON.stringify(body)), |
| 43 | + contentType: "sys_attachment", |
| 44 | + extension: "json" |
| 45 | + }; |
| 46 | + } catch (err) { |
| 47 | + gs.error(err); |
| 48 | + if (this.RUN_SYS_ID) { |
| 49 | + this._updateDevOpsIntegrationRunState([this.RUN_SYS_ID], 'complete', 'failed', err); |
| 50 | + } |
| 51 | + } |
| 52 | + }, |
| 53 | +
|
| 54 | + _validateAndUpdateParams: function(processParams) { |
| 55 | + var appId = processParams.projectId; |
| 56 | + var appName = processParams.projectName; |
| 57 | + var scanId = processParams.scanId; |
| 58 | +
|
| 59 | + if (gs.nil(appId) && gs.nil(appName)) { |
| 60 | + throw gs.getMessage('Missing application info for fetching Scan summary details of process: {0}', |
| 61 | + [this.PROCESS.getDisplayValue()]); |
| 62 | + } |
| 63 | +
|
| 64 | + var applicationInfo = this._fetchProjectInfo(appId, appName); |
| 65 | +
|
| 66 | + if (gs.nil(applicationInfo)) { |
| 67 | + throw gs.getMessage("Application Id not found for process: {0}.", [this.PROCESS.getDisplayValue()]); |
| 68 | + } |
| 69 | +
|
| 70 | + processParams.applicationId = appId = applicationInfo; |
| 71 | +
|
| 72 | + if (gs.nil(scanId)) { |
| 73 | + scanId = this._fetchScanId(appId); |
| 74 | + } |
| 75 | + if (!gs.nil(scanId)) { |
| 76 | + processParams.scanId = scanId; |
| 77 | + processParams.scanStatus = this._fetchScanStatus(appId, scanId); |
| 78 | + } |
| 79 | + return processParams; |
| 80 | + }, |
| 81 | +
|
| 82 | + _fetchProjectInfo: function(appId, appName) { |
| 83 | + var queryParams = {}; |
| 84 | + var projectId = ''; |
| 85 | + if (!gs.nil(appId)) { |
| 86 | + queryParams.app_id = appId; |
| 87 | + var responseByid = this.UTIL.getProjectById(this.IMPLEMENTATION, appId); |
| 88 | + projectId = responseByid.id.toString(); |
| 89 | +
|
| 90 | + } else if (!gs.nil(appName)) { |
| 91 | + queryParams.app_name = encodeURIComponent(appName); |
| 92 | + var responseByname = this.UTIL.getProjectByName(this.IMPLEMENTATION, queryParams.app_name); |
| 93 | + for (var item in responseByname.projects) { |
| 94 | + projectId = responseByname.projects[item].id; |
| 95 | + } |
| 96 | + } |
| 97 | + if (projectId.length == 0 || projectId == '') { |
| 98 | + throw gs.getMessage("Application details could not be found for the process: {0}", [this.PROCESS.getDisplayValue()]); |
| 99 | +
|
| 100 | +
|
| 101 | + } else { |
| 102 | + return projectId; |
| 103 | + } |
| 104 | +
|
| 105 | +
|
| 106 | + }, |
| 107 | +
|
| 108 | + _fetchScanId: function(appId) { |
| 109 | + var resp = this.UTIL.getLastScan(this.IMPLEMENTATION, appId); |
| 110 | + var jsonLastScanSummResp = JSON.parse(resp.getBody()); |
| 111 | +
|
| 112 | + if (jsonLastScanSummResp.scans) { |
| 113 | + for (var item in jsonLastScanSummResp.scans) { |
| 114 | + return jsonLastScanSummResp.scans[item].id; |
| 115 | + } |
| 116 | + } |
| 117 | + return null; |
| 118 | + }, |
| 119 | +
|
| 120 | +
|
| 121 | + _fetchScanStatus: function(appId, scanId) { |
| 122 | + var resp = this.UTIL.getLastScanInfo(this.IMPLEMENTATION, appId, scanId); |
| 123 | + var jsonLastScanSummResp = JSON.parse(resp.getBody()); |
| 124 | +
|
| 125 | + if (jsonLastScanSummResp.scans) { |
| 126 | + for (var item in jsonLastScanSummResp.scans) { |
| 127 | + return jsonLastScanSummResp.scans[item].status; |
| 128 | + } |
| 129 | + } |
| 130 | + return null; |
| 131 | + }, |
| 132 | +
|
| 133 | + type: 'CheckmarxOneDevOpsIntegration' |
| 134 | +});]]></script> |
| 135 | +<sys_class_name>sys_script_include</sys_class_name> |
| 136 | +<sys_created_by>admin</sys_created_by> |
| 137 | +<sys_created_on>2023-08-07 10:58:12</sys_created_on> |
| 138 | +<sys_id>f171708947e431108a980178c26d434f</sys_id> |
| 139 | +<sys_mod_count>37</sys_mod_count> |
| 140 | +<sys_name>CheckmarxOneDevOpsIntegration</sys_name> |
| 141 | +<sys_package display_value="Checkmarx One Vulnerability Integration" source="x_chec3_chexone">3d20e92d47471110328ca368436d436a</sys_package> |
| 142 | +<sys_policy>read</sys_policy> |
| 143 | +<sys_scope display_value="Checkmarx One Vulnerability Integration">3d20e92d47471110328ca368436d436a</sys_scope> |
| 144 | +<sys_update_name>sys_script_include_f171708947e431108a980178c26d434f</sys_update_name> |
| 145 | +<sys_updated_by>admin</sys_updated_by> |
| 146 | +<sys_updated_on>2023-11-09 09:55:09</sys_updated_on> |
| 147 | +</sys_script_include> |
| 148 | +</unload> |
0 commit comments