Secrets: Implement secrets manager plugin fallback store (#54496)

* Refactor fallback to be isolated to plugin secret store

* Check for error value on replace fallback test helper

* Move ResetPlugin from test_helpers.go to plugin.go

* Add check to GetUnwrappedStoreFromCache

* Add fallback GetAll query to WithFallbackEnabled

* Add mutex lock to WithFallbackEnabled

* Add cache to fallback store

* Fix linter issues

* Fix linter issues

* Fix linter issues
This commit is contained in:
Guilherme Caulada
2022-09-02 12:39:18 -03:00
committed by GitHub
parent 6b197f3fa9
commit f4a35a4645
8 changed files with 147 additions and 90 deletions
+9 -11
View File
@@ -2,6 +2,7 @@ package kvstore
import (
"context"
"errors"
"fmt"
"time"
@@ -9,13 +10,15 @@ import (
"github.com/grafana/grafana/pkg/infra/log"
)
var errSecretStoreIsNotCached = errors.New("SecretsKVStore is not a CachedKVStore")
type CachedKVStore struct {
log log.Logger
cache *localcache.CacheService
store SecretsKVStore
}
func NewCachedKVStore(store SecretsKVStore, defaultExpiration time.Duration, cleanupInterval time.Duration) *CachedKVStore {
func WithCache(store SecretsKVStore, defaultExpiration time.Duration, cleanupInterval time.Duration) *CachedKVStore {
return &CachedKVStore{
log: log.New("secrets.kvstore"),
cache: localcache.New(defaultExpiration, cleanupInterval),
@@ -81,14 +84,9 @@ func (kv *CachedKVStore) GetAll(ctx context.Context) ([]Item, error) {
return kv.store.GetAll(ctx)
}
func (kv *CachedKVStore) Fallback() SecretsKVStore {
return kv.store.Fallback()
}
func (kv *CachedKVStore) SetFallback(store SecretsKVStore) error {
return kv.store.SetFallback(store)
}
func (kv *CachedKVStore) GetUnwrappedStore() SecretsKVStore {
return kv.store
func GetUnwrappedStoreFromCache(kv SecretsKVStore) (SecretsKVStore, error) {
if cache, ok := kv.(*CachedKVStore); ok {
return cache.store, nil
}
return nil, errSecretStoreIsNotCached
}