/
backend.go
73 lines (60 loc) · 1.45 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
package plugin
import (
"context"
"errors"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
const (
// #nosec G101
backendSecretType = "vercel_token"
backendPathHelp = `
Vercel Secrets backend is a secrets backend for dynamically managing Vercel tokens.`
// #nosec G101
secretTokenIDDescription = `
Token ID of the generated API key is stored in the plugin backend.
This ID is used for revocation purposes. It can only be used to identify a key,
and cannot be used to do API operations.`
)
var (
errBackendEmptyConfig = errors.New("configuration passed into backend is nil")
)
type backend struct {
*framework.Backend
}
var _ logical.Factory = Factory
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b := newBackend()
if conf == nil {
return nil, errBackendEmptyConfig
}
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
func newBackend() *backend {
b := &backend{}
b.Backend = &framework.Backend{
Help: backendPathHelp,
BackendType: logical.TypeLogical,
Paths: framework.PathAppend(
b.pathConfig(),
b.pathToken(),
b.pathInfo(),
),
Secrets: []*framework.Secret{
{
Type: backendSecretType,
Fields: map[string]*framework.FieldSchema{
pathTokenID: {
Type: framework.TypeString,
Description: secretTokenIDDescription,
},
},
Revoke: b.Revoke,
},
},
}
return b
}