-
Notifications
You must be signed in to change notification settings - Fork 5
/
path_config.go
56 lines (49 loc) · 1.55 KB
/
path_config.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
package packet
import (
"context"
"errors"
"strings"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
func (b *backend) pathConfig() *framework.Path {
return &framework.Path{
Pattern: "config",
Fields: map[string]*framework.FieldSchema{
"api_token": {
Type: framework.TypeString,
Description: "User API token with read-write permissions",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.operationConfigUpdate,
},
HelpSynopsis: pathConfigRootHelpSyn,
HelpDescription: pathConfigRootHelpDesc,
}
}
type packetSecretsEngineConfig struct {
APIToken string `json:"api_token"`
}
func (b *backend) operationConfigUpdate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
apiToken := ""
if apiTokenIfc, ok := data.GetOk("api_token"); ok {
apiToken = strings.TrimSpace(apiTokenIfc.(string))
} else {
return nil, errors.New("api_token is required")
}
entry, err := logical.StorageEntryJSON("config",
packetSecretsEngineConfig{
APIToken: apiToken,
})
if err != nil {
return nil, err
}
if err := req.Storage.Put(ctx, entry); err != nil {
return nil, err
}
b.resetClient(ctx)
return nil, nil
}
const pathConfigRootHelpSyn = `Configure the API token which Vault will use to create temporary tokens.`
const pathConfigRootHelpDesc = `Before doing anything, the Packet backend needs credentials that are able to create other API tokens. This endpoint is used to configure those credentials.`