Class: Instana::Secrets

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/secrets.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger: ::Instana.logger) ⇒ Secrets

Returns a new instance of Secrets.



9
10
11
# File 'lib/instana/secrets.rb', line 9

def initialize(logger: ::Instana.logger)
  @logger = logger
end

Instance Method Details

#remove_from_query(str, secret_values = Instana.agent.secret_values) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/instana/secrets.rb', line 13

def remove_from_query(str, secret_values = Instana.agent.secret_values)
  return str unless secret_values && str

  begin
    url = URI(str)
    params = url.scheme ? CGI.parse(url.query || '') : CGI.parse(url.to_s)

    redacted = redact(params, secret_values)

    url.query = URI.encode_www_form(redacted)
    url.scheme ? CGI.unescape(url.to_s) : CGI.unescape(url.query)
  rescue URI::InvalidURIError => _e
    params = CGI.parse(str || '')
    redacted = redact(params, secret_values)
    CGI.unescape(URI.encode_www_form(redacted))
  end
end