Skip to content

Commit

Permalink
Lock before FindByKey
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Sep 21, 2024
1 parent 033b916 commit cd8ef50
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/usecases/credentialplugin/get_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ func (u *GetToken) Do(ctx context.Context, in Input) error {
if in.GrantOptionSet.ROPCOption != nil {
tokenCacheKey.Username = in.GrantOptionSet.ROPCOption.Username
}

u.Logger.V(1).Infof("acquiring the lock of token cache")
lock, err := u.TokenCacheRepository.Lock(in.TokenCacheDir, tokenCacheKey)
if err != nil {
return fmt.Errorf("could not lock the token cache: %w", err)
}
defer func() {
u.Logger.V(1).Infof("releasing the lock of token cache")
if err := lock.Close(); err != nil {
u.Logger.Printf("could not unlock the token cache: %s", err)
}
}()

cachedTokenSet, err := u.TokenCacheRepository.FindByKey(in.TokenCacheDir, tokenCacheKey)
if err != nil {
u.Logger.V(1).Infof("could not find a token cache: %s", err)
Expand Down Expand Up @@ -94,18 +107,6 @@ func (u *GetToken) Do(ctx context.Context, in Input) error {
}
}

u.Logger.V(1).Infof("acquiring the lock of token cache")
lock, err := u.TokenCacheRepository.Lock(in.TokenCacheDir, tokenCacheKey)
if err != nil {
return fmt.Errorf("could not lock the token cache: %w", err)
}
defer func() {
u.Logger.V(1).Infof("releasing the lock of token cache")
if err := lock.Close(); err != nil {
u.Logger.Printf("could not unlock the token cache: %s", err)
}
}()

authenticationInput := authentication.Input{
Provider: in.Provider,
GrantOptionSet: in.GrantOptionSet,
Expand Down

0 comments on commit cd8ef50

Please sign in to comment.