From 29378cfb46a4c98d00dafa164a11751d5ec09d3f Mon Sep 17 00:00:00 2001 From: youhwsh Date: Mon, 20 May 2019 20:52:51 +0800 Subject: [PATCH] add start time in IAMTokenInfo --- bluemix/configuration/core_config/iam_token.go | 5 ++++- bluemix/configuration/core_config/iam_token_test.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bluemix/configuration/core_config/iam_token.go b/bluemix/configuration/core_config/iam_token.go index 4f7af68f..10e97a98 100644 --- a/bluemix/configuration/core_config/iam_token.go +++ b/bluemix/configuration/core_config/iam_token.go @@ -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 { @@ -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 { @@ -54,6 +56,7 @@ func NewIAMTokenInfo(token string) IAMTokenInfo { ret := t.IAMTokenInfo ret.Expiry = t.Expiry.Time() + ret.IssueAt = t.IssueAt.Time() return ret } diff --git a/bluemix/configuration/core_config/iam_token_test.go b/bluemix/configuration/core_config/iam_token_test.go index 088af1cf..27433b6c 100644 --- a/bluemix/configuration/core_config/iam_token_test.go +++ b/bluemix/configuration/core_config/iam_token_test.go @@ -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 {