Sha256: 468bdf459b05d7cd90cd0144082ffdf18582f3be93f66630fb3614d61c4fe69e
Contents?: true
Size: 1.35 KB
Versions: 6
Compression:
Stored size: 1.35 KB
Contents
# (c) Copyright IBM Corp. 2021 # (c) Copyright Instana Inc. 2021 require 'uri' require 'cgi' module Instana class Secrets def initialize(logger: ::Instana.logger) @logger = logger end def remove_from_query(str, secret_values = Instana.agent.secret_values) return str unless secret_values url = URI(str) params = url.scheme ? CGI.parse(url.query || '') : CGI.parse(url.to_s) redacted = params.map do |k, v| needs_redaction = secret_values['list'] .any? { |t| matcher(secret_values['matcher']).(t,k) } [k, needs_redaction ? '<redacted>' : v] end url.query = URI.encode_www_form(redacted) url.scheme ? CGI.unescape(url.to_s) : CGI.unescape(url.query) end private def matcher(name) case name when 'equals-ignore-case' ->(expected, actual) { expected.casecmp(actual) == 0 } when 'equals' ->(expected, actual) { (expected <=> actual) == 0 } when 'contains-ignore-case' ->(expected, actual) { actual.downcase.include?(expected) } when 'contains' ->(expected, actual) { actual.include?(expected) } when 'regex' ->(expected, actual) { !Regexp.new(expected).match(actual).nil? } else @logger.warn("Matcher #{name} is not supported.") ->(_e, _a) { false } end end end end
Version data entries
6 entries across 6 versions & 1 rubygems