From 84ec15a45c5769a19b06262195591fa4ed6a2059 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Sun, 3 Jul 2022 20:38:29 -0500 Subject: [PATCH] Add noop storage plugin Add a storage plugin that doesn't store anything. This can be used by people who want to use Porter to install bundles, but don't ever care about seeing previously installed bundles. Signed-off-by: Carolyn Van Slyck --- pkg/porter/internal_plugins.go | 9 +++++ pkg/storage/plugins/noop/noop.go | 65 ++++++++++++++++++++++++++++++ pkg/storage/plugins/noop/plugin.go | 21 ++++++++++ 3 files changed, 95 insertions(+) create mode 100644 pkg/storage/plugins/noop/noop.go create mode 100644 pkg/storage/plugins/noop/plugin.go diff --git a/pkg/porter/internal_plugins.go b/pkg/porter/internal_plugins.go index 57f45328e..19765a2e5 100644 --- a/pkg/porter/internal_plugins.go +++ b/pkg/porter/internal_plugins.go @@ -7,6 +7,8 @@ import ( "fmt" "io" + "get.porter.sh/porter/pkg/storage/plugins/noop" + "get.porter.sh/porter/pkg/config" "get.porter.sh/porter/pkg/plugins" "get.porter.sh/porter/pkg/portercontext" @@ -129,6 +131,13 @@ func getInternalPlugins() map[string]InternalPlugin { return filesystem.NewPlugin(c, pluginCfg), nil }, }, + noop.PluginKey: { + Interface: storageplugins.PluginInterface, + ProtocolVersion: storageplugins.PluginProtocolVersion, + Create: func(c *config.Config, pluginCfg interface{}) (plugin.Plugin, error) { + return noop.NewPlugin(c.Context) + }, + }, mongodb.PluginKey: { Interface: storageplugins.PluginInterface, ProtocolVersion: storageplugins.PluginProtocolVersion, diff --git a/pkg/storage/plugins/noop/noop.go b/pkg/storage/plugins/noop/noop.go new file mode 100644 index 000000000..9a3cb4ffa --- /dev/null +++ b/pkg/storage/plugins/noop/noop.go @@ -0,0 +1,65 @@ +package noop + +import ( + "context" + + "get.porter.sh/porter/pkg/storage/plugins" + "go.mongodb.org/mongo-driver/bson" +) + +var ( + _ plugins.StorageProtocol = Store{} +) + +// Store implements a noop storage plugin. +type Store struct{} + +// NewStore creates a new storage plugin that does nothing. +func NewStore() Store { + return Store{} +} + +// Aggregate does nothing. +func (s Store) Aggregate(ctx context.Context, opts plugins.AggregateOptions) ([]bson.Raw, error) { + return nil, nil +} + +// EnsureIndex does nothing. +func (s Store) EnsureIndex(ctx context.Context, opts plugins.EnsureIndexOptions) error { + return nil +} + +// Count does nothing. +func (s Store) Count(ctx context.Context, opts plugins.CountOptions) (int64, error) { + return 0, nil +} + +// Find does nothing. +func (s Store) Find(ctx context.Context, opts plugins.FindOptions) ([]bson.Raw, error) { + return nil, nil +} + +// Insert does nothing +func (s Store) Insert(ctx context.Context, opts plugins.InsertOptions) error { + return nil +} + +// Patch does nothing +func (s Store) Patch(ctx context.Context, opts plugins.PatchOptions) error { + return nil +} + +// Remove does nothing +func (s Store) Remove(ctx context.Context, opts plugins.RemoveOptions) error { + return nil +} + +// Update does nothing +func (s Store) Update(ctx context.Context, opts plugins.UpdateOptions) error { + return nil +} + +// RemoveDatabase does nothing. +func (s Store) RemoveDatabase(ctx context.Context) error { + return nil +} diff --git a/pkg/storage/plugins/noop/plugin.go b/pkg/storage/plugins/noop/plugin.go new file mode 100644 index 000000000..683207f8c --- /dev/null +++ b/pkg/storage/plugins/noop/plugin.go @@ -0,0 +1,21 @@ +package noop + +import ( + "get.porter.sh/porter/pkg/portercontext" + "get.porter.sh/porter/pkg/storage/plugins" + "get.porter.sh/porter/pkg/storage/pluginstore" + "github.com/hashicorp/go-plugin" +) + +const PluginKey = plugins.PluginInterface + ".porter.noop" + +var _ plugins.StorageProtocol = Plugin{} + +type Plugin struct { + *Store +} + +func NewPlugin(c *portercontext.Context) (plugin.Plugin, error) { + impl := NewStore() + return pluginstore.NewPlugin(c, impl), nil +}