open-vault/builtin/logical/consul/secret_token.go

60 lines
1.4 KiB
Go
Raw Normal View History

2015-03-21 16:19:37 +00:00
package consul
import (
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
const (
SecretTokenType = "token"
)
2015-03-21 16:19:37 +00:00
func secretToken(b *backend) *framework.Secret {
2015-03-21 16:19:37 +00:00
return &framework.Secret{
Type: SecretTokenType,
Fields: map[string]*framework.FieldSchema{
"token": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Request token",
},
},
Renew: b.secretTokenRenew,
2015-03-21 16:19:37 +00:00
Revoke: secretTokenRevoke,
}
}
func (b *backend) secretTokenRenew(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
return framework.LeaseExtend(0, 0, b.System())(req, d)
}
2015-03-21 16:19:37 +00:00
func secretTokenRevoke(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
c, userErr, intErr := client(req.Storage)
if intErr != nil {
return nil, intErr
}
if userErr != nil {
// Returning logical.ErrorResponse from revocation function is risky
return nil, userErr
2015-03-21 16:19:37 +00:00
}
tokenRaw, ok := req.Secret.InternalData["token"]
if !ok {
// We return nil here because this is a pre-0.5.3 problem and there is
// nothing we can do about it. We already can't revoke the lease
// properly if it has been renewed and this is documented pre-0.5.3
// behavior with a security bulletin about it.
return nil, nil
}
_, err := c.ACL().Destroy(tokenRaw.(string), nil)
2015-03-21 16:19:37 +00:00
if err != nil {
return nil, err
2015-03-21 16:19:37 +00:00
}
return nil, nil
}