Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/wrapper/CxConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export enum CxConstants {
SEVERITY_MEDIUM = "medium",
STATE_CONFIRMED = "confirmed",
CMD_LEARN_MORE = "learn-more",
IDE_SCANS_KEY = " scan.config.plugins.ideScans",
AI_GUIDED_REMEDIATION_KEY = " scan.config.plugins.aiGuidedRemediation",
IDE_SCANS_KEY = "scan.config.plugins.ideScans",
AI_GUIDED_REMEDIATION_KEY = "scan.config.plugins.aiGuidedRemediation",
AI_MCP_SERVER_KEY = "scan.config.plugins.aiMcpServer"

}
44 changes: 27 additions & 17 deletions src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as fs from "fs"
import * as os from "os";
import CxBFL from "../bfl/CxBFL";
import path = require('path');
import {getTrimmedMapValue} from "./utils";

type ParamTypeMap = Map<CxParamType, string>;

Expand Down Expand Up @@ -56,6 +57,7 @@ export class CxWrapper {
}
}


initializeCommands(formatRequired: boolean): string[] {
const list: string[] = [];
if (this.config.clientId) {
Expand Down Expand Up @@ -353,30 +355,38 @@ export class CxWrapper {
return exec.executeCommands(this.config.pathToExecutable, commands);
}

async ideScansEnabled() : Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));
const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
return output.has(CxConstants.IDE_SCANS_KEY) && output.get(CxConstants.IDE_SCANS_KEY).toLowerCase() === " true";
}
async ideScansEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));

async guidedRemediationEnabled() : Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));
const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
return output.has(CxConstants.AI_GUIDED_REMEDIATION_KEY) && output.get(CxConstants.AI_GUIDED_REMEDIATION_KEY).toLowerCase() === " true";
}
const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);

const value = getTrimmedMapValue(output, CxConstants.IDE_SCANS_KEY);
return value?.toLowerCase() === "true";
}

async aiMcpServerEnabled(): Promise<boolean> {
async guidedRemediationEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));

const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
return output.has(CxConstants.AI_MCP_SERVER_KEY) &&
output.get(CxConstants.AI_MCP_SERVER_KEY).toLowerCase() === "true";

const value = getTrimmedMapValue(output, CxConstants.AI_GUIDED_REMEDIATION_KEY);
return value?.toLowerCase() === "true";
}


async aiMcpServerEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));

const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);

const value = getTrimmedMapValue(output, CxConstants.AI_MCP_SERVER_KEY);
return value?.toLowerCase() === "true";
}

async kicsChat(apikey: string, file: string, line: number, severity: string, vulnerability: string, input: string, conversationId?: string, model?: string): Promise<CxCommandOutput> {
Expand Down
11 changes: 11 additions & 0 deletions src/main/wrapper/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function getTrimmedMapValue(map: Map<string, string>, targetKey: string): string | undefined {
const entries = Array.from(map.entries());

for (const [key, value] of entries) {
if (key.trim() === targetKey) {
return value.trim();
}
}

return undefined;
}
7 changes: 7 additions & 0 deletions src/tests/ScanTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ describe("ScanCreate cases", () => {
expect(aiEnabled).toBeDefined();
})

it("Should check if AI MCP server is active", async () => {
const cxScanConfig = new BaseTest();
const auth = new CxWrapper(cxScanConfig);
const aiMcpEnabled: boolean = await auth.aiMcpServerEnabled();
expect(typeof aiMcpEnabled).toBe("boolean");
});

it('ScanAsca fail case Without extensions', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/python-file");
Expand Down