diff --git a/go.mod b/go.mod index b287ce9a..2fc09823 100644 --- a/go.mod +++ b/go.mod @@ -178,7 +178,7 @@ require ( ) replace ( - github.com/flyteorg/flyte/flyteidl => github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240427064045-c2a1e27e0a92 + github.com/flyteorg/flyte/flyteidl => github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240429144225-f947ff324417 github.com/flyteorg/flyte/flyteplugins => github.com/flyteorg/flyte/flyteplugins v1.11.1-b1.0.20240427064045-c2a1e27e0a92 github.com/flyteorg/flyte/flytepropeller => github.com/flyteorg/flyte/flytepropeller v1.11.1-b1.0.20240427064045-c2a1e27e0a92 github.com/flyteorg/flyte/flytestdlib => github.com/flyteorg/flyte/flytestdlib v1.11.1-b1.0.20240427064045-c2a1e27e0a92 diff --git a/go.sum b/go.sum index f829405c..4b60c447 100644 --- a/go.sum +++ b/go.sum @@ -352,8 +352,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240427064045-c2a1e27e0a92 h1:PnPX6Tic37883Rtsaq8Ov3xtljaWXw4eG9RfH9zO0oM= -github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240427064045-c2a1e27e0a92/go.mod h1:4nlOzFdnc+9cQMsaXJEECek3hkvKmo1RxpDAGiELOCo= +github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240429144225-f947ff324417 h1:hU/LX8HUmZ8N/155lZbTPdt2Wcm3/3kp2RjMo6JERSQ= +github.com/flyteorg/flyte/flyteidl v1.11.1-b1.0.20240429144225-f947ff324417/go.mod h1:4nlOzFdnc+9cQMsaXJEECek3hkvKmo1RxpDAGiELOCo= github.com/flyteorg/flyte/flyteplugins v1.11.1-b1.0.20240427064045-c2a1e27e0a92 h1:mtX9C2NSbrUUBoUFL2S5puQyHo4zuu6+b5VKam1vFUk= github.com/flyteorg/flyte/flyteplugins v1.11.1-b1.0.20240427064045-c2a1e27e0a92/go.mod h1:bnW+Jb8u60I7FlufsCu/nE7XZZOlY4m7ngWPA7YFnQc= github.com/flyteorg/flyte/flytepropeller v1.11.1-b1.0.20240427064045-c2a1e27e0a92 h1:kH0APNrAaNFoEj3RIXj2BKg1M86jX4HajjBRuHvbKqg= diff --git a/pkg/pkce/token_cache_keyring.go b/pkg/pkce/token_cache_keyring.go index 20343436..76d6dd79 100644 --- a/pkg/pkce/token_cache_keyring.go +++ b/pkg/pkce/token_cache_keyring.go @@ -21,8 +21,22 @@ type TokenCacheKeyringProvider struct { mu *sync.Mutex } -func (t *TokenCacheKeyringProvider) Purge() { +func (t *TokenCacheKeyringProvider) PurgeIfEquals(existing *oauth2.Token) (bool, error) { + t.Lock() + defer t.Unlock() + tokenJSON, err := keyring.Get(t.ServiceName, t.ServiceUser) + if err != nil { + return false, fmt.Errorf("failed to read token. Error: %w", err) + } + + if existingBytes, err := json.Marshal(existing); err != nil { + return false, fmt.Errorf("unable to marshal token to save in cache due to %w", err) + } else if tokenJSON != string(existingBytes) { + return false, nil + } + _ = keyring.Delete(t.ServiceName, t.ServiceUser) + return true, nil } func (t *TokenCacheKeyringProvider) Lock() {