1111import com .checkmarx .ast .results .ResultsSummary ;
1212import com .checkmarx .ast .results .result .Node ;
1313import com .checkmarx .ast .scan .Scan ;
14+ import com .checkmarx .ast .tenant .TenantSetting ;
1415import com .fasterxml .jackson .databind .ObjectMapper ;
1516import com .fasterxml .jackson .databind .type .CollectionType ;
1617import com .fasterxml .jackson .databind .type .TypeFactory ;
@@ -38,13 +39,11 @@ public class CxWrapper {
3839 @ NonNull
3940 private final String executable ;
4041
41- public CxWrapper (CxConfig cxConfig )
42- throws CxConfig .InvalidCLIConfigException , IOException {
42+ public CxWrapper (CxConfig cxConfig ) throws IOException {
4343 this (cxConfig , LoggerFactory .getLogger (CxWrapper .class ));
4444 }
4545
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 {
4847 this .cxConfig = cxConfig ;
4948 this .logger = logger ;
5049 this .executable = StringUtils .isBlank (this .cxConfig .getPathToExecutable ())
@@ -281,24 +280,9 @@ public String results(@NonNull UUID scanId, ReportFormat reportFormat)
281280 fileName + reportFormat .getExtension ());
282281 }
283282
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-
300283 public String scaRemediation (String packageFiles , String packages , String packageVersion ) throws CxException , IOException , InterruptedException {
301284 List <String > arguments = new ArrayList <>();
285+
302286 arguments .add (CxConstants .CMD_UTILS );
303287 arguments .add (CxConstants .CMD_REMEDIATION );
304288 arguments .add (CxConstants .SUB_CMD_REMEDIATION_SCA );
@@ -347,8 +331,8 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String
347331 arguments .add (CxConstants .ENGINE );
348332 arguments .add (engine );
349333 }
350- KicsRealtimeResults kicsResults = Execution . executeCommand ( withConfigArguments ( arguments ), logger , KicsRealtimeResults :: fromLine );
351- return kicsResults ;
334+
335+ return Execution . executeCommand ( withConfigArguments ( arguments ), logger , KicsRealtimeResults :: fromLine ) ;
352336 }
353337
354338 public KicsRemediation kicsRemediate (@ NonNull String resultsFile , String kicsFile , String engine ,String similarityIds )
@@ -373,8 +357,8 @@ public KicsRemediation kicsRemediate(@NonNull String resultsFile, String kicsFil
373357 arguments .add (CxConstants .KICS_REMEDIATION_SIMILARITY );
374358 arguments .add (similarityIds );
375359 }
376- KicsRemediation remediation = Execution . executeCommand ( arguments , logger , KicsRemediation :: fromLine );
377- return remediation ;
360+
361+ return Execution . executeCommand ( arguments , logger , KicsRemediation :: fromLine ) ;
378362 }
379363
380364 public List <LearnMore > learnMore (String queryId ) throws CxException , IOException , InterruptedException {
@@ -387,8 +371,28 @@ public List<LearnMore> learnMore(String queryId) throws CxException, IOException
387371 arguments .add (CxConstants .FORMAT );
388372 arguments .add (CxConstants .FORMAT_JSON );
389373
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 );
392396 }
393397
394398 private int getIndexOfBfLNode (List <Node > bflNodes , List <Node > resultNodes ) {
@@ -404,6 +408,22 @@ private int getIndexOfBfLNode(List<Node> bflNodes, List<Node> resultNodes) {
404408 return bflNodeNotFound ;
405409 }
406410
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+
407427 private List <String > withConfigArguments (List <String > commands ) {
408428 List <String > arguments = new ArrayList <>();
409429
0 commit comments