-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.go
74 lines (60 loc) · 1.59 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
66
67
68
69
70
71
72
73
74
package auth0
import (
"context"
"fmt"
"strings"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
// backend wraps the backend framework and adds a map for storing key value pairs
type backend struct {
*framework.Backend
}
var _ logical.Factory = Factory
// Factory configures and returns Mock backends
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b, err := newBackend()
if err != nil {
return nil, err
}
if conf == nil {
return nil, fmt.Errorf("configuration passed into backend is nil")
}
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
func newBackend() (*backend, error) {
b := &backend{}
b.Backend = &framework.Backend{
Help: strings.TrimSpace(backendHelp),
BackendType: logical.TypeLogical,
Paths: framework.PathAppend(
b.paths(),
),
Secrets: []*framework.Secret{
secretToken(b),
},
}
return b, nil
}
func (b *backend) paths() []*framework.Path {
return []*framework.Path{
pathConfigRoot(b),
pathCredsCreate(b),
pathRoles(b),
pathListRoles(b),
pathConfigRotateRoot(b),
pathConfigLease(b),
}
}
const backendHelp = `
The cloudflare backend generates cloudflare tokens based on cloudflare
polices The Cloudflare tokens have a configurable lease set and are
automatically revoked at the end of the lease.
After mounting this backend, a root token (with the ability to generate
tokens) must be configured with the 'config/token' path and policies must
be written using the "roles/" endpoints before any access keys can be
generated.
`