merged commit for plugin rework, storage bucket sql and proto, storage bucket secret rewrapping, storage bucket repository

This commit is contained in:
Danielle Miu authored and Timothy Messier committed 2023-05-31 12:18:13 +00:00
1 parent 38723f8112
commit a4a14fc7fc
66 files changed
+2332 -980

No files matched your search

+63 -3
View File
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/require"
@@ -44,14 +45,73 @@ func (c *plugin) SetTableName(n string) {
c.tableName = n
}
func testPlugin(t testing.TB, conn *db.DB, name string) *plugin {
// getTestOpts - iterate the inbound TestOptions and return a struct
func getTestOpts(opt ...TestOption) testOptions {
opts := getDefaultTestOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// TestOption - how Options are passed as arguments
type TestOption func(*testOptions)
// options = how options are represented
type testOptions struct {
withHostFlag bool
withStorageFlag bool
}
func getDefaultTestOptions() testOptions {
return testOptions{
withHostFlag: true,
withStorageFlag: false,
}
}
// WithHostFlag determines whether or not to enable the host flag for a test plugin
func WithHostFlag(flag bool) TestOption {
return func(o *testOptions) {
o.withHostFlag = flag
}
}
// WithStorageFlag determines whether or not to enable the storage flag for a test plugin
func WithStorageFlag(flag bool) TestOption {
return func(o *testOptions) {
o.withStorageFlag = flag
}
}
// TestPlugin creates a plugin and inserts it into the database. enables the "host" flag by default
//
// Supported options: WithHostFlag, WithStorageFlag
func TestPlugin(t testing.TB, conn *db.DB, name string, opt ...TestOption) *Plugin {
opts := getTestOpts(opt...)
t.Helper()
p := newPlugin(name)
id, err := db.NewPublicId("plg")
p := NewPlugin(WithName(name))
id, err := newPluginId()
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
wrapper := db.TestWrapper(t)
kmsCache := kms.TestKms(t, conn, wrapper)
ctx := context.Background()
repo, err := NewRepository(ctx, w, w, kmsCache)
require.NoError(t, err)
if opts.withHostFlag {
// add the host supported flag
repo.AddSupportFlag(context.Background(), p, PluginTypeHost)
}
if opts.withStorageFlag {
// add the storage supported flag
repo.AddSupportFlag(context.Background(), p, PluginTypeStorage)
}
return p
}