2015-03-21 16:19:37 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2016-05-26 03:24:10 +00:00
|
|
|
"fmt"
|
|
|
|
|
2015-03-21 16:19:37 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
2015-05-26 00:33:31 +00:00
|
|
|
const (
|
2016-01-29 22:44:09 +00:00
|
|
|
SecretTokenType = "token"
|
2015-05-26 00:33:31 +00:00
|
|
|
)
|
2015-03-21 16:19:37 +00:00
|
|
|
|
2016-01-29 22:44:09 +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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-01-29 22:44:09 +00:00
|
|
|
Renew: b.secretTokenRenew,
|
2015-03-21 16:19:37 +00:00
|
|
|
Revoke: secretTokenRevoke,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 22:44:09 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-05-26 03:24:10 +00:00
|
|
|
tokenRaw, ok := req.Secret.InternalData["token"]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("secret is missing internal data: token")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = c.ACL().Destroy(tokenRaw.(string), nil)
|
2015-03-21 16:19:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return logical.ErrorResponse(err.Error()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|