|
| 1 | +import click |
| 2 | +from core import clone_repo, detect_malicious, scan_insecure, dependency_check, policy_config, report |
| 3 | + |
| 4 | +@click.command() |
| 5 | +@click.option("--repo", prompt="GitHub repository URL", help="URL of the GitHub repository") |
| 6 | +def main(repo): |
| 7 | + """Secure Source Code Scanner CLI.""" |
| 8 | + config = policy_config.load_policy("config.yaml") |
| 9 | + |
| 10 | + # Clone repository |
| 11 | + repo_dir = clone_repo.clone_repository(repo) |
| 12 | + if not repo_dir: |
| 13 | + click.echo("Failed to clone repository.") |
| 14 | + return |
| 15 | + |
| 16 | + # Scan repository for malicious code |
| 17 | + malicious_results = [] |
| 18 | + insecure_results = [] |
| 19 | + |
| 20 | + # Perform scans on each .py file |
| 21 | + for root, _, files in os.walk(repo_dir): |
| 22 | + for file in files: |
| 23 | + if file.endswith('.py'): |
| 24 | + file_path = os.path.join(root, file) |
| 25 | + malicious_results += detect_malicious.detect_malicious_patterns(file_path, config) |
| 26 | + insecure_results += scan_insecure.run_bandit_scan(file_path) |
| 27 | + |
| 28 | + # Check dependencies |
| 29 | + dependency_results = dependency_check.check_dependencies(repo_dir, config) |
| 30 | + |
| 31 | + # Generate report |
| 32 | + results = { |
| 33 | + "malicious": malicious_results, |
| 34 | + "insecure": insecure_results, |
| 35 | + "dependencies": dependency_results |
| 36 | + } |
| 37 | + report.generate_report(results, config) |
| 38 | + |
| 39 | + # Cleanup cloned repository |
| 40 | + clone_repo.cleanup_repository(repo_dir) |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + main() |
0 commit comments