Skip to content

Commit ae02acb

Browse files
authored
Create maskpii.lua
1 parent f91625d commit ae02acb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

maskpii.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
local json = require 'json'
2+
3+
local function maskSSN(ssn)
4+
if not ssn then
5+
return nil
6+
end
7+
-- Replace all but the last four digits of the SSN with "XXX-XX-"
8+
return string.gsub(ssn, "^(.-)(%d%d%d%d)$", "XXX-XX-%2")
9+
end
10+
11+
local function RowToMap(row)
12+
local map = peerdb.RowTable(row)
13+
for col, val in pairs(map) do
14+
local kind = peerdb.RowColumnKind(row, col)
15+
if col == 'ssn' then
16+
-- Apply the maskSSN function to the SSN column
17+
map[col] = maskSSN(val)
18+
elseif kind == 'bytes' or kind == 'bit' then
19+
map[col] = json.bin(val)
20+
end
21+
end
22+
return map
23+
end
24+
25+
local RKINDMAP = {
26+
insert = string.byte('i', 1),
27+
update = string.byte('u', 1),
28+
delete = string.byte('d', 1),
29+
}
30+
31+
function onRecord(r)
32+
local kind = RKINDMAP[r.kind]
33+
if not kind then
34+
return
35+
end
36+
local record = {
37+
action = kind,
38+
lsn = r.checkpoint,
39+
time = r.commit_time,
40+
source = r.source,
41+
}
42+
if r.old then
43+
record.old = RowToMap(r.old)
44+
end
45+
if r.new then
46+
record.new = RowToMap(r.new)
47+
end
48+
return json.encode(record)
49+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy