-
Notifications
You must be signed in to change notification settings - Fork 0
/
devsecops_pipeline.py
64 lines (50 loc) · 1.78 KB
/
devsecops_pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import subprocess
import sys
# Helper function to run shell commands
def run_command(command, cwd=None):
result = subprocess.run(command, shell=True, cwd=cwd, text=True, capture_output=True)
if result.returncode != 0:
print(f"Error: Command '{command}' failed with exit code {result.returncode}")
print(result.stdout)
print(result.stderr)
sys.exit(result.returncode)
return result.stdout
# Static Code Analysis (using Bandit)
def run_bandit(path):
print("Running Bandit for static code analysis...")
run_command(f"bandit -r {path}")
# Dependency Checking (using Safety)
def run_safety():
print("Running Safety for dependency checking...")
run_command("safety check --full-report")
# Secret Scanning (using TruffleHog)
def run_trufflehog(path):
print("Running TruffleHog for secret scanning...")
run_command(f"trufflehog {path}")
# Infrastructure as Code Scanning (using Terraform and Snyk)
def run_terraform_scan(path):
print("Running Snyk for Terraform IaC scanning...")
run_command(f"snyk iac test {path}")
# Code Coverage and Linting (using Pylint)
def run_pylint(path):
print("Running Pylint for code linting...")
run_command(f"pylint {path}")
# Main function to orchestrate the DevSecOps pipeline
def main():
project_path = os.getcwd()
# Static Analysis
run_bandit(project_path)
# Dependency Checking
run_safety()
# Secret Scanning
run_trufflehog(project_path)
# Terraform IaC Scanning
terraform_path = os.path.join(project_path, 'terraform')
if os.path.exists(terraform_path):
run_terraform_scan(terraform_path)
# Linting
run_pylint(project_path)
print("DevSecOps pipeline completed successfully!")
if __name__ == "__main__":
main()