Skip to content

Commit 43dfa2e

Browse files
VaishnaviGopalhkantare
authored andcommitted
retries added while fetching user details
1 parent 63fb775 commit 43dfa2e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ibm/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ func (c *Config) ClientSession() (interface{}, error) {
946946
}
947947

948948
}
949-
userConfig, err := fetchUserDetails(sess.BluemixSession, c.Generation)
949+
userConfig, err := fetchUserDetails(sess.BluemixSession, c.Generation, c.RetryCount)
950950
if err != nil {
951951
session.bmxUserFetchErr = fmt.Errorf("Error occured while fetching account user details: %q", err)
952952
}
@@ -1692,7 +1692,7 @@ func authenticateCF(sess *bxsession.Session) error {
16921692
return tokenRefresher.AuthenticateAPIKey(config.BluemixAPIKey)
16931693
}
16941694

1695-
func fetchUserDetails(sess *bxsession.Session, generation int) (*UserConfig, error) {
1695+
func fetchUserDetails(sess *bxsession.Session, generation, retries int) (*UserConfig, error) {
16961696
config := sess.Config
16971697
user := UserConfig{}
16981698
var bluemixToken string
@@ -1708,6 +1708,12 @@ func fetchUserDetails(sess *bxsession.Session, generation int) (*UserConfig, err
17081708
})
17091709
//TODO validate with key
17101710
if err != nil && !strings.Contains(err.Error(), "key is of invalid type") {
1711+
if retries > 0 {
1712+
if config.BluemixAPIKey != "" {
1713+
_ = authenticateAPIKey(sess)
1714+
return fetchUserDetails(sess, generation, retries-1)
1715+
}
1716+
}
17111717
return &user, err
17121718
}
17131719
claims := token.Claims.(jwt.MapClaims)

0 commit comments

Comments
 (0)