Visual Studio Code Extension
The Cortex XSOAR extension for Visual Studio Code enables you to design and author scripts and integrations for Cortex XSOAR directly from VSCode. The extension adds a set of commands, as a sidebar with Automation and Integration Settings, just like the Settings sidebar in the Cortex XSOAR script editor. When writing code, the plugin provides you with auto-completion of Cortex XSOAR and Python functions. The extension also provides an easy-to-use set of demisto-sdk commands to format your packs, lint, and validate. The extension provides an easy virtual environment setup for Cortex XSOAR integrations and scripts.
#
Extension WorkflowThe extension defines a slightly different workflow than Cortex XSOAR. With the plugin, you can work on your code (whether it is Python, PowerShell or JavaScript). It utilizes the excellent demisto-sdk python package.
#
Prerequisites- Mac, Linux or WSL2 (on Windows)
- Python 3.8 and up.
- Docker (Follow the instructions here to install Docker to your operating system.)
- VSCode
#
Install the Visual Studio Code extensionInstall the Visual Studio Code extension directly from the Visual Studio Code marketplace or use this link.
If working on a Windows machine, click ctrl + shift + P
and choose Connect to WSL
.
#
ConfigurationsCortex XSOAR recommends configuring xsoar.autoFindProblems.readProblems.
This configuration will auto-run demisto-sdk lint and demisto-sdk validate when saving your file if the configuration is set to true.
The default is false, and for now, it is recommended not to enable this configuration for performance.
#
CommandsAll of the commands in the extension start with the easy-to-find pattern XSOAR.
Notable commands:
XSOAR: Demisto-SDK Pre-Commit/Validate/Update Release Notes...: Will run the demisto-sdk commands.
XSOAR: Configure XSOAR unit tests: Will configure the integration unit tests.
XSOAR: Configure Demisto-SDK for XSOAR: Will configure XSOAR environnement variables for demisto-sdk.
#
Environment setup#
Remote development (Any OS)To develop in a fully configured remote development environment, follow the instructions in this guide.
#
Local development (Linux, MacOS, WSL2)The VScode extension supports setting up your development environment automatically.
#
UsageExecute the command XSOAR: install local development environment, either from VSCode Command Pallete, or by right-clicking a file.
If you want to install the dependencies manually, follow the instructions in this guide until the Bootstrap
step.
#
Setup integrations and scripts environmentEach integration or script in Cortex XSOAR
runs on a different environment, and has different dependencies.
This feature will configure the integration or script, and will allow you to debug it easily and run unit tests.
In addition, you will be able to open the integration environment in a new workspace with a virtual environment, for autocompletion.
#
Usage- Go to the integration or a script.
- Right-click it, and select Setup integration/script environment
- There will be a popup asking you if you want to use the current workspace or open a new one with a virtual environment.
- Using the current workspace is quicker, but you may will not have autocompletion for some integrations.
- Opening a new workspace will take longer, but you will have autocompletion for all integrations.
- With both options, you will be able to debug your integration/script easily, run unit tests, and see problems in the IDE.
#
Debugging- First, Setup integrations and scripts environment
- Then, read the Debugging using your IDE section.
- Go to the Run and Debug (⇧⌘D), and make sure that
Docker: debug (<integration>)
is selected. - Click on the green arrow or F5 to start debugging.
#
Run and Debug tests- First, Setup integrations and scripts environment
- Go to the Run and Debug (⇧⌘D), and make sure that
Docker: debug tests (<integration>)
is selected. - Click on the green arrow or F5 to start debugging.
#
NotesIf during the installation one or more Python packages fail to install, the installation will proceed and create the virtual environment with the packages that were installed.
#
Python 2 supportVSCode dropped support for Python 2. In order to debug Python 2 code, it is necessary to install an older python extension.
- Go to VSCode extensions.
- Select Python.
- Select Install Another version.
- Select the version
2022.2.1924087327
.
#
Troubleshooting#
Setup integration/script environment fails- Make sure Docker is running.
- Make sure that
Allow the default Docker socket to be used (requires password)
is enabled in Docker advanced settings. - If Docker is running try to clean up Docker or sign in to Docker to avoid the Docker pull rate limit.