class Elasticsearch::Transport::Redacted

Class for wrapping a hash that could have sensitive data. When printed, the sensitive values will be redacted.

@since 6.1.1

Constants

SENSITIVE_KEYS

The keys whose values will be redacted.

@since 6.1.1

STRING_REPLACEMENT

The replacement string used in place of the value for sensitive keys.

@since 6.1.1

Public Class Methods

new(elements = nil) click to toggle source
Calls superclass method
# File lib/elasticsearch/transport/redacted.rb, line 27
def initialize(elements = nil)
  super()
  (elements || {}).each_pair{ |key, value| self[key] = value }
end

Public Instance Methods

inspect() click to toggle source

Get a string representation of the hash.

@return [ String ] The string representation of the hash.

@since 6.1.1

# File lib/elasticsearch/transport/redacted.rb, line 48
def inspect
  redacted_string(:inspect)
end
to_s() click to toggle source

Get a string representation of the hash.

@return [ String ] The string representation of the hash.

@since 6.1.1

# File lib/elasticsearch/transport/redacted.rb, line 57
def to_s
  redacted_string(:to_s)
end

Private Instance Methods

redact(k, v, method) click to toggle source
# File lib/elasticsearch/transport/redacted.rb, line 69
def redact(k, v, method)
  return STRING_REPLACEMENT if SENSITIVE_KEYS.include?(k.to_sym)
  v.send(method)
end
redacted_string(method) click to toggle source
# File lib/elasticsearch/transport/redacted.rb, line 63
def redacted_string(method)
  '{' + reduce([]) do |list, (k, v)|
    list << "#{k.send(method)}=>#{redact(k, v, method)}"
  end.join(', ') + '}'
end