Linting - Developer Guide - Cortex XSIAM - Cortex - Security Operations

Cortex XSIAM Developer Guide

Product
Cortex XSIAM
Creation date
2023-05-01
Last date published
2024-06-04
Category
Developer Guide
Abstract

Run linters to catch common programming errors, stylistic errors, and possible security issues

As part of the build process, we run linters to catch common programming errors, stylistic errors, and possible security issues. Linters are run only when working with the package (directory) structure.

All linters are run via the demisto-sdk lint command.

Note

This script is also used to run pytest. See: Unit Testing

An example of the result from running lint checks on the HelloWorld package:

➜  content git:(master) ✗ demisto-sdk lint -i Packs/HelloWorld/Integrations/HelloWorld
Execute lint and test on 1/1 packages
HelloWorld - Facts - Using yaml file /home/sb/dev/demisto/content/Packs/HelloWorld/Integrations/HelloWorld/HelloWorld.yml
HelloWorld - Facts - Pulling docker images, can take up to 1-2 minutes if not exists locally 
HelloWorld - Facts - demisto/python3:3.8.2.6981 - Python 3.8
HelloWorld - Facts - Tests found
HelloWorld - Facts - Lint file /home/sb/dev/demisto/content/Packs/HelloWorld/Integrations/HelloWorld/HelloWorld_test.py
HelloWorld - Facts - Lint file /home/sb/dev/demisto/content/Packs/HelloWorld/Integrations/HelloWorld/HelloWorld.py
HelloWorld - Flake8 - Start
HelloWorld - Flake8 - Successfully finished
HelloWorld - XSOAR Linter - Start
HelloWorld - XSOAR Linter - Successfully finished
HelloWorld - Bandit - Start
HelloWorld - Bandit - Successfully finished
HelloWorld - Mypy - Start
HelloWorld - Mypy - Successfully finished
HelloWorld - Vulture - Start
HelloWorld - Vulture - Successfully finished
HelloWorld - Flake8 - Start
HelloWorld - Flake8 - Successfully finished
HelloWorld - Image create - Trying to pull existing image devtestdemisto/python3:3.8.2.6981-02b43abe979132c89892e089d5b8254d
HelloWorld - Image create - Found existing image devtestdemisto/python3:3.8.2.6981-02b43abe979132c89892e089d5b8254d
HelloWorld - Image create - Copy pack dir to image devtestdemisto/python3:3.8.2.6981-02b43abe979132c89892e089d5b8254d
HelloWorld - Image create - Image sha256:ba9f6ede55 created successfully
HelloWorld - Pylint - Image sha256:ba9f6ede55 - Start
HelloWorld - Pylint - Image sha256:ba9f6ede55 - exit-code: 0
HelloWorld - Pylint - Image sha256:ba9f6ede55 - Successfully finished
HelloWorld - Pytest - Image sha256:ba9f6ede55 - Start
        ============================= test session starts ==============================
        platform linux -- Python 3.8.2, pytest-5.0.1, py-1.8.1, pluggy-0.13.1
        rootdir: /devwork
        plugins: json-0.4.0, forked-1.1.3, mock-2.0.0, asyncio-0.10.0, datadir-ng-1.1.1, requests-mock-1.7.0, xdist-1.31.0
        collected 10 items

        HelloWorld_test.py ..........                                            [100%]

        -------------- generated json report: /devwork/report_pytest.json --------------
        ========================== 10 passed in 0.43 seconds ===========================
HelloWorld - Pytest - Image sha256:ba9f6ede55 - exit-code: 0
HelloWorld - Pytest - Image sha256:ba9f6ede55 - Successfully finished
Flake8       - [PASS]
XSOAR linter - [PASS]
Bandit       - [PASS]
Mypy         - [PASS]
Vulture      - [PASS]
Pytest       - [PASS]
Pylint       - [PASS]
Pwsh analyze - [SKIPPED]
Pwsh test    - [SKIPPED]

Passed Unit-tests:
  - Package: HelloWorld
      - Image: demisto/python3:3.8.2.6981
         - HelloWorld_test.py::test_say_hello
         - HelloWorld_test.py::test_start_scan
         - HelloWorld_test.py::test_status_scan
         - HelloWorld_test.py::test_scan_results
         - HelloWorld_test.py::test_search_alerts
         - HelloWorld_test.py::test_get_alert
         - HelloWorld_test.py::test_update_alert_status
         - HelloWorld_test.py::test_ip
         - HelloWorld_test.py::test_domain
         - HelloWorld_test.py::test_fetch_incidents

#########
 Summary 
#########
Packages: 1
Packages PASS: 1
Packages FAIL: 0
Packages WARNING (can either PASS or FAIL): 0

[INFO] 

############################
 unit-tests coverage report
############################
Name                                                     Stmts   Miss  Cover
----------------------------------------------------------------------------
Packs/HelloWorld/Integrations/HelloWorld/HelloWorld.py     277     83    70%
----------------------------------------------------------------------------
TOTAL                                                      277     83    70%