Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
PurgeIfEquals
Browse files Browse the repository at this point in the history
Signed-off-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
EngHabu committed Apr 29, 2024
1 parent aa5e6c6 commit 504042c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 15 additions & 1 deletion pkg/pkce/token_cache_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 504042c

Please sign in to comment.