-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.go
65 lines (57 loc) · 1.47 KB
/
backend.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
package kms
import (
"context"
"strings"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
// Factory returns a new backend as logical.Backend
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
}
// kmsBackend defines an object that
// extends the Vault backend and stores the
// user wallet.
type kmsBackend struct {
*framework.Backend
}
// backend defines the target API backend
// for Vault. It must include each path
// and the secrets it will store.
func backend() *kmsBackend {
var b = kmsBackend{}
b.Backend = &framework.Backend{
Help: strings.TrimSpace(backendHelp),
PathsSpecial: &logical.Paths{
LocalStorage: []string{},
SealWrapStorage: []string{
"did",
"wallet",
},
},
Paths: framework.PathAppend(
pathWallet(&b),
pathSign(&b),
),
Secrets: []*framework.Secret{},
BackendType: logical.TypeLogical,
Invalidate: b.invalidate,
}
return &b
}
// invalidate clears an existing configuration in the backend
func (b *kmsBackend) invalidate(ctx context.Context, key string) {
if key == "config" {
// b.reset()
}
}
// backendHelp should contain help information for the backend
const backendHelp = `
The KMS secrets backend generates user wallet.
After mounting this backend, request data to generate signed transaction
must be transfered with the "wallet/" endpoints.
`