Skip to content

Commit 863b1cc

Browse files
- Merged Iac fixes in ignore changes
2 parents fc72964 + 1c24aa9 commit 863b1cc

5 files changed

Lines changed: 61 additions & 19 deletions

File tree

checkmarx-ast-cli.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.42
1+
2.3.42-iac-engine-fallbackPath

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@
3131

3232
import java.io.IOException;
3333
import java.nio.file.Files;
34-
import java.util.ArrayList;
35-
import java.util.List;
36-
import java.util.Map;
37-
import java.util.UUID;
34+
import java.util.*;
35+
36+
import static com.checkmarx.ast.wrapper.Execution.*;
3837

3938
public class CxWrapper {
4039

4140
private static final CollectionType BRANCHES_TYPE = TypeFactory.defaultInstance()
4241
.constructCollectionType(List.class, String.class);
42+
private static final String OS_LINUX = "linux";
43+
private static final String OS_WINDOWS = "windows";
44+
private static final String OS_MAC = "mac";
4345

4446
@NonNull
4547
private final CxConfig cxConfig;
@@ -413,6 +415,49 @@ public KicsRealtimeResults kicsRealtimeScan(@NonNull String fileSources, String
413415
return Execution.executeCommand(withConfigArguments(arguments), logger, KicsRealtimeResults::fromLine);
414416
}
415417

418+
public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser)
419+
public String checkEngineExist(@NonNull String engineName) throws CxException, IOException, InterruptedException {
420+
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
421+
String osType=Execution.getOperatingSystemType(osName);
422+
return this.checkEngine(engineName,osType);
423+
}
424+
425+
private String checkEngine(String engineName, String osType ) throws CxException, IOException, InterruptedException {
426+
List<String> arguments = new ArrayList<>();
427+
switch (osType){
428+
case OS_MAC:
429+
String enginePath;
430+
arguments.add("/bin/sh");
431+
arguments.add("-c");
432+
arguments.add("command -v " + engineName);
433+
try{
434+
enginePath= Execution.executeCommand((arguments), logger, line->line);
435+
}
436+
throw new CxException(
437+
1,
438+
"Engine '" + engineName + "' is not installed or not found at /usr/local/bin)."
439+
);
440+
441+
442+
return enginePath;
443+
case OS_WINDOWS:
444+
case OS_LINUX:
445+
arguments.add(engineName);
446+
arguments.add("--version");
447+
try {
448+
Execution.executeCommand(arguments, logger, line -> line);
449+
return engineName;
450+
} catch (CxException | IOException e) {
451+
throw new CxException(
452+
1,engineName+" is not installed or is not accessible from the system PATH."
453+
);
454+
}
455+
default:
456+
throw new IllegalArgumentException("Unsupported OS: " + osType);
457+
}
458+
459+
}
460+
416461
public <T> T realtimeScan(@NonNull String subCommand, @NonNull String sourcePath, String containerTool, String ignoredFilePath, java.util.function.Function<String, T> resultParser)
417462
throws IOException, InterruptedException, CxException {
418463
this.logger.info("Executing 'scan {}' command using the CLI.", subCommand);

src/main/java/com/checkmarx/ast/wrapper/Execution.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.checkmarx.ast.wrapper;
22

3+
import com.checkmarx.ast.kicsRealtimeResults.KicsRealtimeResults;
34
import lombok.NonNull;
45
import org.slf4j.Logger;
56

@@ -12,10 +13,7 @@
1213
import java.nio.file.Paths;
1314
import java.security.MessageDigest;
1415
import java.security.NoSuchAlgorithmException;
15-
import java.util.Arrays;
16-
import java.util.List;
17-
import java.util.Locale;
18-
import java.util.Objects;
16+
import java.util.*;
1917
import java.util.function.BiFunction;
2018
import java.util.function.Function;
2119

@@ -171,7 +169,7 @@ private static String detectBinaryName(@NonNull Logger logger) {
171169
return fileName;
172170
}
173171

174-
private static String getOperatingSystemType(String osName) {
172+
public static String getOperatingSystemType(String osName) {
175173
if (osName.contains(OS_LINUX)) {
176174
return OS_LINUX;
177175
} else if (osName.contains(OS_WINDOWS)) {
@@ -217,4 +215,6 @@ private static String md5(InputStream a) {
217215
}
218216
return md5;
219217
}
218+
219+
220220
}

src/main/resources/cx.exe

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/java/com/checkmarx/ast/TelemetryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersAiLog() throws CxExc
1616
// Test case: AI logging with specific parameters and some empty values
1717
Assertions.assertDoesNotThrow(() -> {
1818
String result = wrapper.telemetryAIEvent(
19-
"Copilot", // aiProvider
20-
"JetBrains IntelliJ IDEA", // agent
19+
"Cursor", // aiProvider
20+
"Cursos", // agent
2121
"click", // eventType
22-
"viewDetails", // subType
22+
"ast-results.viewPackageDetails", // subType
2323
"secrets", // engine
2424
"high", // problemSeverity
2525
"", // scanType (empty)
@@ -34,7 +34,7 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersDetectionLog() throw
3434
// Test case: Detection logging with most parameters empty and specific scan data
3535
Assertions.assertDoesNotThrow(() -> {
3636
String result = wrapper.telemetryAIEvent(
37-
"", // aiProvider (empty)
37+
"", // aiProvider (empty)
3838
"", // agent (empty)
3939
"", // eventType (empty)
4040
"", // subType (empty)
@@ -52,7 +52,7 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
5252
// Test case: Edge case with minimal required parameters
5353
Assertions.assertDoesNotThrow(() -> {
5454
String result = wrapper.telemetryAIEvent(
55-
"test-provider", // aiProvider (minimal value)
55+
"test-provider", // aiProvider (minimal value)
5656
"java-wrapper", // agent (minimal value)
5757
"", // eventType (empty)
5858
"", // subType (empty)
@@ -64,4 +64,4 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
6464
);
6565
}, "Telemetry AI event should execute successfully for edge case");
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)