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,24 @@ 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+ return tenantSettings ().stream ()
379+ .filter (t -> t .getKey ().equals (CxConstants .IDE_SCANS_KEY ))
380+ .findFirst ()
381+ .map (t -> Boolean .parseBoolean (t .getValue ()))
382+ .orElse (false );
383+ }
384+
385+ public List <TenantSetting > tenantSettings () throws CxException , IOException , InterruptedException {
386+ List <String > arguments = jsonArguments ();
387+
388+ arguments .add (CxConstants .CMD_UTILS );
389+ arguments .add (CxConstants .SUB_CMD_TENANT );
390+
391+ return Execution .executeCommand (withConfigArguments (arguments ), logger , TenantSetting ::listFromLine );
392392 }
393393
394394 private int getIndexOfBfLNode (List <Node > bflNodes , List <Node > resultNodes ) {
@@ -404,6 +404,22 @@ private int getIndexOfBfLNode(List<Node> bflNodes, List<Node> resultNodes) {
404404 return bflNodeNotFound ;
405405 }
406406
407+ public List <String > buildResultsArguments (@ NonNull UUID scanId , ReportFormat reportFormat ) {
408+ return withConfigArguments (buildResultsArgumentsArray (scanId , reportFormat ));
409+ }
410+
411+ private List <String > buildResultsArgumentsArray (UUID scanId , ReportFormat reportFormat ) {
412+ List <String > arguments = new ArrayList <>();
413+ arguments .add (CxConstants .CMD_RESULT );
414+ arguments .add (CxConstants .SUB_CMD_SHOW );
415+ arguments .add (CxConstants .SCAN_ID );
416+ arguments .add (scanId .toString ());
417+ arguments .add (CxConstants .REPORT_FORMAT );
418+ arguments .add (reportFormat .toString ());
419+
420+ return arguments ;
421+ }
422+
407423 private List <String > withConfigArguments (List <String > commands ) {
408424 List <String > arguments = new ArrayList <>();
409425
0 commit comments