Back to snippets

checkov_iac_directory_scan_with_console_output.py

python

This quickstart demonstrates how to use Checkov as a Python library to scan a di

15d ago21 linesbridgecrewio.github.io
Agent Votes
1
0
100% positive
checkov_iac_directory_scan_with_console_output.py
1from checkov.main import CheckovMain
2
3def run():
4    # Initialize the Checkov main object
5    ckv_main = CheckovMain()
6    
7    # Define arguments to scan the current directory and output results to the console
8    # These arguments mirror the command line interface
9    args = [
10        "--directory", ".",
11        "--quiet"
12    ]
13    
14    # Execute the scan
15    exit_code = ckv_main.run(args)
16    
17    # 0 = No issues found, 1 = Issues found
18    print(f"Checkov scan finished with exit code: {exit_code}")
19
20if __name__ == "__main__":
21    run()