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.
200 201 202 203 |
# File 'lib/antigravity/guards.rb', line 200 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.
198 199 200 |
# File 'lib/antigravity/guards.rb', line 198 def patterns @patterns end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
198 199 200 |
# File 'lib/antigravity/guards.rb', line 198 def replacement @replacement end |
Instance Method Details
#call(_tool_name, _params, result) ⇒ Object
205 206 207 208 209 210 211 212 213 |
# File 'lib/antigravity/guards.rb', line 205 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
215 216 217 |
# File 'lib/antigravity/guards.rb', line 215 def to_proc method(:call).to_proc end |