-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (44 loc) · 1005 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
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
45
46
47
48
49
50
51
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"os"
)
func PrettyString(str string) (string, error) {
var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, []byte(str), "", " "); err != nil {
return "", err
}
return prettyJSON.String(), nil
}
func main() {
prettyPtr := flag.Bool("pretty", true, "display pretty output; otherwise do: -pretty=false")
flag.Parse()
if len(os.Args) < 2 {
fmt.Println("Usage: scrub-pii <input json file> <sensitive fields file>")
os.Exit(1)
}
inputPath := flag.Args()[0]
sensitiveFieldsPath := flag.Args()[1]
// scrub the input file for the given sensitive fields
output, err := ScrubPersonalInfo(inputPath, sensitiveFieldsPath)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
// pretty output if -pretty is specified
if *prettyPtr {
pretty, err := PrettyString(output)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Println(pretty)
return
}
// just output a json string
fmt.Println(output)
}