Class: Lyra::Privacy::PIIMasker

Inherits:
Object
  • Object
show all
Defined in:
lib/lyra/privacy/pii_masker.rb

Overview

Masks PII in attribute hashes

This class delegates to PamDsl::PIIMasker for the core masking logic, providing a unified implementation across both Lyra and PAM DSL.

Examples:

Mask all PII in attributes

PIIMasker.mask({ email: "[email protected]", name: "John" })
# => { email: "t***@example.com", name: "John ***" }

Full redaction

PIIMasker.mask({ email: "[email protected]" }, strategy: :full)
# => { email: "[REDACTED]" }

Class Method Summary collapse

Class Method Details

.mask(attributes, strategy: :partial) ⇒ Hash

Mask all PII fields in an attributes hash

Parameters:

  • attributes (Hash) —

    Key-value pairs to mask

  • strategy (Symbol) (defaults to: :partial) —

    Masking strategy (:partial, :full, :redact_sensitive)

Returns:

  • (Hash) —

    New hash with PII fields masked



24
25
26
# File 'lib/lyra/privacy/pii_masker.rb', line 24

def mask(attributes, strategy: :partial)
  PamDsl::PIIMasker.mask(attributes, strategy: strategy)
end

.mask_events(events, strategy: :partial) ⇒ Array

Mask all PII in a collection of Lyra events

Parameters:

  • events (Array<Lyra::Event>) —

    Events to mask

  • strategy (Symbol) (defaults to: :partial) —

    Masking strategy

Returns:

  • (Array) —

    Events with masked attributes



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lyra/privacy/pii_masker.rb', line 44

def mask_events(events, strategy: :partial)
  PamDsl::PIIMasker.mask_records(
    events,
    attribute_extractor: ->(e) { e.attributes },
    attribute_setter: ->(e, masked) {
      Lyra::Event.new(
        event_id: e.event_id,
        operation: e.operation,
        model_class: e.model_class,
        model_id: e.model_id,
        attributes: masked,
        changes: e.changes,
        timestamp: e.timestamp,
        metadata: e.
      )
    },
    strategy: strategy
  )
end

.mask_field(value, field_name) ⇒ Object

Mask specific field

Parameters:

  • value (Object) —

    The value to mask

  • field_name (String, Symbol) —

    Field name to determine PII type

Returns:

  • (Object) —

    Masked value, or original if not PII



34
35
36
# File 'lib/lyra/privacy/pii_masker.rb', line 34

def mask_field(value, field_name)
  PamDsl::PIIMasker.mask_field(value, field_name)
end