-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.go
More file actions
76 lines (65 loc) · 1.75 KB
/
backend.go
File metadata and controls
76 lines (65 loc) · 1.75 KB
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
package solacevaultplugin
import (
"context"
"sync"
"time"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
const backendHelp = "The Solace secrets engine rotates CLI user passwords on Solace PubSub+ brokers."
type solaceBackend struct {
*framework.Backend
roleMutex sync.RWMutex
}
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b := backend()
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
func backend() *solaceBackend {
b := &solaceBackend{}
b.Backend = &framework.Backend{
Help: backendHelp,
BackendType: logical.TypeLogical,
RunningVersion: "v0.1.0",
PathsSpecial: &logical.Paths{
SealWrapStorage: []string{
"config/brokers/*",
"roles/*",
},
},
PeriodicFunc: b.periodicFunc,
Paths: framework.PathAppend(
pathConfigBrokers(b),
pathRoles(b),
pathCreds(b),
pathRotateRole(b),
),
}
return b
}
func (b *solaceBackend) periodicFunc(ctx context.Context, req *logical.Request) error {
roles, err := listRoles(ctx, req.Storage)
if err != nil {
b.Logger().Error("periodic: failed to list roles", "error", err)
return nil
}
for _, name := range roles {
role, err := getRole(ctx, req.Storage, name)
if err != nil {
b.Logger().Error("periodic: failed to read role", "role", name, "error", err)
continue
}
if role == nil || role.RotationPeriod == 0 || role.LastRotated.IsZero() {
continue
}
if time.Now().UTC().After(role.LastRotated.Add(role.RotationPeriod)) {
if _, err := b.rotateRole(ctx, req.Storage, name); err != nil {
b.Logger().Error("periodic: failed to rotate role", "role", name, "error", err)
}
}
}
return nil
}