From e94e2d77b826790abd6a254bcc9be0ef60666c1d Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Fri, 27 Oct 2023 17:36:30 -0700 Subject: [PATCH 1/3] Added unmarshal attribute for expires_in for device flow auth token Signed-off-by: Eduardo Apolinario --- flyteidl/clients/go/admin/deviceflow/payload.go | 1 + flyteidl/clients/go/admin/deviceflow/token_orchestrator.go | 6 ++++-- .../clients/go/admin/deviceflow/token_orchestrator_test.go | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/flyteidl/clients/go/admin/deviceflow/payload.go b/flyteidl/clients/go/admin/deviceflow/payload.go index 656e1a88d8..0aab348b29 100644 --- a/flyteidl/clients/go/admin/deviceflow/payload.go +++ b/flyteidl/clients/go/admin/deviceflow/payload.go @@ -41,4 +41,5 @@ type DeviceAccessTokenRequest struct { type DeviceAccessTokenResponse struct { oauth2.Token Error string `json:"error"` + ExpiresIn int64 `json:"expires_in"` // relative seconds from now } diff --git a/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go b/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go index fc4f1d3786..2370b6f456 100644 --- a/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go +++ b/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go @@ -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) } 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. diff --git a/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go b/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go index 3ecbeb746e..50d19c0b93 100644 --- a/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go +++ b/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go @@ -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) @@ -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))) }) } From 398ad597ab90bcf2b7f6cee67a1a1862c8f5f4e3 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Mon, 30 Oct 2023 10:18:16 -0700 Subject: [PATCH 2/3] Lint Signed-off-by: Eduardo Apolinario --- flyteidl/clients/go/admin/deviceflow/payload.go | 4 ++-- flyteidl/clients/go/admin/deviceflow/token_orchestrator.go | 4 ++-- .../clients/go/admin/deviceflow/token_orchestrator_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flyteidl/clients/go/admin/deviceflow/payload.go b/flyteidl/clients/go/admin/deviceflow/payload.go index 0aab348b29..38e8b5502f 100644 --- a/flyteidl/clients/go/admin/deviceflow/payload.go +++ b/flyteidl/clients/go/admin/deviceflow/payload.go @@ -40,6 +40,6 @@ type DeviceAccessTokenRequest struct { type DeviceAccessTokenResponse struct { oauth2.Token - Error string `json:"error"` - ExpiresIn int64 `json:"expires_in"` // relative seconds from now + Error string `json:"error"` + ExpiresIn int64 `json:"expires_in"` // relative seconds from now } diff --git a/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go b/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go index 2370b6f456..e934ec6949 100644 --- a/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go +++ b/flyteidl/clients/go/admin/deviceflow/token_orchestrator.go @@ -125,12 +125,12 @@ 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 { - logger.Debugf(ctx, "going to poll again due to error %v", tokResp.Error) + logger.Debugf(ctx, "going to poll again due to error %v", tokResp.Error) } else { return nil, fmt.Errorf("oauth error : %v", tokResp.Error) } } else { - if secs := tokResp.ExpiresIn; secs > 0 { + 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 diff --git a/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go b/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go index 50d19c0b93..b88526e02d 100644 --- a/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go +++ b/flyteidl/clients/go/admin/deviceflow/token_orchestrator_test.go @@ -87,7 +87,7 @@ func TestFetchFromAuthFlow(t *testing.T) { Token: oauth2.Token{ AccessToken: "access_token", }, - ExpiresIn: 300, + ExpiresIn: 300, } darBytes, err := json.Marshal(dar) assert.Nil(t, err) @@ -122,6 +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))) + assert.True(t, authToken.Expiry.After(time.Now().Add(time.Second*200))) }) } From 712dbc4c061199549c58ad9383204d0ed88137aa Mon Sep 17 00:00:00 2001 From: Yee Hing Tong Date: Mon, 15 Apr 2024 15:32:58 -0700 Subject: [PATCH 3/3] empty Signed-off-by: Yee Hing Tong