Plugins: Refactor kvstore usage in signing keys and angular patterns (#73154)
* Initial refactoring work for plugins kvstore * Replace implementations for keystore and angularstore * Cleanup * add interface check * lint * fix storeKeyGetter not being called in namespacedstore set * Fix tests * Comments * Add tests * Fix invalid cap in ListKeys when store is empty * Update docstrings * Add setLastUpdatedOnDelete * Renamed DefaultStoreKeyGetterFunc, add TestDefaultStoreKeyGetter * Sort imports * PR review: removed last_updated key * PR review: Removed setLastUpdatedOnDelete * Re-added relevant tests * PR review: Removed SingleKeyStore * PR review: Removed custom marshaling support * Renamed marshaler.go to marshal.go * PR review: removed unused interfaces * PR review: Moved marshal into namespacedstore.go * PR review: removed storekeygetter * Removed unused file cachekvstore.go * Renamed NamespacedStore to CacheKvStore * removed todo
This commit is contained in:
@@ -101,7 +101,7 @@ func (kr *KeyRetriever) updateKeys(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !kr.cfg.PluginForcePublicKeyDownload && time.Since(*lastUpdated) < publicKeySyncInterval {
|
||||
if !kr.cfg.PluginForcePublicKeyDownload && time.Since(lastUpdated) < publicKeySyncInterval {
|
||||
// Cache is still valid
|
||||
return nil
|
||||
}
|
||||
@@ -170,15 +170,13 @@ func (kr *KeyRetriever) downloadKeys(ctx context.Context) error {
|
||||
// Delete keys that are no longer in the API
|
||||
for _, key := range cachedKeys {
|
||||
if !shouldKeep[key] {
|
||||
err = kr.kv.Del(ctx, key)
|
||||
err = kr.kv.Delete(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the last updated timestamp
|
||||
return kr.kv.SetLastUpdated(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kr *KeyRetriever) ensureKeys(ctx context.Context) error {
|
||||
|
||||
@@ -79,7 +79,7 @@ func Test_PublicKeyUpdate(t *testing.T) {
|
||||
defer v.lock.Unlock()
|
||||
ti, err := v.kv.GetLastUpdated(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Less(t, time.Time{}, *ti)
|
||||
require.Less(t, time.Time{}, ti)
|
||||
})
|
||||
|
||||
t.Run("it should remove old keys", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user