|
29 | 29 | import org.slf4j.Logger; |
30 | 30 | import org.slf4j.LoggerFactory; |
31 | 31 |
|
32 | | -import java.io.File; |
33 | 32 | import java.io.IOException; |
34 | 33 | import java.nio.file.Files; |
35 | 34 | import java.nio.file.Path; |
36 | 35 | import java.nio.file.Paths; |
37 | 36 | import java.util.*; |
38 | 37 |
|
39 | | -import static com.checkmarx.ast.wrapper.Execution.*; |
40 | 38 |
|
41 | 39 | public class CxWrapper { |
42 | 40 |
|
@@ -170,12 +168,46 @@ public List<Predicate> triageShow(@NonNull UUID projectId, String similarityId, |
170 | 168 | arguments.add(similarityId); |
171 | 169 | arguments.add(CxConstants.SCAN_TYPE); |
172 | 170 | arguments.add(scanType); |
173 | | - |
174 | 171 | arguments.addAll(jsonArguments()); |
175 | 172 |
|
176 | 173 | return Execution.executeCommand(withConfigArguments(arguments), logger, Predicate::listFromLine, Predicate::validator); |
177 | 174 | } |
178 | 175 |
|
| 176 | + /** |
| 177 | + * SCA-specific triage show command. |
| 178 | + */ |
| 179 | + public List<Predicate> triageScaShow(@NonNull UUID projectId, String vulnerabilities, String scanType) |
| 180 | + throws IOException, InterruptedException, CxException { |
| 181 | + this.logger.info("Executing 'triage show' command using the CLI for SCA."); |
| 182 | + |
| 183 | + if (StringUtils.isBlank(vulnerabilities)) { |
| 184 | + this.logger.warn("Skipping SCA triage show: no vulnerability identifiers were provided."); |
| 185 | + return Collections.emptyList(); |
| 186 | + } |
| 187 | + |
| 188 | + List<String> arguments = new ArrayList<>(); |
| 189 | + arguments.add(CxConstants.CMD_TRIAGE); |
| 190 | + arguments.add(CxConstants.SUB_CMD_SHOW); |
| 191 | + arguments.add(CxConstants.SCAN_TYPE); |
| 192 | + arguments.add(scanType); |
| 193 | + arguments.add(CxConstants.VULNERABILITY_IDENTIFIERS); |
| 194 | + arguments.add(vulnerabilities); |
| 195 | + arguments.add(CxConstants.PROJECT_ID); |
| 196 | + arguments.add(projectId.toString()); |
| 197 | + arguments.addAll(jsonArguments()); |
| 198 | + |
| 199 | + try { |
| 200 | + return Execution.executeCommand(withConfigArguments(arguments), logger, Predicate::listFromLine, Predicate::validator); |
| 201 | + } catch (CxException e) { |
| 202 | + String message = e.getMessage(); |
| 203 | + if (message != null && message.contains("Failed to get SCA predicate result")) { |
| 204 | + this.logger.info("No SCA triage history found for vulnerability identifiers: {}", vulnerabilities); |
| 205 | + return Collections.emptyList(); |
| 206 | + } |
| 207 | + throw e; |
| 208 | + } |
| 209 | + } |
| 210 | + |
179 | 211 | public List<CustomState> triageGetStates(boolean all) throws IOException, InterruptedException, CxException { |
180 | 212 | this.logger.info("Executing 'triage get-states' command using the CLI."); |
181 | 213 |
|
@@ -224,6 +256,39 @@ public void triageUpdate(@NonNull UUID projectId, String similarityId, String sc |
224 | 256 | Execution.executeCommand(withConfigArguments(arguments), logger, line -> null); |
225 | 257 | } |
226 | 258 |
|
| 259 | + /** |
| 260 | + * SCA-specific triage update command. |
| 261 | + */ |
| 262 | + public void triageScaUpdate(@NonNull UUID projectId, |
| 263 | + String state, |
| 264 | + String comment, |
| 265 | + String vulnerabilities, |
| 266 | + String scanType) |
| 267 | + throws IOException, InterruptedException, CxException { |
| 268 | + this.logger.info("Executing 'triage update' command using the CLI for SCA."); |
| 269 | + |
| 270 | + if (StringUtils.isBlank(vulnerabilities)) { |
| 271 | + this.logger.warn("Skipping SCA triage update: no vulnerability identifiers were provided."); |
| 272 | + return; |
| 273 | + } |
| 274 | + |
| 275 | + List<String> arguments = new ArrayList<>(); |
| 276 | + arguments.add(CxConstants.CMD_TRIAGE); |
| 277 | + arguments.add(CxConstants.SUB_CMD_UPDATE); |
| 278 | + arguments.add(CxConstants.SCAN_TYPE); |
| 279 | + arguments.add(scanType); |
| 280 | + arguments.add(CxConstants.VULNERABILITY_IDENTIFIERS); |
| 281 | + arguments.add(vulnerabilities); |
| 282 | + arguments.add(CxConstants.STATE); |
| 283 | + arguments.add(state); |
| 284 | + arguments.add(CxConstants.COMMENT); |
| 285 | + arguments.add(comment); |
| 286 | + arguments.add(CxConstants.PROJECT_ID); |
| 287 | + arguments.add(projectId.toString()); |
| 288 | + |
| 289 | + Execution.executeCommand(withConfigArguments(arguments), logger, line -> null); |
| 290 | + } |
| 291 | + |
227 | 292 | public Project projectShow(@NonNull UUID projectId) throws IOException, InterruptedException, CxException { |
228 | 293 | this.logger.info("Retrieving the details for project id: {}", projectId); |
229 | 294 |
|
|
0 commit comments