Skip to content

Commit 04add34

Browse files
committed
libs/auth/storage: use CLI's FileTokenCache in ResolveCache
The file factory was calling the SDK's cache.NewFileTokenCache(), which is being phased out in favor of the CLI's own storage.NewFileTokenCache(ctx) imported in #5056. Route ResolveCache through it so that legacy and plaintext modes share a single file cache implementation owned by the CLI. Co-authored-by: Isaac
1 parent 0dd0ea6 commit 04add34

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

libs/auth/storage/cache.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ import (
1111
// so unit tests can inject stubs without hitting the real OS keyring or
1212
// filesystem. Production code uses defaultCacheFactories().
1313
type cacheFactories struct {
14-
newFile func() (cache.TokenCache, error)
14+
newFile func(context.Context) (cache.TokenCache, error)
1515
newKeyring func() cache.TokenCache
1616
}
1717

1818
// defaultCacheFactories returns the production factory set.
19-
// newFile is wrapped in a closure because cache.NewFileTokenCache is variadic
20-
// (func(...FileTokenCacheOption)) and cannot satisfy the non-variadic field type
21-
// by direct reference. The closure calls it with no options (SDK defaults).
2219
func defaultCacheFactories() cacheFactories {
2320
return cacheFactories{
24-
newFile: func() (cache.TokenCache, error) { return cache.NewFileTokenCache() },
21+
newFile: func(ctx context.Context) (cache.TokenCache, error) { return NewFileTokenCache(ctx) },
2522
newKeyring: NewKeyringCache,
2623
}
2724
}
@@ -53,7 +50,7 @@ func resolveCacheWith(ctx context.Context, override StorageMode, f cacheFactorie
5350
case StorageModeLegacy, StorageModePlaintext:
5451
// Plaintext currently maps to the file cache; a dedicated
5552
// plaintext backend (no host-keyed dual-writes) is a follow-up.
56-
c, err := f.newFile()
53+
c, err := f.newFile(ctx)
5754
if err != nil {
5855
return nil, "", fmt.Errorf("open file token cache: %w", err)
5956
}

libs/auth/storage/cache_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package storage
22

33
import (
4+
"context"
45
"errors"
56
"path/filepath"
67
"testing"
@@ -22,7 +23,7 @@ func (stubCache) Lookup(string) (*oauth2.Token, error) { return nil, cache.ErrNo
2223
func fakeFactories(t *testing.T) cacheFactories {
2324
t.Helper()
2425
return cacheFactories{
25-
newFile: func() (cache.TokenCache, error) { return stubCache{source: "file"}, nil },
26+
newFile: func(context.Context) (cache.TokenCache, error) { return stubCache{source: "file"}, nil },
2627
newKeyring: func() cache.TokenCache { return stubCache{source: "keyring"} },
2728
}
2829
}
@@ -104,7 +105,7 @@ func TestResolveCache_FileFactoryErrorPropagates(t *testing.T) {
104105
ctx := t.Context()
105106
boom := errors.New("disk full")
106107
factories := cacheFactories{
107-
newFile: func() (cache.TokenCache, error) { return nil, boom },
108+
newFile: func(context.Context) (cache.TokenCache, error) { return nil, boom },
108109
newKeyring: func() cache.TokenCache { return stubCache{source: "keyring"} },
109110
}
110111

0 commit comments

Comments
 (0)