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

47 lines
1002 B
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, err := client(req.Storage)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
}
_, err = c.ACL().Destroy(d.Get("token").(string), nil)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
}
return nil, nil
}