Class: Ace::Git::Secrets::Atoms::GitleaksRunner
- Inherits:
-
Object
- Object
- Ace::Git::Secrets::Atoms::GitleaksRunner
- Defined in:
- lib/ace/git/secrets/atoms/gitleaks_runner.rb
Overview
Runner for gitleaks external tool Handles gitleaks availability detection and execution
Gitleaks is REQUIRED for ace-git-secrets. The gem focuses on remediation (revocation, history rewriting) while delegating detection to gitleaks which has 100+ actively maintained patterns.
Defined Under Namespace
Classes: GitleaksNotFoundError
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if gitleaks is available in PATH.
-
.ensure_available! ⇒ Object
Ensure gitleaks is available, raising error if not.
-
.ensure_compatible! ⇒ Object
Ensure gitleaks version is compatible.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Instance method for backward compatibility.
-
#compatible_version? ⇒ Boolean
Check if gitleaks version is compatible (8.0+) ace-git-secrets requires gitleaks 8.x for the ‘git` subcommand and JSON report format.
-
#initialize(config_path: nil) ⇒ GitleaksRunner
constructor
A new instance of GitleaksRunner.
-
#scan_files(path: ".", verbose: false) ⇒ Hash
Run gitleaks scan on current files (no git history).
-
#scan_history(path: ".", since: nil, verbose: false) ⇒ Hash
Run gitleaks scan on git history.
-
#version ⇒ String?
Get gitleaks version.
Constructor Details
#initialize(config_path: nil) ⇒ GitleaksRunner
Returns a new instance of GitleaksRunner.
24 25 26 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 24 def initialize(config_path: nil) @config_path = config_path end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
21 22 23 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 21 def config_path @config_path end |
Class Method Details
.available? ⇒ Boolean
Check if gitleaks is available in PATH
30 31 32 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 30 def self.available? system("which gitleaks > /dev/null 2>&1") end |
.ensure_available! ⇒ Object
Ensure gitleaks is available, raising error if not
36 37 38 39 40 41 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 36 def self.ensure_available! return if available? raise GitleaksNotFoundError, "gitleaks is required but not installed. Install with: brew install gitleaks" end |
.ensure_compatible! ⇒ Object
Ensure gitleaks version is compatible
77 78 79 80 81 82 83 84 85 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 77 def self.ensure_compatible! runner = new return if runner.compatible_version? ver = runner.version || "unknown" raise GitleaksNotFoundError, "gitleaks version #{ver} is not compatible. Version 8.0+ is required. " \ "Upgrade with: brew upgrade gitleaks" end |
Instance Method Details
#available? ⇒ Boolean
Instance method for backward compatibility
45 46 47 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 45 def available? self.class.available? end |
#compatible_version? ⇒ Boolean
Check if gitleaks version is compatible (8.0+) ace-git-secrets requires gitleaks 8.x for the ‘git` subcommand and JSON report format
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 63 def compatible_version? ver = version return false unless ver # Extract major version from strings like "v8.18.4" or "8.18.4" match = ver.match(/v?(\d+)\./) return false unless match major = match[1].to_i major >= 8 end |
#scan_files(path: ".", verbose: false) ⇒ Hash
Run gitleaks scan on current files (no git history)
91 92 93 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 91 def scan_files(path: ".", verbose: false) run_gitleaks(path: path, no_git: true, verbose: verbose) end |
#scan_history(path: ".", since: nil, verbose: false) ⇒ Hash
Run gitleaks scan on git history
100 101 102 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 100 def scan_history(path: ".", since: nil, verbose: false) run_gitleaks(path: path, no_git: false, since: since, verbose: verbose) end |
#version ⇒ String?
Get gitleaks version
51 52 53 54 55 56 57 58 |
# File 'lib/ace/git/secrets/atoms/gitleaks_runner.rb', line 51 def version return nil unless available? stdout, _status = Open3.capture2("gitleaks version") stdout.strip rescue nil end |