Skip to content

Commit

Permalink
Merge pull request #188 from YouHang/master
Browse files Browse the repository at this point in the history
add start time in IAMTokenInfo
  • Loading branch information
weieigao authored May 21, 2019
2 parents 97f1dfc + 29378cf commit 8983a1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bluemix/configuration/core_config/iam_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type IAMTokenInfo struct {
GrantType string `json:"grant_type"`
Scope string `json:"scope"`
Expiry time.Time
IssueAt time.Time
}

type AccountsInfo struct {
Expand All @@ -45,7 +46,8 @@ func NewIAMTokenInfo(token string) IAMTokenInfo {

var t struct {
IAMTokenInfo
Expiry types.UnixTime `json:"exp"`
Expiry types.UnixTime `json:"exp"`
IssueAt types.UnixTime `json:"iat"`
}
err = json.Unmarshal(tokenJSON, &t)
if err != nil {
Expand All @@ -54,6 +56,7 @@ func NewIAMTokenInfo(token string) IAMTokenInfo {

ret := t.IAMTokenInfo
ret.Expiry = t.Expiry.Time()
ret.IssueAt = t.IssueAt.Time()
return ret
}

Expand Down
5 changes: 5 additions & 0 deletions bluemix/configuration/core_config/iam_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestNewIAMTokenInfo(t *testing.T) {
assert.Equal(t, tokenInfo.Accounts.AccountID, "8d63fb1cc5e99e86dd7229dddffc05a5")
}
}
func TestIATandEXP(t *testing.T) {
tokenInfo := NewIAMTokenInfo(TestIAMTokenData[1])
assert.Equal(t, tokenInfo.IssueAt.Unix(), int64(1516174603))
assert.Equal(t, tokenInfo.Expiry.Unix(), int64(1516178203))
}

func TestUAATokenInfo(t *testing.T) {
for _, token := range TestUAATokenData {
Expand Down

0 comments on commit 8983a1c

Please sign in to comment.