Class: Julewire::Redaction::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/redaction/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(filters = Redaction.config.filters, mask: Redaction.config.mask, max_array_items: Redaction.config.max_array_items, max_depth: Redaction.config.max_depth, max_hash_keys: Redaction.config.max_hash_keys, max_string_bytes: Redaction.config.max_string_bytes, string_values: Redaction.config.string_values, authorization_header: Redaction.config.authorization_header) ⇒ Processor

Returns a new instance of Processor.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/julewire/redaction/processor.rb', line 11

def initialize(
  filters = Redaction.config.filters,
  mask: Redaction.config.mask,
  max_array_items: Redaction.config.max_array_items,
  max_depth: Redaction.config.max_depth,
  max_hash_keys: Redaction.config.max_hash_keys,
  max_string_bytes: Redaction.config.max_string_bytes,
  string_values: Redaction.config.string_values,
  authorization_header: Redaction.config.authorization_header
)
  @matcher = Matcher.new(filters)
  @blocks = @matcher.blocks
  @mask = mask.to_s
  @max_array_items = Core::Validation.validate_integer_limit!(max_array_items, name: :max_array_items)
  @max_depth = Core::Validation.validate_integer_limit!(max_depth, name: :max_depth, positive: true)
  @max_hash_keys = Core::Validation.validate_integer_limit!(max_hash_keys, name: :max_hash_keys)
  @max_string_bytes = Core::Validation.validate_integer_limit!(max_string_bytes, name: :max_string_bytes)
  @string_redactor = if string_values
                       StringRedactor.new(
                         matcher: @matcher,
                         mask: @mask,
                         authorization_header: authorization_header
                       )
                     end
  @enabled = !@matcher.empty? || @string_redactor || !@blocks.empty?
  @record_transform = Core::Processing::RecordFieldTransform.new(
    max_array_items: @max_array_items,
    max_depth: @max_depth,
    max_hash_keys: @max_hash_keys,
    max_string_bytes: @max_string_bytes,
    preserve_top_level_keys: PRESERVED_TOP_LEVEL_KEYS,
    track_paths: @matcher.path_dependent?
  )
end

Instance Method Details

#call(draft) ⇒ Object



46
47
48
49
50
51
# File 'lib/julewire/redaction/processor.rb', line 46

def call(draft)
  validate_draft!(draft)
  return draft unless @enabled

  draft.transform_record! { redact_record(it) }
end