57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
|
package transit
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/hashicorp/vault/logical"
|
||
|
"github.com/hashicorp/vault/logical/framework"
|
||
|
)
|
||
|
|
||
|
func pathRotate() *framework.Path {
|
||
|
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{
|
||
|
logical.WriteOperation: pathRotateWrite,
|
||
|
},
|
||
|
|
||
|
HelpSynopsis: pathRotateHelpSyn,
|
||
|
HelpDescription: pathRotateHelpDesc,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func pathRotateWrite(
|
||
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||
|
name := d.Get("name").(string)
|
||
|
|
||
|
// Check if the policy already exists
|
||
|
policy, err := getPolicy(req, name)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if policy == nil {
|
||
|
return logical.ErrorResponse(
|
||
|
fmt.Sprintf("no existing role named %s could be found", name)),
|
||
|
logical.ErrInvalidRequest
|
||
|
}
|
||
|
|
||
|
// Generate the policy
|
||
|
err = policy.rotate(req.Storage)
|
||
|
|
||
|
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.
|
||
|
`
|