import { Command } from 'commander'; import { BaseCommand } from './BaseCommand'; import { ScanSecurityUseCaseImpl } from '../../domain/usecases/ScanSecurityUseCase'; export class SecurityScanCommand extends BaseCommand { constructor() { super('security-scan', 'Scan code for security vulnerabilities'); this.option('--severity ', 'Security severity levels (low,medium,high,critical)') .option('--categories ', 'Security categories (injection,authentication,authorization,cryptography,data_exposure,input_validation,dependency,configuration,logging,other)') .option('--include-dependencies', 'Include dependency vulnerability scanning') .option('--package-json ', 'Path to package.json file') .option('--lock-file ', 'Path to lock file (package-lock.json, yarn.lock, etc.)') .option('--max-issues ', 'Maximum number of issues to report', '50'); } protected async execute(options: any, command: Command): Promise { const useCase = new ScanSecurityUseCaseImpl( this.gitAdapter, this.securityScannerAdapter, this.outputAdapter ); const securityOptions: any = { baseRef: options.baseRef, headRef: options.headRef, includeStaged: options.staged, includeUnstaged: options.unstaged, filePatterns: this.parseFilePatterns(options.filePatterns) || [], excludePatterns: this.parseExcludePatterns(options.excludePatterns) || [], outputFormat: this.getOutputFormat(options) as 'html' | 'json' | 'markdown' | 'console' | 'file', severity: options.severity ? options.severity.split(',') : this.config.security.severity, categories: options.categories ? options.categories.split(',') : this.config.security.categories, includeDependencies: options.includeDependencies || this.config.security.includeDependencies, packageJsonPath: options.packageJson || this.config.security.packageJsonPath, lockFilePath: options.lockFile || this.config.security.lockFilePath, }; const outputPath = this.getOutputPath(options); if (outputPath) { securityOptions.outputPath = outputPath; } if (this.isVerbose(options)) { console.log('Starting security scan...'); console.log('Options:', securityOptions); } try { const issues = await useCase.execute(securityOptions); if (this.isVerbose(options)) { console.log(`Security scan completed. Found ${issues.length} security issues.`); } } catch (error) { throw new Error(`Security scan failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } } }