Class: QueryGuard::CLI::Commands::Check
- Inherits:
-
QueryGuard::CLI::Command
- Object
- QueryGuard::CLI::Command
- QueryGuard::CLI::Commands::Check
- Defined in:
- lib/query_guard/cli/commands/check.rb
Overview
Checks if findings exceed severity threshold for CI/CD
Instance Method Summary collapse
Methods inherited from QueryGuard::CLI::Command
Constructor Details
This class inherits a constructor from QueryGuard::CLI::Command
Instance Method Details
#execute ⇒ Object
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 |
# File 'lib/query_guard/cli/commands/check.rb', line 8 def execute unless path_exists? puts "Error: Path does not exist: #{path_absolute}" return 2 # Failed to check end threshold = [:threshold] || 'error' # Skip progress output if JSON format is being used unless [:json] || [:format] == 'json' puts "Checking migrations: #{path_absolute}" puts "Threshold: #{threshold.upcase}\n" puts "(This may take a moment...)\n" end # Find and analyze migration files migration_files = find_migration_files(@path) if migration_files.empty? puts "✅ No migrations found - clear to deploy!\n" unless [:json] || [:format] == 'json' return 0 end puts " Found #{migration_files.length} migration files" unless [:json] || [:format] == 'json' findings = analyze_migrations(migration_files) if findings.empty? puts "\n✅ No issues found - clear to deploy!\n" unless [:json] || [:format] == 'json' return 0 end # Check if findings exceed threshold if findings_exceed_threshold?(findings, threshold) @formatter.print_findings(findings, "Migration Risk Check - FAILED ❌", 'check', @path) unless [:json] || [:format] == 'json' puts "\n🚫 Risk threshold exceeded! Deployment blocked.\n" puts "To proceed, either:" puts " 1. Fix the identified risks above" puts " 2. Increase the threshold (e.g., --threshold error)" puts " 3. Review with your DBA\n" end return 1 # Check failed else @formatter.print_findings(findings, "Migration Risk Check - PASSED ✅", 'check', @path) puts "\n✅ All risks below threshold - clear to deploy!\n" unless [:json] || [:format] == 'json' return 0 end end |