Skip to content

Commit

Permalink
token: avoid panic when expire_time is nil (#740)
Browse files Browse the repository at this point in the history
* token: avoid panic when expire_time is nil

Signed-off-by: Yoan Blanc <[email protected]>

* Update vault/resource_token.go

Co-authored-by: Becca Petrin <[email protected]>

* Update vault/resource_token.go

Co-authored-by: Becca Petrin <[email protected]>

* Update vault/resource_token.go

Co-authored-by: Becca Petrin <[email protected]>

Co-authored-by: Becca Petrin <[email protected]>
  • Loading branch information
greut and tyrannosaurus-becks authored May 11, 2020
1 parent aa8c962 commit 7d07921
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions vault/resource_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,23 @@ func tokenRead(d *schema.ResourceData, meta interface{}) error {
d.Set("encrypted_client_token", "")
}

issueTime, err := time.Parse(time.RFC3339Nano, resp.Data["issue_time"].(string))
issueTimeStr, ok := resp.Data["issue_time"].(string)
if !ok {
return fmt.Errorf("error issue_time is not a string, got %T", resp.Data["issue_time"])
}

issueTime, err := time.Parse(time.RFC3339Nano, issueTimeStr)
if err != nil {
return fmt.Errorf("error parsing issue_time: %s", err)
return fmt.Errorf("error parsing issue_time: %s, please format string like '2006-01-02T15:04:05.999999999Z07:00'", err)
}
d.Set("lease_started", issueTime.Format(time.RFC3339))

expireTime, err := time.Parse(time.RFC3339Nano, resp.Data["expire_time"].(string))
expireTimeStr, ok := resp.Data["expire_time"].(string)
if !ok {
return fmt.Errorf("error expire_time is %T", resp.Data["expire_time"])
}

expireTime, err := time.Parse(time.RFC3339Nano, expireTimeStr)
if err != nil {
return fmt.Errorf("error parsing expire_time: %s", err)
}
Expand Down

0 comments on commit 7d07921

Please sign in to comment.