/
main.go
60 lines (52 loc) · 1.21 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
/*
| Protect your secrets, protect your sensitive data.
: Explore VMware Secrets Manager docs at https://vsecm.com/
</
<>/ keep your secrets... secret
>/
<>/' Copyright 2023-present VMware Secrets Manager contributors.
>/' SPDX-License-Identifier: BSD-2-Clause
*/
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/vmware-tanzu/secrets-manager/sdk/sentry" // <- SDK
)
func main() {
go func() {
// Block the process from exiting, but also be graceful and honor the
// termination signals that may come from the orchestrator.
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM)
select {
case e := <-s:
fmt.Println(e)
panic("bye cruel world!")
}
}()
for {
log.Println("fetch")
d, err := sentry.Fetch()
if err != nil {
fmt.Println("Failed to read the secrets file. Will retry in 5 seconds...")
fmt.Println(err.Error())
time.Sleep(5 * time.Second)
continue
}
if d.Data == "" {
fmt.Println("no secret yet... will check again later.")
time.Sleep(5 * time.Second)
continue
}
fmt.Printf(
"secret: updated: %s, created: %s, value: %s\n",
d.Updated, d.Created, d.Data,
)
time.Sleep(5 * time.Second)
}
}