Class: Omamori::StaticAnalysers::BundlerAuditRunner
- Inherits:
-
Object
- Object
- Omamori::StaticAnalysers::BundlerAuditRunner
- Defined in:
- lib/omamori/static_analysers/bundler_audit_runner.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BundlerAuditRunner
constructor
A new instance of BundlerAuditRunner.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BundlerAuditRunner
Returns a new instance of BundlerAuditRunner.
8 9 10 |
# File 'lib/omamori/static_analysers/bundler_audit_runner.rb', line 8 def initialize( = {}) @options = end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/omamori/static_analysers/bundler_audit_runner.rb', line 12 def run # TODO: Determine Bundler-Audit command based on options # Example: bundle audit --format json # Include options passed during initialization # Build options string from the options hash = @options.map { |key, value| "--#{key.to_s.gsub('_', '-')}" + (value == true ? "" : " #{value}") }.join(" ") bundler_audit_command = "bundle audit --format json#{.empty? ? '' : " #{}"}" begin # Execute the Bundler-Audit command and capture output # Note: bundle audit exits with non-zero status if vulnerabilities are found # We need to capture stdout and stderr regardless of exit status bundler_audit_output = `#{bundler_audit_command} 2>&1` # Parse the JSON output # Bundler-Audit JSON output structure might vary, need to confirm # Assuming it returns a JSON object with vulnerability information parsed_output = JSON.parse(bundler_audit_output) # Validate the parsed output structure if parsed_output.is_a?(Hash) && parsed_output.key?('results') # Return the entire parsed output hash parsed_output else puts "Error: Unexpected Bundler-Audit JSON output structure." puts "Raw output:\n#{bundler_audit_output}" nil # Return nil if the structure is unexpected end rescue Errno::ENOENT puts "Error: bundle command not found. Is Bundler installed?" nil rescue JSON::ParserError puts "Error: Failed to parse Bundler-Audit JSON output." puts "Raw output:\n#{bundler_audit_output}" nil rescue => e puts "An error occurred during Bundler-Audit execution: #{e.}" nil end end |