Class: Antigravity::Guards::SecretMasker
- Inherits:
-
Object
- Object
- Antigravity::Guards::SecretMasker
- Defined in:
- lib/antigravity/guards.rb
Overview
Configurable opt-in secret masking filter
Constant Summary collapse
- DEFAULT_PATTERNS =
[ /(AIzaSy[A-Za-z0-9_-]{25,45})/, # Google API Keys /(sk-[A-Za-z0-9]{25,50})/, # OpenAI API Keys /(ghp_[A-Za-z0-9]{25,45})/, # GitHub Tokens /(bearer\s+[A-Za-z0-9\._-]{20,})/i # Bearer Tokens ].freeze
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
- #call(_tool_name, _params, result) ⇒ Object
-
#initialize(patterns: nil, replacement: "[REDACTED_SECRET]") ⇒ SecretMasker
constructor
A new instance of SecretMasker.
- #to_proc ⇒ Object
Constructor Details
#initialize(patterns: nil, replacement: "[REDACTED_SECRET]") ⇒ SecretMasker
Returns a new instance of SecretMasker.
140 141 142 143 |
# File 'lib/antigravity/guards.rb', line 140 def initialize(patterns: nil, replacement: "[REDACTED_SECRET]") @patterns = (patterns ? Array(patterns) : DEFAULT_PATTERNS).freeze @replacement = replacement end |
Instance Attribute Details
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
138 139 140 |
# File 'lib/antigravity/guards.rb', line 138 def patterns @patterns end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
138 139 140 |
# File 'lib/antigravity/guards.rb', line 138 def replacement @replacement end |
Instance Method Details
#call(_tool_name, _params, result) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/antigravity/guards.rb', line 145 def call(_tool_name, _params, result) return result unless result.is_a?(String) sanitized = result.dup @patterns.each do |pattern| sanitized.gsub!(pattern, @replacement) end sanitized end |
#to_proc ⇒ Object
155 156 157 |
# File 'lib/antigravity/guards.rb', line 155 def to_proc method(:call).to_proc end |