require 'oga'

module VSphereCloud
  module SdkHelpers
    class LogFilter

      FILTERS = [
        "soapenv:Envelope/soapenv:Body/Login/password",
      ]

      def filter(content)
        document = Oga.parse_xml(content)
        FILTERS.each do |filter|
          matching_node = document.xpath(filter)

          matching_node.each do |element|
            text = Oga::XML::Text.new
            text.text = 'redacted'

            element.children = [text]
          end
        end

        document.to_xml
      end

    end
  end
end

require 'oga'

module VSphereCloud
  module SdkHelpers
    class LogFilter

      FILTERS = [
        "soapenv:Envelope/soapenv:Body/Login/password",
      ]

      def filter(content)
        modified = false

        document = Oga.parse_xml(content)
        FILTERS.each do |filter|
          matching_node = document.xpath(filter)

          matching_node.each do |element|
            modified = true
            text = Oga::XML::Text.new
            text.text = 'redacted'

            element.children = [text]
          end
        end

        if modified
          document.to_xml
        else
          content
        end
      end

    end
  end
end

Use modified xml only if filter is applied
Use modified xml only if filter is applied

Signed-off-by: Chris Dutra <7eb54fc324f04033595eb420f2ee7c112fb7259e@pivotal.io>
