2015-11-18 16:25:42 +00:00
|
|
|
package rabbitmq
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2015-11-18 16:25:42 +00:00
|
|
|
"time"
|
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
"github.com/fatih/structs"
|
2015-11-18 16:25:42 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func pathConfigLease(b *backend) *framework.Path {
|
|
|
|
return &framework.Path{
|
2016-06-08 07:18:26 +00:00
|
|
|
Pattern: "config/lease",
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"ttl": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeDurationSecond,
|
2016-06-08 15:35:09 +00:00
|
|
|
Default: 0,
|
2016-06-08 07:18:26 +00:00
|
|
|
Description: "Duration before which the issued credentials needs renewal",
|
|
|
|
},
|
|
|
|
"max_ttl": &framework.FieldSchema{
|
|
|
|
Type: framework.TypeDurationSecond,
|
2016-06-08 15:35:09 +00:00
|
|
|
Default: 0,
|
2016-06-08 15:31:57 +00:00
|
|
|
Description: `Duration after which the issued credentials should not be allowed to be renewed`,
|
2016-06-08 07:18:26 +00:00
|
|
|
},
|
|
|
|
},
|
2015-11-18 16:25:42 +00:00
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2016-05-21 05:51:09 +00:00
|
|
|
logical.ReadOperation: b.pathLeaseRead,
|
2016-05-21 06:27:22 +00:00
|
|
|
logical.UpdateOperation: b.pathLeaseUpdate,
|
2015-11-18 16:25:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathConfigLeaseHelpSyn,
|
|
|
|
HelpDescription: pathConfigLeaseHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
// Sets the lease configuration parameters
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathLeaseUpdate(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2016-06-08 07:18:26 +00:00
|
|
|
entry, err := logical.StorageEntryJSON("config/lease", &configLease{
|
|
|
|
TTL: time.Second * time.Duration(d.Get("ttl").(int)),
|
2016-06-08 14:46:46 +00:00
|
|
|
MaxTTL: time.Second * time.Duration(d.Get("max_ttl").(int)),
|
2015-11-18 16:25:42 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := req.Storage.Put(ctx, entry); err != nil {
|
2015-11-18 16:25:42 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
// Returns the lease configuration parameters
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathLeaseRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2018-01-19 06:44:44 +00:00
|
|
|
lease, err := b.Lease(ctx, req.Storage)
|
2015-11-18 16:25:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if lease == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2016-06-08 14:46:46 +00:00
|
|
|
lease.TTL = lease.TTL / time.Second
|
|
|
|
lease.MaxTTL = lease.MaxTTL / time.Second
|
|
|
|
|
2015-11-18 16:25:42 +00:00
|
|
|
return &logical.Response{
|
2016-06-08 07:18:26 +00:00
|
|
|
Data: structs.New(lease).Map(),
|
2015-11-18 16:25:42 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
// Lease configuration information for the secrets issued by this backend
|
2015-11-18 16:25:42 +00:00
|
|
|
type configLease struct {
|
2016-06-08 07:18:26 +00:00
|
|
|
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"`
|
|
|
|
MaxTTL time.Duration `json:"max_ttl" structs:"max_ttl" mapstructure:"max_ttl"`
|
2015-11-18 16:25:42 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
var pathConfigLeaseHelpSyn = "Configure the lease parameters for generated credentials"
|
2015-11-18 16:25:42 +00:00
|
|
|
|
2016-06-08 07:18:26 +00:00
|
|
|
var pathConfigLeaseHelpDesc = `
|
|
|
|
Sets the ttl and max_ttl values for the secrets to be issued by this backend.
|
2016-06-08 15:31:57 +00:00
|
|
|
Both ttl and max_ttl takes in an integer number of seconds as input as well as
|
|
|
|
inputs like "1h".
|
2016-06-08 07:18:26 +00:00
|
|
|
`
|