refact(plugin): Move host loopback plugin into internal/plugin/loopback

This commit is contained in:
Louis Ruch authored and Timothy Messier committed 2023-05-31 12:18:12 +00:00
1 parent 4c801cca18
commit 351444f1bd
28 files changed
+3435 -177

No files matched your search

+7 -2
View File
@@ -34,6 +34,7 @@ import (
kmsjob "github.com/hashicorp/boundary/internal/kms/job"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/scheduler/cleaner"
"github.com/hashicorp/boundary/internal/scheduler/job"
@@ -251,10 +252,14 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
}
switch enabledPlugin {
case base.EnabledPluginHostLoopback:
plg := pluginhost.NewWrappingPluginClient(pluginhost.NewLoopbackPlugin())
lp, err := loopback.NewLoopbackPlugin()
if err != nil {
return nil, fmt.Errorf("error creating loopback plugin: %w", err)
}
plg := loopback.NewWrappingPluginClient(lp)
opts := []host.Option{
host.WithDescription("Provides an initial loopback host plugin in Boundary"),
host.WithPublicId(conf.DevLoopbackHostPluginId),
host.WithPublicId(conf.DevLoopbackPluginId),
}
if _, err = conf.RegisterHostPlugin(ctx, "loopback", plg, opts...); err != nil {
return nil, err
@@ -25,6 +25,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
@@ -838,7 +839,7 @@ func TestCreate_Plugin(t *testing.T) {
plg := host.TestPlugin(t, conn, name)
pluginHostRepo := func() (*plugin.Repository, error) {
return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{
OnCreateCatalogFn: func(ctx context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
return nil, nil
},
@@ -1372,8 +1373,10 @@ func TestUpdate_Plugin(t *testing.T) {
name := "test"
plg := host.TestPlugin(t, conn, name)
lp, err := loopback.NewLoopbackPlugin()
require.NoError(t, err)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(plugin.NewLoopbackPlugin()),
plg.GetPublicId(): loopback.NewWrappingPluginClient(lp),
}
repoFn := func() (*static.Repository, error) {
@@ -25,6 +25,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
@@ -166,7 +167,7 @@ func TestGet_Plugin(t *testing.T) {
prefEndpoints := []string{"cidr:1.2.3.4", "cidr:2.3.4.5/24"}
plg := hostplugin.TestPlugin(t, conn, name)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
pluginRepoFn := func() (*plugin.Repository, error) {
return plugin.NewRepository(rw, rw, kms, sche, plgm)
@@ -380,7 +381,7 @@ func TestList_Plugin(t *testing.T) {
name := "test"
plg := hostplugin.TestPlugin(t, conn, name)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
pluginRepoFn := func() (*plugin.Repository, error) {
return plugin.NewRepository(rw, rw, kms, sche, plgm)
@@ -568,7 +569,7 @@ func TestDelete_Plugin(t *testing.T) {
name := "test"
plg := hostplugin.TestPlugin(t, conn, name)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
@@ -837,7 +838,7 @@ func TestCreate_Plugin(t *testing.T) {
plg := hostplugin.TestPlugin(t, conn, name)
plgRepoFn := func() (*plugin.Repository, error) {
return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{
OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
return nil, nil
},
@@ -1476,7 +1477,7 @@ func TestUpdate_Plugin(t *testing.T) {
name := "test"
plg := hostplugin.TestPlugin(t, conn, name)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
repoFn := func() (*static.Repository, error) {
@@ -24,6 +24,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/types/subtypes"
@@ -153,7 +154,7 @@ func TestGet_Plugin(t *testing.T) {
plg := hostplugin.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
rw := db.New(conn)
@@ -384,7 +385,7 @@ func TestList_Plugin(t *testing.T) {
org, proj := iam.TestScopes(t, iamRepo)
plg := hostplugin.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
rw := db.New(conn)
@@ -38,6 +38,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/server"
@@ -1368,7 +1369,7 @@ func TestAddTargetHostSources(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
pluginHs := plugin.TestSet(t, conn, kms, sche, pluginHc, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
})
ctx := context.Background()
@@ -1530,7 +1531,7 @@ func TestSetTargetHostSources(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
pluginHs := plugin.TestSet(t, conn, kms, sche, pluginHc, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
})
ctx := context.Background()
@@ -1680,7 +1681,7 @@ func TestRemoveTargetHostSources(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
pluginHs := plugin.TestSet(t, conn, kms, sche, pluginHc, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
})
ctx := context.Background()
@@ -2456,7 +2457,7 @@ func TestAuthorizeSession(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(plugin.TestPluginServer{
plg.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{
ListHostsFn: func(_ context.Context, req *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error) {
var setIds []string
for _, set := range req.GetSets() {
+1 -1
View File
@@ -612,7 +612,7 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
tc.b.DevOidcAccountId = DefaultTestOidcAccountId
tc.b.DevUnprivilegedPasswordAccountId = DefaultTestUnprivilegedPasswordAccountId
tc.b.DevUnprivilegedOidcAccountId = DefaultTestUnprivilegedOidcAccountId
tc.b.DevLoopbackHostPluginId = DefaultTestPluginId
tc.b.DevLoopbackPluginId = DefaultTestPluginId
tc.b.EnabledPlugins = append(tc.b.EnabledPlugins, base.EnabledPluginHostLoopback)