Skip to main content

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 Workflow#

The 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 extension#

Install 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.

Configurations#

Cortex 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.

Commands#

All of the commands in the extension start with the easy-to-find pattern XSOAR.
Notable commands:

  • XSOAR: Demisto-SDK Lint/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.

Usage#

Execute 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 environment#

Each 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#

Run and Debug tests#

Notes#

If 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 support#

VSCode 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. Python
  • Select Install Another version.
  • Select the version 2022.2.1924087327. Version

Troubleshooting#

Setup integration/script environment fails#

Last updated on