-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (55 loc) · 1.53 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
package main
import (
"encoding/json"
"fmt"
"github.com/evidenceledger/gosiop2/credentials"
"github.com/evidenceledger/gosiop2/ent"
"github.com/evidenceledger/gosiop2/internal/gyaml"
"github.com/evidenceledger/gosiop2/internal/jwt"
zlog "github.com/rs/zerolog/log"
)
type CredentialClaims struct {
jwt.RegisteredClaims
Other map[string]any
}
func main() {
// Open connection to the database
db, err := ent.Open("sqlite3", "file:/home/jesus/.siop2/vaultdb.sqlite?mode=rwc&cache=shared&_fk=1")
if err != nil {
panic(err)
}
c := credentials.NewFromDBClient(db)
// Parse credential data
data, err := gyaml.ParseYamlFile("/home/jesus/gosrc/gosiop2/cmd/creds/sampledata/employee_data.yaml")
_, err = json.MarshalIndent(data.Data(), "", " ")
if err != nil {
panic(err)
}
// Get the top-level list (the list of credentials)
creds, err := data.List("")
if err != nil {
panic(err)
}
// Iterate through the list creating each credential which will use its own template
for _, item := range creds {
cred, _ := item.(map[string]any)
rawCred, err := c.CreateCredentialFromMap2(cred)
if err != nil {
zlog.Logger.Error().Err(err).Send()
}
fmt.Println(string(rawCred))
// Check that the content is correct
b := &CredentialClaims{}
_, err = jwt.NewParser().ParseUnverified2(string(rawCred), b)
if err != nil {
zlog.Logger.Error().Err(err).Send()
continue
}
out, err := json.MarshalIndent(b.Other, "", " ")
if err != nil {
zlog.Logger.Error().Err(err).Send()
continue
}
fmt.Println(string(out))
}
}