Files
Giuseppe Guerra 2e67a9463d 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
2023-09-05 16:20:42 +02:00

44 lines
1.1 KiB
Go

package angularpatternsstore
import (
"context"
"time"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/services/pluginsintegration/cachekvstore"
)
type Service interface {
GetLastUpdated(ctx context.Context) (time.Time, error)
Get(ctx context.Context) (string, bool, error)
Set(ctx context.Context, value any) error
}
const (
kvNamespace = "plugin.angularpatterns"
keyPatterns = "angular_patterns"
)
// KVStoreService allows to cache GCOM angular patterns into the database, as a cache.
type KVStoreService struct {
*cachekvstore.CacheKvStore
}
var _ Service = (*KVStoreService)(nil)
func ProvideService(kv kvstore.KVStore) Service {
return &KVStoreService{
CacheKvStore: cachekvstore.NewCacheKvStore(kv, kvNamespace),
}
}
// Get returns the stored angular patterns from the underlying cachekvstore.
func (s *KVStoreService) Get(ctx context.Context) (string, bool, error) {
return s.CacheKvStore.Get(ctx, keyPatterns)
}
// Set stores the given angular patterns in the underlying cachekvstore.s
func (s *KVStoreService) Set(ctx context.Context, value any) error {
return s.CacheKvStore.Set(ctx, keyPatterns, value)
}