forked from getsops/sops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
48 lines (44 loc) · 1.19 KB
/
example_test.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
package sops_test
import (
"encoding/json"
"log"
"go.mozilla.org/sops/decrypt"
)
type configuration struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Age float64 `json:"age"`
Address struct {
City string `json:"city"`
PostalCode string `json:"postalCode"`
State string `json:"state"`
StreetAddress string `json:"streetAddress"`
} `json:"address"`
PhoneNumbers []struct {
Number string `json:"number"`
Type string `json:"type"`
} `json:"phoneNumbers"`
AnEmptyValue string `json:"anEmptyValue"`
}
func Example_DecryptFile() {
var (
confPath string = "./example.json"
cfg configuration
err error
)
confData, err := decrypt.File(confPath, "json")
if err != nil {
log.Fatalf("cleartext configuration marshalling failed with error: %v", err)
}
err = json.Unmarshal(confData, &cfg)
if err != nil {
log.Fatalf("cleartext configuration unmarshalling failed with error: %v", err)
}
if cfg.FirstName != "John" ||
cfg.LastName != "Smith" ||
cfg.Age != 25.4 ||
cfg.PhoneNumbers[1].Number != "646 555-4567" {
log.Fatalf("configuration does not contain expected values: %+v", cfg)
}
log.Printf("%+v", cfg)
}