2017-12-14 17:51:50 +00:00
|
|
|
package transit
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2017-12-14 17:51:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *backend) pathBackup() *framework.Path {
|
|
|
|
return &framework.Path{
|
|
|
|
Pattern: "backup/" + framework.GenericNameRegex("name"),
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"name": {
|
2017-12-14 17:51:50 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "Name of the key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
|
|
logical.ReadOperation: b.pathBackupRead,
|
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathBackupHelpSyn,
|
|
|
|
HelpDescription: pathBackupHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathBackupRead(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2018-01-19 06:44:44 +00:00
|
|
|
backup, err := b.lm.BackupPolicy(ctx, req.Storage, d.Get("name").(string))
|
2017-12-14 17:51:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &logical.Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"backup": backup,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
const (
|
|
|
|
pathBackupHelpSyn = `Backup the named key`
|
|
|
|
pathBackupHelpDesc = `This path is used to backup the named key.`
|
|
|
|
)
|