forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_backup.go
43 lines (35 loc) · 1.06 KB
/
path_backup.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
package transit
import (
"context"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func (b *backend) pathBackup() *framework.Path {
return &framework.Path{
Pattern: "backup/" + framework.GenericNameRegex("name"),
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Name of the key",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathBackupRead,
},
HelpSynopsis: pathBackupHelpSyn,
HelpDescription: pathBackupHelpDesc,
}
}
func (b *backend) pathBackupRead(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
backup, err := b.lm.BackupPolicy(ctx, req.Storage, d.Get("name").(string))
if err != nil {
return nil, err
}
return &logical.Response{
Data: map[string]interface{}{
"backup": backup,
},
}, nil
}
const pathBackupHelpSyn = `Backup the named key`
const pathBackupHelpDesc = `This path is used to backup the named key.`