Class: Lemans::SecretsFilter
- Inherits:
-
Object
- Object
- Lemans::SecretsFilter
- Defined in:
- lib/lemans/secrets_filter.rb
Overview
Redacts known secret values (API credentials) from everything the store persists.
Class Method Summary collapse
-
.default ⇒ Object
Credentials follow the
_ environment convention (DAYTONA_API_KEY, OPENROUTER_API_KEY, DAYTONA_TOKEN, ...).
Instance Method Summary collapse
- #filter(text) ⇒ Object
-
#initialize(secrets, replacement: "<filtered>", min_length: 8) ⇒ SecretsFilter
constructor
A new instance of SecretsFilter.
Constructor Details
#initialize(secrets, replacement: "<filtered>", min_length: 8) ⇒ SecretsFilter
Returns a new instance of SecretsFilter.
10 11 12 13 14 15 16 17 |
# File 'lib/lemans/secrets_filter.rb', line 10 def initialize(secrets, replacement: "<filtered>", min_length: 8) @replacement = replacement secrets = secrets.compact.uniq.select { it.length >= min_length } # Match bytes, not characters, so artifacts with non-UTF-8 content # (binary patch hunks) don't raise on scanning. @pattern = Regexp.union(secrets.map(&:b)) unless secrets.empty? end |
Class Method Details
.default ⇒ Object
Credentials follow the
8 |
# File 'lib/lemans/secrets_filter.rb', line 8 def self.default = new(ENV.filter_map { |name, value| value if name.match?(/_(API_KEY|TOKEN|SECRET|JWT)\z/) }) |
Instance Method Details
#filter(text) ⇒ Object
19 20 21 22 23 |
# File 'lib/lemans/secrets_filter.rb', line 19 def filter(text) return text unless @pattern text.b.gsub(@pattern, @replacement) end |