Skip to content

Commit

Permalink
Update token refresh logging
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi committed Jan 25, 2024
1 parent 4e32878 commit dab0f9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
13 changes: 7 additions & 6 deletions binding/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,14 @@ func (r *Client) send(rb func() (*http.Request, error)) (response *http.Response
err = liberr.Wrap(err)
return
}
} else if r.refreshToken(response.StatusCode) {
} else if r.refreshToken(response.StatusCode, request.URL.Path) {
unAuthErr := errors.New("401 Unauthorized")
if i < r.Retry {
Log.Info("|401| Unauthorized, refreshing auth token.")
token := api.Login{Refresh: r.token.Refresh}
refreshErr := r.Post(api.AuthRefreshRoot, &token) // calls itself.. ensure no deadlock/stacktoodeep
refreshErr := r.Post(api.AuthRefreshRoot, &token)
if refreshErr != nil {
Log.Error(err, "Token refresh failed.")
Log.Error(refreshErr, "Token refresh failed.")
time.Sleep(RetryDelay)
} else {
r.SetToken(token)
Expand Down Expand Up @@ -816,9 +817,9 @@ func (f *Field) disposition() (d string) {
return
}

func (r *Client) refreshToken(status int) (refresh bool) {
if status == 401 && r.token.Refresh != "" {
func (r *Client) refreshToken(status int, path string) (refresh bool) {
if status == 401 && !strings.HasSuffix(path, api.AuthRefreshRoot) && r.token.Refresh != "" {
refresh = true
}
return
}
}
2 changes: 0 additions & 2 deletions binding/richclient.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package binding

import (
"time"

"github.com/jortel/go-utils/logr"
"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/settings"
Expand Down
4 changes: 2 additions & 2 deletions test/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func PrepareRichClient() (richClient *binding.RichClient) {
panic(fmt.Sprintf("Cannot login to API: %v.", err.Error()))
}

// Disable HTTP requests retry for network-related errors to fail quickly.
richClient.Client.Retry = 1
// Disable HTTP requests retry for network-related errors to fail quickly.
richClient.Client.Retry = 1

return
}

0 comments on commit dab0f9e

Please sign in to comment.