forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 1
/
path_restore.go
43 lines (35 loc) · 1.3 KB
/
path_restore.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) pathRestore() *framework.Path {
return &framework.Path{
Pattern: "restore" + framework.OptionalParamRegex("name"),
Fields: map[string]*framework.FieldSchema{
"backup": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Backed up key data to be restored. This should be the output from the 'backup/' endpoint.",
},
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "If set, this will be the name of the restored key.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.pathRestoreUpdate,
},
HelpSynopsis: pathRestoreHelpSyn,
HelpDescription: pathRestoreHelpDesc,
}
}
func (b *backend) pathRestoreUpdate(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
backupB64 := d.Get("backup").(string)
if backupB64 == "" {
return logical.ErrorResponse("'backup' must be supplied"), nil
}
return nil, b.lm.RestorePolicy(ctx, req.Storage, d.Get("name").(string), backupB64)
}
const pathRestoreHelpSyn = `Restore the named key`
const pathRestoreHelpDesc = `This path is used to restore the named key.`