Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for xsoar 8/xsiam configuration #53

Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This will configure `.env` file with the following environment variables:
* DEMISTO_USERNAME (XSOAR username)
* DEMISTO_PASSWORD (XSOAR password)
* DEMISTO_API_KEY (XSOAR API key)
* XSIAM_AUTH_ID (XSOAR/XSIAM Auth ID) (Relevant for XSOAR 8/XSIAM)
* DEMISTO_VERIFY_SSL (Verify SSL in XSOAR, `true` or `false`)
## Configure XSOAR unit tests

Expand Down Expand Up @@ -86,7 +87,7 @@ If the `license/cla` status check remains on *Pending*, even though all contribu

* `npm install`
* `npm run compile`
* `pip demisto-sdk`
* `pip install demisto-sdk`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch


### Main Locations

Expand Down
44 changes: 42 additions & 2 deletions src/devEnvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import JSON5 from "json5";
import * as dsdk from "./demistoSDKWrapper";
import * as fs from "fs-extra";
import { spawn } from "child_process";
import { parse, stringify } from "envfile";
import { getContentPath } from "./tools";
import { getContentPath, parse, stringify } from "./tools";

enum Platform {
XSOAR6 = 'XSOAR 6',
XSOAR8_XSIAM = 'XSOAR 8/XSIAM'
}

export async function installDevEnv(): Promise<void> {
const workspaces = vscode.workspace.workspaceFolders;
Expand Down Expand Up @@ -239,6 +242,7 @@ export async function developDemistoSDK(): Promise<void> {

export async function configureDemistoVars(): Promise<void> {
const workspaces = vscode.workspace.workspaceFolders;

if (!workspaces) {
vscode.window.showErrorMessage("Could not find a valid workspace");
return;
Expand All @@ -256,6 +260,16 @@ export async function configureDemistoVars(): Promise<void> {
if (!env) {
env = {};
}

// Select configured platform
const configuredPlatform = await vscode.window
.showQuickPick([Platform.XSOAR6, Platform.XSOAR8_XSIAM], {
title: "Platform",
placeHolder: "Select configured platform",
ignoreFocusOut: true,
}) ?? Platform.XSOAR6;

// XSOAR url
await vscode.window
.showInputBox({
title: "XSOAR URL",
Expand All @@ -270,6 +284,8 @@ export async function configureDemistoVars(): Promise<void> {
vscode.window.showInformationMessage(
"Enter either XSOAR username and password, or an API key"
);

// XSOAR username
await vscode.window
.showInputBox({
title: "XSOAR username (optional)",
Expand All @@ -281,6 +297,8 @@ export async function configureDemistoVars(): Promise<void> {
env["DEMISTO_USERNAME"] = username;
}
});

// XSOAR password
await vscode.window
.showInputBox({
title: "XSOAR password (optional)",
Expand All @@ -294,6 +312,7 @@ export async function configureDemistoVars(): Promise<void> {
}
});

// XSOAR API Key
await vscode.window
.showInputBox({
title: "XSOAR API key (optional)",
Expand All @@ -306,10 +325,31 @@ export async function configureDemistoVars(): Promise<void> {
env["DEMISTO_API_KEY"] = apiKey;
}
});

// XSIAM Auth ID
if (configuredPlatform === Platform.XSOAR8_XSIAM){
await vscode.window
.showInputBox({
title: "XSIAM Auth ID",
ignoreFocusOut: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add ignorefocusout to all input boxes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}).then((authId) => {
if (authId){
env["XSIAM_AUTH_ID"] = authId;
}
})
} else {
// Commenting XSIAM_AUTH_ID if exist.
if (env["XSIAM_AUTH_ID"])
env["# XSIAM_AUTH_ID"] = `${env["XSIAM_AUTH_ID"]}`;
delete env["XSIAM_AUTH_ID"];
}

// Verify SSL
await vscode.window
.showQuickPick(["true", "false"], {
title: "XSOAR SSL verification",
placeHolder: "Should XSOAR SSL verification be enabled?",
ignoreFocusOut: true,
})
.then((verifySSL) => {
if (verifySSL) {
Expand Down
52 changes: 52 additions & 0 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,56 @@
});
</script>
`;
}

/** We don't normalize anything, so it is just strings and strings. */
export type Data = Record<string, string>

/** We typecast the value as a string so that it is compatible with envfiles. */
export type Input = Record<string, any>

Check warning on line 287 in src/tools.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type

/** Parse an envfile string. */
export function parse(src: string): Data {
const result: Data = {}
const lines = src.toString().split('\n')
let notHandleCount = 0
for (const [lineIndex, line] of lines.entries()) {
const match = line.match(/^([^=:#]+?)[=:](.*)/)
if (match) {
const key = match[1].trim()
const value = match[2].trim().replace(/['"]+/g, '')
result[key] = value
} else if ( line.trim().startsWith('#')) {
const sym = Symbol.for(`comment#${lineIndex - notHandleCount}`)
result[sym as any] = line

Check warning on line 302 in src/tools.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type
} else {
notHandleCount++
}
}
return result
}

/** Turn an object into an envfile string. */
export function stringify(obj: Input): string {
const result = []
for (const key of Reflect.ownKeys(obj)) {
const value = obj[key as string]
if (key) {
if (
typeof key === 'symbol' &&
(key as symbol).toString().startsWith('Symbol(comment')
) {

const [_, lineIndex] = (

Check warning on line 321 in src/tools.ts

View workflow job for this annotation

GitHub Actions / Test

'_' is assigned a value but never used
(key as symbol).description ?? 'comment#0'
).split('#')
result.splice(parseInt(lineIndex, 10), 0, value)

} else {
const line = `${key as string}=${String(value)}`
result.push(line)
}
}
}
return result.join('\n')
}
Loading