11
11
import com .checkmarx .ast .results .ResultsSummary ;
12
12
import com .checkmarx .ast .results .result .Node ;
13
13
import com .checkmarx .ast .scan .Scan ;
14
+ import com .checkmarx .ast .tenant .TenantSetting ;
14
15
import com .fasterxml .jackson .databind .ObjectMapper ;
15
16
import com .fasterxml .jackson .databind .type .CollectionType ;
16
17
import com .fasterxml .jackson .databind .type .TypeFactory ;
@@ -38,13 +39,11 @@ public class CxWrapper {
38
39
@ NonNull
39
40
private final String executable ;
40
41
41
- public CxWrapper (CxConfig cxConfig )
42
- throws CxConfig .InvalidCLIConfigException , IOException {
42
+ public CxWrapper (CxConfig cxConfig ) throws IOException {
43
43
this (cxConfig , LoggerFactory .getLogger (CxWrapper .class ));
44
44
}
45
45
46
- public CxWrapper (@ NonNull CxConfig cxConfig , @ NonNull Logger logger ) throws CxConfig .InvalidCLIConfigException ,
47
- IOException {
46
+ public CxWrapper (@ NonNull CxConfig cxConfig , @ NonNull Logger logger ) throws IOException {
48
47
this .cxConfig = cxConfig ;
49
48
this .logger = logger ;
50
49
this .executable = StringUtils .isBlank (this .cxConfig .getPathToExecutable ())
@@ -281,24 +280,9 @@ public String results(@NonNull UUID scanId, ReportFormat reportFormat)
281
280
fileName + reportFormat .getExtension ());
282
281
}
283
282
284
- public List <String > buildResultsArguments (@ NonNull UUID scanId , ReportFormat reportFormat ) {
285
- return withConfigArguments (buildResultsArgumentsArray (scanId , reportFormat ));
286
- }
287
-
288
- private List <String > buildResultsArgumentsArray (UUID scanId , ReportFormat reportFormat ) {
289
- List <String > arguments = new ArrayList <>();
290
- arguments .add (CxConstants .CMD_RESULT );
291
- arguments .add (CxConstants .SUB_CMD_SHOW );
292
- arguments .add (CxConstants .SCAN_ID );
293
- arguments .add (scanId .toString ());
294
- arguments .add (CxConstants .REPORT_FORMAT );
295
- arguments .add (reportFormat .toString ());
296
-
297
- return arguments ;
298
- }
299
-
300
283
public String scaRemediation (String packageFiles , String packages , String packageVersion ) throws CxException , IOException , InterruptedException {
301
284
List <String > arguments = new ArrayList <>();
285
+
302
286
arguments .add (CxConstants .CMD_UTILS );
303
287
arguments .add (CxConstants .CMD_REMEDIATION );
304
288
arguments .add (CxConstants .SUB_CMD_REMEDIATION_SCA );
@@ -347,8 +331,8 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String
347
331
arguments .add (CxConstants .ENGINE );
348
332
arguments .add (engine );
349
333
}
350
- KicsRealtimeResults kicsResults = Execution . executeCommand ( withConfigArguments ( arguments ), logger , KicsRealtimeResults :: fromLine );
351
- return kicsResults ;
334
+
335
+ return Execution . executeCommand ( withConfigArguments ( arguments ), logger , KicsRealtimeResults :: fromLine ) ;
352
336
}
353
337
354
338
public KicsRemediation kicsRemediate (@ NonNull String resultsFile , String kicsFile , String engine ,String similarityIds )
@@ -373,8 +357,8 @@ public KicsRemediation kicsRemediate(@NonNull String resultsFile, String kicsFil
373
357
arguments .add (CxConstants .KICS_REMEDIATION_SIMILARITY );
374
358
arguments .add (similarityIds );
375
359
}
376
- KicsRemediation remediation = Execution . executeCommand ( arguments , logger , KicsRemediation :: fromLine );
377
- return remediation ;
360
+
361
+ return Execution . executeCommand ( arguments , logger , KicsRemediation :: fromLine ) ;
378
362
}
379
363
380
364
public List <LearnMore > learnMore (String queryId ) throws CxException , IOException , InterruptedException {
@@ -387,8 +371,28 @@ public List<LearnMore> learnMore(String queryId) throws CxException, IOException
387
371
arguments .add (CxConstants .FORMAT );
388
372
arguments .add (CxConstants .FORMAT_JSON );
389
373
390
- List <LearnMore > learnMore = Execution .executeCommand (withConfigArguments (arguments ), logger , LearnMore ::listFromLine );
391
- return learnMore ;
374
+ return Execution .executeCommand (withConfigArguments (arguments ), logger , LearnMore ::listFromLine );
375
+ }
376
+
377
+ public boolean ideScansEnabled () throws CxException , IOException , InterruptedException {
378
+ List <TenantSetting > tenantSettings = tenantSettings ();
379
+ if (tenantSettings == null ) {
380
+ throw new CxException (1 , "Unable to parse tenant settings" );
381
+ }
382
+ return tenantSettings .stream ()
383
+ .filter (t -> t .getKey ().equals (CxConstants .IDE_SCANS_KEY ))
384
+ .findFirst ()
385
+ .map (t -> Boolean .parseBoolean (t .getValue ()))
386
+ .orElse (false );
387
+ }
388
+
389
+ public List <TenantSetting > tenantSettings () throws CxException , IOException , InterruptedException {
390
+ List <String > arguments = jsonArguments ();
391
+
392
+ arguments .add (CxConstants .CMD_UTILS );
393
+ arguments .add (CxConstants .SUB_CMD_TENANT );
394
+
395
+ return Execution .executeCommand (withConfigArguments (arguments ), logger , TenantSetting ::listFromLine );
392
396
}
393
397
394
398
private int getIndexOfBfLNode (List <Node > bflNodes , List <Node > resultNodes ) {
@@ -404,6 +408,22 @@ private int getIndexOfBfLNode(List<Node> bflNodes, List<Node> resultNodes) {
404
408
return bflNodeNotFound ;
405
409
}
406
410
411
+ public List <String > buildResultsArguments (@ NonNull UUID scanId , ReportFormat reportFormat ) {
412
+ return withConfigArguments (buildResultsArgumentsArray (scanId , reportFormat ));
413
+ }
414
+
415
+ private List <String > buildResultsArgumentsArray (UUID scanId , ReportFormat reportFormat ) {
416
+ List <String > arguments = new ArrayList <>();
417
+ arguments .add (CxConstants .CMD_RESULT );
418
+ arguments .add (CxConstants .SUB_CMD_SHOW );
419
+ arguments .add (CxConstants .SCAN_ID );
420
+ arguments .add (scanId .toString ());
421
+ arguments .add (CxConstants .REPORT_FORMAT );
422
+ arguments .add (reportFormat .toString ());
423
+
424
+ return arguments ;
425
+ }
426
+
407
427
private List <String > withConfigArguments (List <String > commands ) {
408
428
List <String > arguments = new ArrayList <>();
409
429
0 commit comments