Add wrapping through core and change to use TTL instead of Duration.

This commit is contained in:
Jeff Mitchell
2016-05-02 00:08:07 -04:00
parent 778d000b5f
commit 21c0e4ee42
15 changed files with 576 additions and 363 deletions

View File

@@ -54,9 +54,9 @@ type Request struct {
// request path with the MountPoint trimmed off.
MountPoint string
// WrapDuration contains the requested TTL of the token used to wrap the
// WrapTTL contains the requested TTL of the token used to wrap the
// response in a cubbyhole.
WrapDuration time.Duration
WrapTTL time.Duration
}
// Get returns a data field and guards for nil Data

View File

@@ -30,7 +30,7 @@ const (
type WrapInfo struct {
// Setting to non-zero specifies that the response should be wrapped.
// Specifies the desired TTL of the wrapping token.
Duration time.Duration
TTL time.Duration
// The token containing the wrapped response
Token string
@@ -132,6 +132,11 @@ func (r *Response) ClearWarnings() {
r.warnings = make([]string, 0, 1)
}
// Copies the warnings from the other response to this one
func (r *Response) CloneWarnings(other *Response) {
r.warnings = other.warnings
}
// IsError returns true if this response seems to indicate an error.
func (r *Response) IsError() bool {
return r != nil && len(r.Data) == 1 && r.Data["error"] != nil

View File

@@ -5,6 +5,7 @@ func SanitizeResponse(input *Response) *HTTPResponse {
Data: input.Data,
Warnings: input.Warnings(),
}
if input.Secret != nil {
logicalResp.LeaseID = input.Secret.LeaseID
logicalResp.Renewable = input.Secret.Renewable
@@ -32,6 +33,7 @@ type HTTPResponse struct {
Renewable bool `json:"renewable"`
LeaseDuration int `json:"lease_duration"`
Data map[string]interface{} `json:"data"`
WrapInfo *HTTPWrapInfo `json:"wrap_info"`
Warnings []string `json:"warnings"`
Auth *HTTPAuth `json:"auth"`
}
@@ -44,3 +46,8 @@ type HTTPAuth struct {
LeaseDuration int `json:"lease_duration"`
Renewable bool `json:"renewable"`
}
type HTTPWrapInfo struct {
Token string `json:"token"`
TTL int `json:"ttl"`
}