2015-09-14 20:28:46 +00:00
|
|
|
package transit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
2016-01-27 21:24:11 +00:00
|
|
|
func (b *backend) pathRotate() *framework.Path {
|
2015-09-14 20:28:46 +00:00
|
|
|
return &framework.Path{
|
|
|
|
Pattern: "keys/" + framework.GenericNameRegex("name") + "/rotate",
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"name": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "Name of the key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2016-01-27 21:24:11 +00:00
|
|
|
logical.UpdateOperation: b.pathRotateWrite,
|
2015-09-14 20:28:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathRotateHelpSyn,
|
|
|
|
HelpDescription: pathRotateHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-27 21:24:11 +00:00
|
|
|
func (b *backend) pathRotateWrite(
|
2015-09-14 20:28:46 +00:00
|
|
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
name := d.Get("name").(string)
|
|
|
|
|
2016-01-27 21:24:11 +00:00
|
|
|
// Get the policy
|
2016-05-03 03:46:39 +00:00
|
|
|
p, lock, err := b.lm.GetPolicyExclusive(req.Storage, name)
|
|
|
|
if lock != nil {
|
|
|
|
defer lock.Unlock()
|
2016-01-27 21:24:11 +00:00
|
|
|
}
|
2016-04-21 20:32:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-26 15:39:19 +00:00
|
|
|
if p == nil {
|
2016-05-03 03:46:39 +00:00
|
|
|
return logical.ErrorResponse("key not found"), logical.ErrInvalidRequest
|
2015-09-14 20:28:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 20:32:06 +00:00
|
|
|
// Rotate the policy
|
2016-04-26 15:39:19 +00:00
|
|
|
err = p.rotate(req.Storage)
|
2015-09-14 20:28:46 +00:00
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathRotateHelpSyn = `Rotate named encryption key`
|
|
|
|
|
|
|
|
const pathRotateHelpDesc = `
|
|
|
|
This path is used to rotate the named key. After rotation,
|
|
|
|
new encryption requests using this name will use the new key,
|
|
|
|
but decryption will still be supported for older versions.
|
|
|
|
`
|