2015-03-21 16:19:37 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2015-04-19 05:29:46 +00:00
|
|
|
"time"
|
|
|
|
|
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 (
|
|
|
|
SecretTokenType = "token"
|
|
|
|
DefaultLeaseDuration = 1 * time.Hour
|
|
|
|
DefaultGracePeriod = 10 * time.Minute
|
|
|
|
)
|
2015-03-21 16:19:37 +00:00
|
|
|
|
|
|
|
func secretToken() *framework.Secret {
|
|
|
|
return &framework.Secret{
|
|
|
|
Type: SecretTokenType,
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"token": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "Request token",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2015-05-26 00:33:31 +00:00
|
|
|
DefaultDuration: DefaultLeaseDuration,
|
|
|
|
DefaultGracePeriod: DefaultGracePeriod,
|
2015-04-19 05:29:46 +00:00
|
|
|
|
2015-06-17 21:34:11 +00:00
|
|
|
Renew: framework.LeaseExtend(0, 0, true),
|
2015-03-21 16:19:37 +00:00
|
|
|
Revoke: secretTokenRevoke,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|