Sha256: c81ab8de4b8189e4478b880f5bb5b06c338782f50a8b720b9b5011f3b91b1466

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true
require 'forwardable'
require 'facets/string/titlecase'

module SensitiveDataFilter
  module Middleware
    class Occurrence
      extend Forwardable

      attr_reader :matches

      def initialize(original_env_parser, filtered_env_parser, matches)
        @original_env_parser = original_env_parser
        @filtered_env_parser = filtered_env_parser
        @matches             = matches
      end

      def origin_ip
        @original_env_parser.ip
      end

      def original_query_params
        @original_env_parser.query_params
      end

      def original_body_params
        @original_env_parser.body_params
      end

      def filtered_query_params
        @filtered_env_parser.query_params
      end

      def filtered_body_params
        @filtered_env_parser.body_params
      end

      def_delegators :@original_env_parser, :request_method, :url, :content_type, :session

      def matches_count
        @matches.map { |type, matches| [type, matches.count] }.to_h
      end

      def to_h
        {
          origin_ip:             origin_ip,
          request_method:        request_method,
          url:                   url,
          content_type:          content_type,
          filtered_query_params: filtered_query_params,
          filtered_body_params:  filtered_body_params,
          session:               session,
          matches_count:         matches_count
        }
      end

      def to_s
        "[SensitiveDataFilter] Sensitive Data detected and masked:\n" +
          to_h.map { |attribute, value| "#{attribute.to_s.titlecase}: #{value}" }.join("\n")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensitive_data_filter-0.2.2 lib/sensitive_data_filter/middleware/occurrence.rb
sensitive_data_filter-0.2.1 lib/sensitive_data_filter/middleware/occurrence.rb
sensitive_data_filter-0.2.0 lib/sensitive_data_filter/middleware/occurrence.rb