Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34a77d5

Browse files
committed
Refactor key cache initialization and retrieval
- Simplify error handling by removing redundant checks in `newCache`.- Ensure `Latest` returns appropriate errors for key cache state.- Update tests to align with new error handling logic.
1 parenta8e7140 commit34a77d5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

‎coderd/cryptokeys/dbkeycache.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func NewDBKeyCache(ctx context.Context, logger slog.Logger, db database.Store, f
3939
for_,opt:=rangeopts {
4040
opt(d)
4141
}
42+
4243
err:=d.newCache(ctx)
4344
iferr!=nil {
4445
returnnil,xerrors.Errorf("new cache: %w",err)
@@ -115,6 +116,14 @@ func (d *DBKeyCache) Latest(ctx context.Context) (database.CryptoKey, error) {
115116
return database.CryptoKey{},xerrors.Errorf("new cache: %w",err)
116117
}
117118

119+
iflen(d.cache)==0 {
120+
return database.CryptoKey{},ErrKeyNotFound
121+
}
122+
123+
if!d.latestKey.IsActive(now) {
124+
return database.CryptoKey{},ErrKeyInvalid
125+
}
126+
118127
returnd.latestKey,nil
119128
}
120129

@@ -135,12 +144,7 @@ func (d *DBKeyCache) newCache(ctx context.Context) error {
135144
iferr!=nil {
136145
returnxerrors.Errorf("get crypto keys by feature: %w",err)
137146
}
138-
iflen(keys)==0 {
139-
returnErrKeyNotFound
140-
}
141-
142147
cache:=toMap(keys)
143-
144148
varlatest database.CryptoKey
145149
for_,key:=rangekeys {
146150
if!key.IsActive(now) {
@@ -150,10 +154,6 @@ func (d *DBKeyCache) newCache(ctx context.Context) error {
150154
break
151155
}
152156

153-
iflatest.IsInvalid(now) {
154-
returnErrKeyInvalid
155-
}
156-
157157
d.cache=cache
158158
d.latestKey=latest
159159
returnnil

‎coderd/cryptokeys/dbkeycache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestDBKeyCache(t *testing.T) {
3131
)
3232

3333
_,err:=cryptokeys.NewDBKeyCache(ctx,logger,db,database.CryptoKeyFeatureWorkspaceApps,withClock(clock))
34-
require.ErrorIs(t,err,cryptokeys.ErrKeyNotFound)
34+
require.NoError(t,err)
3535
})
3636

3737
t.Run("Version",func(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp