Skip to content

Commit

Permalink
Merge 398ad59 into a7fc664
Browse files Browse the repository at this point in the history
  • Loading branch information
eapolinario authored Oct 30, 2023
2 parents a7fc664 + 398ad59 commit 160a457
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion flyteidl/clients/go/admin/deviceflow/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ type DeviceAccessTokenRequest struct {

type DeviceAccessTokenResponse struct {
oauth2.Token
Error string `json:"error"`
Error string `json:"error"`
ExpiresIn int64 `json:"expires_in"` // relative seconds from now
}
6 changes: 4 additions & 2 deletions flyteidl/clients/go/admin/deviceflow/token_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ func (t TokenOrchestrator) PollTokenEndpoint(ctx context.Context, tokReq DeviceA
// Unmarshalled response if it contains an error then check if we need to increase the polling interval
if len(tokResp.Error) > 0 {
if tokResp.Error == errSlowDown || tokResp.Error == errAuthPending {
pollInterval = pollInterval * 2

logger.Debugf(ctx, "going to poll again due to error %v", tokResp.Error)

Check warning on line 128 in flyteidl/clients/go/admin/deviceflow/token_orchestrator.go

View check run for this annotation

Codecov / codecov/patch

flyteidl/clients/go/admin/deviceflow/token_orchestrator.go#L128

Added line #L128 was not covered by tests
} else {
return nil, fmt.Errorf("oauth error : %v", tokResp.Error)
}
} else {
if secs := tokResp.ExpiresIn; secs > 0 {
tokResp.Token.Expiry = time.Now().Add(time.Duration(secs) * time.Second)
}
// Got the auth token in the response and save it in the cache
err = t.TokenCache.SaveToken(&tokResp.Token)
// Saving into the cache is only considered to be a warning in this case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestFetchFromAuthFlow(t *testing.T) {
Token: oauth2.Token{
AccessToken: "access_token",
},
ExpiresIn: 300,
}
darBytes, err := json.Marshal(dar)
assert.Nil(t, err)
Expand Down Expand Up @@ -121,5 +122,6 @@ func TestFetchFromAuthFlow(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, authToken)
assert.Equal(t, "access_token", authToken.AccessToken)
assert.True(t, authToken.Expiry.After(time.Now().Add(time.Second*200)))
})
}

0 comments on commit 160a457

Please sign in to comment.