kvstore

package
v0.0.1-test Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QuitOnPluginStartupFailureKey = "quit_on_secrets_plugin_startup_failure"
	PluginNamespace               = "secretsmanagerplugin"
	DataSourceSecretType          = "datasource"
)
View Source
const (
	// Wildcard to query all organizations
	AllOrganizations = -1
)

Variables

This section is empty.

Functions

func EvaluateRemoteSecretsPlugin

func EvaluateRemoteSecretsPlugin(ctx context.Context, mg plugins.SecretsPluginManager, cfg *setting.Cfg) error

func GetNamespacedKVStore

func GetNamespacedKVStore(kv kvstore.KVStore) *kvstore.NamespacedKVStore

func HasPluginStarted

func HasPluginStarted(ctx context.Context, mg plugins.SecretsPluginManager) bool

func IsPluginStartupErrorFatal

func IsPluginStartupErrorFatal(ctx context.Context, kvstore *kvstore.NamespacedKVStore) (bool, error)

func NewFakeFeatureToggles

func NewFakeFeatureToggles(t *testing.T, returnValue bool) featuremgmt.FeatureToggles

func NewFakeSecretsPluginManager

func NewFakeSecretsPluginManager(t *testing.T, shouldFailOnStart bool) plugins.SecretsPluginManager

func ReplaceFallback

func ReplaceFallback(t *testing.T, kv SecretsKVStore, fb SecretsKVStore) error

func ResetPlugin

func ResetPlugin()

func SetPluginStartupErrorFatal

func SetPluginStartupErrorFatal(ctx context.Context, kvstore *kvstore.NamespacedKVStore, isFatal bool) error

func SetupFatalCrashTest

func SetupFatalCrashTest(
	t *testing.T,
	shouldFailOnStart bool,
	isPluginErrorFatal bool,
	isBackwardsCompatDisabled bool,
) (fatalCrashTestFields, error)

func SetupTestConfig

func SetupTestConfig(t *testing.T) *setting.Cfg

Types

type CachedKVStore

type CachedKVStore struct {
	// contains filtered or unexported fields
}

func WithCache

func WithCache(store SecretsKVStore, defaultExpiration time.Duration, cleanupInterval time.Duration) *CachedKVStore

func (*CachedKVStore) Del

func (kv *CachedKVStore) Del(ctx context.Context, orgId int64, namespace string, typ string) error

func (*CachedKVStore) Get

func (kv *CachedKVStore) Get(ctx context.Context, orgId int64, namespace string, typ string) (string, bool, error)

func (*CachedKVStore) GetAll

func (kv *CachedKVStore) GetAll(ctx context.Context) ([]Item, error)

func (*CachedKVStore) Keys

func (kv *CachedKVStore) Keys(ctx context.Context, orgId int64, namespace string, typ string) ([]Key, error)

func (*CachedKVStore) Rename

func (kv *CachedKVStore) Rename(ctx context.Context, orgId int64, namespace string, typ string, newNamespace string) error

func (*CachedKVStore) Set

func (kv *CachedKVStore) Set(ctx context.Context, orgId int64, namespace string, typ string, value string) error

type FakeSecretsKVStore

type FakeSecretsKVStore struct {
	// contains filtered or unexported fields
}

In memory kv store used for testing

func NewFakeSecretsKVStore

func NewFakeSecretsKVStore() *FakeSecretsKVStore

func (*FakeSecretsKVStore) Del

func (f *FakeSecretsKVStore) Del(ctx context.Context, orgId int64, namespace string, typ string) error

func (*FakeSecretsKVStore) DeletionError

func (f *FakeSecretsKVStore) DeletionError(shouldErr bool)

func (*FakeSecretsKVStore) Fallback

func (f *FakeSecretsKVStore) Fallback() SecretsKVStore

func (*FakeSecretsKVStore) Get

func (f *FakeSecretsKVStore) Get(ctx context.Context, orgId int64, namespace string, typ string) (string, bool, error)

func (*FakeSecretsKVStore) GetAll

func (f *FakeSecretsKVStore) GetAll(ctx context.Context) ([]Item, error)

func (*FakeSecretsKVStore) Keys

func (f *FakeSecretsKVStore) Keys(ctx context.Context, orgId int64, namespace string, typ string) ([]Key, error)

List all keys with an optional filter. If default values are provided, filter is not applied.

func (*FakeSecretsKVStore) Rename

func (f *FakeSecretsKVStore) Rename(ctx context.Context, orgId int64, namespace string, typ string, newNamespace string) error

func (*FakeSecretsKVStore) Set

func (f *FakeSecretsKVStore) Set(ctx context.Context, orgId int64, namespace string, typ string, value string) error

func (*FakeSecretsKVStore) SetFallback

func (f *FakeSecretsKVStore) SetFallback(store SecretsKVStore) error

type FixedKVStore

type FixedKVStore struct {
	OrgId     int64
	Namespace string
	Type      string
	// contains filtered or unexported fields
}

FixedKVStore is a SecretsKVStore wrapper with fixed orgId, namespace and type.

func With

func With(kv SecretsKVStore, orgId int64, namespace string, typ string) *FixedKVStore

WithType returns a kvstore wrapper with fixed orgId and type.

func (*FixedKVStore) Del

func (kv *FixedKVStore) Del(ctx context.Context) error

func (*FixedKVStore) Get

func (kv *FixedKVStore) Get(ctx context.Context) (string, bool, error)

func (*FixedKVStore) Keys

func (kv *FixedKVStore) Keys(ctx context.Context) ([]Key, error)

func (*FixedKVStore) Rename

func (kv *FixedKVStore) Rename(ctx context.Context, newNamespace string) error

func (*FixedKVStore) Set

func (kv *FixedKVStore) Set(ctx context.Context, value string) error

type Item

type Item struct {
	Id        int64
	OrgId     *int64
	Namespace *string
	Type      *string
	Value     string

	Created time.Time
	Updated time.Time
}

Item stored in k/v store.

func (*Item) TableName

func (i *Item) TableName() string

type Key

type Key struct {
	OrgId     int64
	Namespace string
	Type      string
}

func (*Key) TableName

func (i *Key) TableName() string

type SecretsKVStore

type SecretsKVStore interface {
	Get(ctx context.Context, orgId int64, namespace string, typ string) (string, bool, error)
	Set(ctx context.Context, orgId int64, namespace string, typ string, value string) error
	Del(ctx context.Context, orgId int64, namespace string, typ string) error
	Keys(ctx context.Context, orgId int64, namespace string, typ string) ([]Key, error)
	Rename(ctx context.Context, orgId int64, namespace string, typ string, newNamespace string) error
	GetAll(ctx context.Context) ([]Item, error)
}

SecretsKVStore is an interface for k/v store.

func GetUnwrappedStoreFromCache

func GetUnwrappedStoreFromCache(kv SecretsKVStore) (SecretsKVStore, error)

func ProvideService

func ProvideService(
	sqlStore sqlstore.Store,
	secretsService secrets.Service,
	pluginsManager plugins.SecretsPluginManager,
	kvstore kvstore.KVStore,
	features featuremgmt.FeatureToggles,
	cfg *setting.Cfg,
) (SecretsKVStore, error)

type SecretsKVStorePlugin

type SecretsKVStorePlugin struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SecretsKVStorePlugin provides a key/value store backed by the Grafana plugin gRPC interface

func NewFakePluginSecretsKVStore

func NewFakePluginSecretsKVStore(t *testing.T, features featuremgmt.FeatureToggles, fallback SecretsKVStore) *SecretsKVStorePlugin

func NewPluginSecretsKVStore

func NewPluginSecretsKVStore(
	secretsPlugin smp.SecretsManagerPlugin,
	secretsService secrets.Service,
	kvstore *kvstore.NamespacedKVStore,
	features featuremgmt.FeatureToggles,
	fallback SecretsKVStore,
	logger log.Logger,
) *SecretsKVStorePlugin

func (*SecretsKVStorePlugin) Del

func (kv *SecretsKVStorePlugin) Del(ctx context.Context, orgId int64, namespace string, typ string) error

Del deletes an item from the store.

func (*SecretsKVStorePlugin) Fallback

func (kv *SecretsKVStorePlugin) Fallback() SecretsKVStore

func (*SecretsKVStorePlugin) Get

func (kv *SecretsKVStorePlugin) Get(ctx context.Context, orgId int64, namespace string, typ string) (string, bool, error)

Get an item from the store If it is the first time a secret has been retrieved and backwards compatibility is disabled, mark plugin startup errors fatal

func (*SecretsKVStorePlugin) GetAll

func (kv *SecretsKVStorePlugin) GetAll(ctx context.Context) ([]Item, error)

func (*SecretsKVStorePlugin) Keys

func (kv *SecretsKVStorePlugin) Keys(ctx context.Context, orgId int64, namespace string, typ string) ([]Key, error)

Keys get all keys for a given namespace. To query for all organizations the constant 'kvstore.AllOrganizations' can be passed as orgId.

func (*SecretsKVStorePlugin) Rename

func (kv *SecretsKVStorePlugin) Rename(ctx context.Context, orgId int64, namespace string, typ string, newNamespace string) error

Rename an item in the store

func (*SecretsKVStorePlugin) Set

func (kv *SecretsKVStorePlugin) Set(ctx context.Context, orgId int64, namespace string, typ string, value string) error

Set an item in the store If it is the first time a secret has been set and backwards compatibility is disabled, mark plugin startup errors fatal

func (*SecretsKVStorePlugin) WithFallbackEnabled

func (kv *SecretsKVStorePlugin) WithFallbackEnabled(fn func() error) error

type SecretsKVStoreSQL

type SecretsKVStoreSQL struct {
	// contains filtered or unexported fields
}

SecretsKVStoreSQL provides a key/value store backed by the Grafana database

func NewFakeSQLSecretsKVStore

func NewFakeSQLSecretsKVStore(t *testing.T) *SecretsKVStoreSQL

func NewSQLSecretsKVStore

func NewSQLSecretsKVStore(sqlStore sqlstore.Store, secretsService secrets.Service, logger log.Logger) *SecretsKVStoreSQL

func (*SecretsKVStoreSQL) Del

func (kv *SecretsKVStoreSQL) Del(ctx context.Context, orgId int64, namespace string, typ string) error

Del deletes an item from the store.

func (*SecretsKVStoreSQL) Get

func (kv *SecretsKVStoreSQL) Get(ctx context.Context, orgId int64, namespace string, typ string) (string, bool, error)

Get an item from the store

func (*SecretsKVStoreSQL) GetAll

func (kv *SecretsKVStoreSQL) GetAll(ctx context.Context) ([]Item, error)

GetAll this returns all the secrets stored in the database. This is not part of the kvstore interface as we only need it for migration from sql to plugin at this moment

func (*SecretsKVStoreSQL) Keys

func (kv *SecretsKVStoreSQL) Keys(ctx context.Context, orgId int64, namespace string, typ string) ([]Key, error)

Keys get all keys for a given namespace. To query for all organizations the constant 'kvstore.AllOrganizations' can be passed as orgId.

func (*SecretsKVStoreSQL) Rename

func (kv *SecretsKVStoreSQL) Rename(ctx context.Context, orgId int64, namespace string, typ string, newNamespace string) error

Rename an item in the store

func (*SecretsKVStoreSQL) Set

func (kv *SecretsKVStoreSQL) Set(ctx context.Context, orgId int64, namespace string, typ string, value string) error

Set an item in the store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL