mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 16:47:01 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package rabbitmq
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/fatih/structs"
|
|
"github.com/hashicorp/vault/sdk/framework"
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
)
|
|
|
|
func pathConfigLease(b *backend) *framework.Path {
|
|
return &framework.Path{
|
|
Pattern: "config/lease",
|
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
OperationPrefix: operationPrefixRabbitMQ,
|
|
},
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
"ttl": {
|
|
Type: framework.TypeDurationSecond,
|
|
Default: 0,
|
|
Description: "Duration before which the issued credentials needs renewal",
|
|
},
|
|
"max_ttl": {
|
|
Type: framework.TypeDurationSecond,
|
|
Default: 0,
|
|
Description: `Duration after which the issued credentials should not be allowed to be renewed`,
|
|
},
|
|
},
|
|
|
|
Operations: map[logical.Operation]framework.OperationHandler{
|
|
logical.ReadOperation: &framework.PathOperation{
|
|
Callback: b.pathLeaseRead,
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
OperationVerb: "read",
|
|
OperationSuffix: "lease-configuration",
|
|
},
|
|
},
|
|
logical.UpdateOperation: &framework.PathOperation{
|
|
Callback: b.pathLeaseUpdate,
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
OperationVerb: "configure",
|
|
OperationSuffix: "lease",
|
|
},
|
|
},
|
|
},
|
|
|
|
HelpSynopsis: pathConfigLeaseHelpSyn,
|
|
HelpDescription: pathConfigLeaseHelpDesc,
|
|
}
|
|
}
|
|
|
|
// Sets the lease configuration parameters
|
|
func (b *backend) pathLeaseUpdate(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
entry, err := logical.StorageEntryJSON("config/lease", &configLease{
|
|
TTL: time.Second * time.Duration(d.Get("ttl").(int)),
|
|
MaxTTL: time.Second * time.Duration(d.Get("max_ttl").(int)),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := req.Storage.Put(ctx, entry); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
// Returns the lease configuration parameters
|
|
func (b *backend) pathLeaseRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
|
lease, err := b.Lease(ctx, req.Storage)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if lease == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
lease.TTL = lease.TTL / time.Second
|
|
lease.MaxTTL = lease.MaxTTL / time.Second
|
|
|
|
return &logical.Response{
|
|
Data: structs.New(lease).Map(),
|
|
}, nil
|
|
}
|
|
|
|
// Lease configuration information for the secrets issued by this backend
|
|
type configLease struct {
|
|
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"`
|
|
MaxTTL time.Duration `json:"max_ttl" structs:"max_ttl" mapstructure:"max_ttl"`
|
|
}
|
|
|
|
var pathConfigLeaseHelpSyn = "Configure the lease parameters for generated credentials"
|
|
|
|
var pathConfigLeaseHelpDesc = `
|
|
Sets the ttl and max_ttl values for the secrets to be issued by this backend.
|
|
Both ttl and max_ttl takes in an integer number of seconds as input as well as
|
|
inputs like "1h".
|
|
`
|