-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Lease into the Backend configuration
- Loading branch information
Showing
6 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package nomad | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/fatih/structs" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/logical/framework" | ||
) | ||
|
||
func pathConfigLease(b *backend) *framework.Path { | ||
return &framework.Path{ | ||
Pattern: "config/lease", | ||
Fields: map[string]*framework.FieldSchema{ | ||
"ttl": &framework.FieldSchema{ | ||
Type: framework.TypeDurationSecond, | ||
Default: 0, | ||
Description: "Duration before which the issued token needs renewal", | ||
}, | ||
"max_ttl": &framework.FieldSchema{ | ||
Type: framework.TypeDurationSecond, | ||
Default: 0, | ||
Description: `Duration after which the issued token should not be allowed to be renewed`, | ||
}, | ||
}, | ||
|
||
Callbacks: map[logical.Operation]framework.OperationFunc{ | ||
logical.ReadOperation: b.pathLeaseRead, | ||
logical.UpdateOperation: b.pathLeaseUpdate, | ||
}, | ||
|
||
HelpSynopsis: pathConfigLeaseHelpSyn, | ||
HelpDescription: pathConfigLeaseHelpDesc, | ||
} | ||
} | ||
|
||
// Sets the lease configuration parameters | ||
func (b *backend) pathLeaseUpdate(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(entry); err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
// Returns the lease configuration parameters | ||
func (b *backend) pathLeaseRead(req *logical.Request, data *framework.FieldData) (*logical.Response, error) { | ||
lease, err := b.Lease(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 tokens" | ||
|
||
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". | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters