Module: DockerSwarm::LogHelper
- Defined in:
- lib/docker_swarm/log_helper.rb
Overview
Helper module to centralize logging logic and formatting
Constant Summary collapse
- SENSITIVE_KEYS =
datase matchea con \b para queData(Secret/Config) se filtre perometadatau otras claves no caigan en falso positivo.authcubre headers de autenticación (X-Registry-Auth,Authorization), case-insensitive. /password|pass|passwd|secret|token|api_key|auth|\bdata\b/i.freeze
- FILTERED =
"[FILTERED]"
Class Method Summary collapse
-
.format_kv(payload) ⇒ String
Formats a hash into a KV structured string with sensitive data masking.
-
.sanitize(value) ⇒ Object
Redacta recursivamente los valores cuya CLAVE es sensible, a cualquier profundidad (hashes y arrays anidados).
Class Method Details
.format_kv(payload) ⇒ String
Formats a hash into a KV structured string with sensitive data masking
37 38 39 40 41 42 43 |
# File 'lib/docker_swarm/log_helper.rb', line 37 def self.format_kv(payload) sanitize(payload).map do |k, v| "#{k}=#{v}" end.join(" ") rescue "event=logging_error" end |
.sanitize(value) ⇒ Object
Redacta recursivamente los valores cuya CLAVE es sensible, a cualquier profundidad (hashes y arrays anidados). No muta la entrada: devuelve copias.
Un header sensible puede viajar anidado (headers: { "X-Registry-Auth" => "<cred>" })
y el match por clave de primer nivel no lo alcanzaba — el hash interno se
interpolaba entero.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docker_swarm/log_helper.rb', line 21 def self.sanitize(value) case value when Hash value.each_with_object({}) do |(k, v), acc| acc[k] = k.to_s.match?(SENSITIVE_KEYS) ? FILTERED : sanitize(v) end when Array value.map { |v| sanitize(v) } else value end end |