Merge pull request #1684 from hashicorp/issue-1683

Add extra nil check for an error response/use duration helper for TTL values
This commit is contained in:
Jeff Mitchell 2016-08-02 16:36:50 -04:00 committed by GitHub
commit c4992fa3e5
2 changed files with 4 additions and 3 deletions

View file

@ -232,7 +232,7 @@ func respondErrorCommon(w http.ResponseWriter, resp *logical.Response, err error
}
}
if resp != nil {
if resp != nil && resp.IsError(){
err = fmt.Errorf("%s", resp.Data["error"].(string))
}

View file

@ -10,6 +10,7 @@ import (
"github.com/armon/go-metrics"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/vault/helper/duration"
"github.com/hashicorp/vault/helper/jsonutil"
"github.com/hashicorp/vault/helper/locksutil"
"github.com/hashicorp/vault/helper/policyutil"
@ -1179,7 +1180,7 @@ func (ts *TokenStore) handleCreateCommon(
}
if data.ExplicitMaxTTL != "" {
dur, err := time.ParseDuration(data.ExplicitMaxTTL)
dur, err := duration.ParseDurationSecond(data.ExplicitMaxTTL)
if err != nil {
return logical.ErrorResponse(err.Error()), logical.ErrInvalidRequest
}
@ -1191,7 +1192,7 @@ func (ts *TokenStore) handleCreateCommon(
// Parse the TTL/lease if any
if data.TTL != "" {
dur, err := time.ParseDuration(data.TTL)
dur, err := duration.ParseDurationSecond(data.TTL)
if err != nil {
return logical.ErrorResponse(err.Error()), logical.ErrInvalidRequest
}