-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (63 loc) · 1.35 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bytes"
"encoding/csv"
"github.com/cheggaaa/pb/v3"
"github.com/davecgh/go-spew/spew"
"io/ioutil"
"os"
"time"
)
import "github.com/mohae/struct2csv"
type Record struct {
Name string
Email string
Group string
CertID string
CertSignMessage string
CertSignedMessage string
}
var Records []Record
func main() {
file, err := os.Open("data.csv")
if err != nil {
panic(err)
}
reader := csv.NewReader(file)
reader.TrimLeadingSpace = true
records, err := reader.ReadAll()
bar := pb.New(len(records))
bar.SetRefreshRate(time.Millisecond * 33)
bar.Start()
// unmarshal data from csv, generate CertID and message, then sign it
for _, record := range records {
r := Record{
Name: sanitize(record[0]),
Email: sanitize(record[1]),
Group: sanitize(record[2]),
}
r.CertID = GenerateCertID(r)
r.CertSignMessage = GenerateSignMessage(r)
r.CertSignedMessage = PGPSignString(r.CertSignMessage)
spew.Dump(r)
Records = append(Records, r)
bar.Increment()
}
bar.Finish()
buff := &bytes.Buffer{}
w := struct2csv.NewWriter(buff)
err = w.WriteStructs(Records)
if err != nil {
panic(err)
}
w.Flush()
dat, err := ioutil.ReadAll(buff)
if err != nil {
panic(err)
}
err = ioutil.WriteFile("result.csv", dat, 0644)
if err != nil {
panic(err)
}
// write cert data to a csv and use photoshop to generate it
}