From b1c28317788b1f3769bfe8527982dcf8f02e21e1 Mon Sep 17 00:00:00 2001 From: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:05:34 -0400 Subject: [PATCH 1/4] rework plugin/host_plugin sql and accompanying domain --- Makefile | 1 - internal/cmd/base/initial_resources.go | 22 +- internal/daemon/controller/common/common.go | 4 +- internal/daemon/controller/controller.go | 16 +- .../host_catalogs/host_catalog_service.go | 66 ++--- .../host_catalog_service_test.go | 148 +++++------ .../handlers/host_sets/host_set_service.go | 58 ++--- .../host_sets/host_set_service_test.go | 138 +++++----- .../controller/handlers/hosts/host_service.go | 28 +- .../handlers/hosts/host_service_test.go | 100 +++---- .../postgres/64/01_plugins_restructure.up.sql | 65 +++++ internal/host/plugin/host_address_test.go | 10 +- .../host/plugin/host_catalog_secret_test.go | 6 +- internal/host/plugin/host_catalog_test.go | 16 +- internal/host/plugin/host_set_member_test.go | 4 +- internal/host/plugin/host_set_test.go | 4 +- internal/host/plugin/host_test.go | 4 +- internal/host/plugin/immutable_fields_test.go | 8 +- .../plugin/job_orphaned_host_cleanup_test.go | 4 +- internal/host/plugin/job_set_sync_test.go | 8 +- internal/host/plugin/repository_host.go | 6 +- .../host/plugin/repository_host_catalog.go | 16 +- .../plugin/repository_host_catalog_test.go | 21 +- internal/host/plugin/repository_host_set.go | 14 +- .../host/plugin/repository_host_set_test.go | 18 +- internal/host/plugin/repository_host_test.go | 12 +- internal/host/plugin/rewrapping_test.go | 4 +- internal/host/plugin/testing.go | 6 +- internal/host/plugin/testing_test.go | 12 +- internal/plugin/host/doc.go | 7 - internal/plugin/host/immutable_fields_test.go | 79 ------ internal/plugin/host/store/plugin.pb.go | 246 ------------------ internal/plugin/host/testing.go | 24 -- internal/plugin/host/testing_test.go | 21 -- internal/plugin/{host => }/ids.go | 2 +- internal/plugin/immutable_fields_test.go | 26 +- internal/plugin/{host => }/options.go | 2 +- internal/plugin/{host => }/options_test.go | 2 +- internal/plugin/{host => }/plugin.go | 19 +- internal/plugin/{host => }/plugin_test.go | 6 +- internal/plugin/query.go | 5 + internal/plugin/{host => }/repository.go | 2 +- .../plugin/{host => }/repository_plugin.go | 27 +- .../{host => }/repository_plugin_test.go | 131 +++++++++- internal/plugin/{host => }/repository_test.go | 2 +- internal/plugin/store/plugin.pb.go | 101 +++++-- internal/plugin/testing.go | 6 +- internal/plugin/testing_test.go | 4 +- .../storage/plugin/host/store/v1/plugin.proto | 47 ---- .../storage/plugin/store/v1/plugin.proto | 28 +- 50 files changed, 750 insertions(+), 856 deletions(-) create mode 100644 internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql delete mode 100644 internal/plugin/host/doc.go delete mode 100644 internal/plugin/host/immutable_fields_test.go delete mode 100644 internal/plugin/host/store/plugin.pb.go delete mode 100644 internal/plugin/host/testing.go delete mode 100644 internal/plugin/host/testing_test.go rename internal/plugin/{host => }/ids.go (96%) rename internal/plugin/{host => }/options.go (98%) rename internal/plugin/{host => }/options_test.go (98%) rename internal/plugin/{host => }/plugin.go (78%) rename internal/plugin/{host => }/plugin_test.go (96%) create mode 100644 internal/plugin/query.go rename internal/plugin/{host => }/repository.go (99%) rename internal/plugin/{host => }/repository_plugin.go (84%) rename internal/plugin/{host => }/repository_plugin_test.go (65%) rename internal/plugin/{host => }/repository_test.go (99%) delete mode 100644 internal/proto/controller/storage/plugin/host/store/v1/plugin.proto diff --git a/Makefile b/Makefile index 608cf71934..cf259f225f 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,6 @@ protobuild: @protoc-go-inject-tag -input=./internal/host/store/host.pb.go @protoc-go-inject-tag -input=./internal/host/static/store/static.pb.go @protoc-go-inject-tag -input=./internal/host/plugin/store/host.pb.go - @protoc-go-inject-tag -input=./internal/plugin/host/store/plugin.pb.go @protoc-go-inject-tag -input=./internal/plugin/store/plugin.pb.go @protoc-go-inject-tag -input=./internal/authtoken/store/authtoken.pb.go @protoc-go-inject-tag -input=./internal/auth/store/account.pb.go diff --git a/internal/cmd/base/initial_resources.go b/internal/cmd/base/initial_resources.go index 6282e67c73..01dece9022 100644 --- a/internal/cmd/base/initial_resources.go +++ b/internal/cmd/base/initial_resources.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/boundary/internal/host/static" "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" "github.com/hashicorp/boundary/internal/target" "github.com/hashicorp/boundary/internal/target/tcp" "github.com/hashicorp/boundary/internal/types/scope" @@ -554,7 +554,7 @@ func (b *Server) CreateInitialTargetWithHostSources(ctx context.Context) (target // It also registers the plugin in the shared map of running plugins. Since // all boundary provided host plugins must have a name, a name is required // when calling RegisterHostPlugin and will be used even if WithName is provided. -func (b *Server) RegisterHostPlugin(ctx context.Context, name string, plg plgpb.HostPluginServiceClient, opt ...hostplugin.Option) (*hostplugin.Plugin, error) { +func (b *Server) RegisterHostPlugin(ctx context.Context, name string, hostClient plgpb.HostPluginServiceClient, opt ...plugin.Option) (*plugin.Plugin, error) { if name == "" { return nil, fmt.Errorf("no name provided when creating plugin.") } @@ -571,31 +571,33 @@ func (b *Server) RegisterHostPlugin(ctx context.Context, name string, plg plgpb. return nil, fmt.Errorf("error adding config keys to kms: %w", err) } - hpRepo, err := hostplugin.NewRepository(rw, rw, kmsCache) + hpRepo, err := plugin.NewRepository(rw, rw, kmsCache) if err != nil { return nil, fmt.Errorf("error creating host plugin repository: %w", err) } - plugin, err := hpRepo.LookupPluginByName(ctx, name) + plg, err := hpRepo.LookupPluginByName(ctx, name) if err != nil { return nil, fmt.Errorf("error looking up host plugin by name: %w", err) } - if plugin == nil { - opt = append(opt, hostplugin.WithName(name)) - plugin = hostplugin.NewPlugin(opt...) - plugin, err = hpRepo.CreatePlugin(ctx, plugin, opt...) + if plg == nil { + opt = append(opt, plugin.WithName(name)) + plg = plugin.NewPlugin(opt...) + plg, err = hpRepo.CreatePlugin(ctx, plg, opt...) if err != nil { return nil, fmt.Errorf("error creating host plugin: %w", err) } } + hpRepo.AddSupportFlag(ctx, plg, plugin.PluginTypeHost) + if b.HostPlugins == nil { b.HostPlugins = make(map[string]plgpb.HostPluginServiceClient) } - b.HostPlugins[plugin.GetPublicId()] = plg + b.HostPlugins[plg.GetPublicId()] = hostClient - return plugin, nil + return plg, nil } // unprivilegedDevUserRoleSetup adds dev user to the role that grants diff --git a/internal/daemon/controller/common/common.go b/internal/daemon/controller/common/common.go index 66b62dcb63..5d422e4ada 100644 --- a/internal/daemon/controller/common/common.go +++ b/internal/daemon/controller/common/common.go @@ -12,7 +12,7 @@ import ( pluginhost "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/server" "github.com/hashicorp/boundary/internal/session" ) @@ -28,7 +28,7 @@ type ( ServersRepoFactory func() (*server.Repository, error) StaticRepoFactory func() (*static.Repository, error) PluginHostRepoFactory func() (*pluginhost.Repository, error) - HostPluginRepoFactory func() (*hostplugin.Repository, error) + HostPluginRepoFactory func() (*plugin.Repository, error) ConnectionRepoFactory func() (*session.ConnectionRepository, error) WorkerAuthRepoStorageFactory func() (*server.WorkerAuthRepositoryStorage, error) ) diff --git a/internal/daemon/controller/controller.go b/internal/daemon/controller/controller.go index 39ee14a16c..8c9d153385 100644 --- a/internal/daemon/controller/controller.go +++ b/internal/daemon/controller/controller.go @@ -31,7 +31,7 @@ import ( "github.com/hashicorp/boundary/internal/kms" kmsjob "github.com/hashicorp/boundary/internal/kms/job" "github.com/hashicorp/boundary/internal/observability/event" - "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/scheduler/cleaner" "github.com/hashicorp/boundary/internal/scheduler/job" @@ -244,14 +244,14 @@ func New(ctx context.Context, conf *Config) (*Controller, error) { switch enabledPlugin { case base.EnabledPluginHostLoopback: plg := pluginhost.NewWrappingPluginClient(pluginhost.NewLoopbackPlugin()) - opts := []host.Option{ - host.WithDescription("Provides an initial loopback host plugin in Boundary"), - host.WithPublicId(conf.DevLoopbackHostPluginId), + opts := []iplugin.Option{ + iplugin.WithDescription("Provides an initial loopback host plugin in Boundary"), + iplugin.WithPublicId(conf.DevLoopbackHostPluginId), } if _, err = conf.RegisterHostPlugin(ctx, "loopback", plg, opts...); err != nil { return nil, err } - case base.EnabledPluginHostAzure, base.EnabledPluginHostAws: + case base.EnabledPluginHostAzure, base.EnabledPluginHostAws: // TODO: add pluginType := strings.ToLower(enabledPlugin.String()) client, cleanup, err := external_host_plugins.CreateHostPlugin( ctx, @@ -266,7 +266,7 @@ func New(ctx context.Context, conf *Config) (*Controller, error) { return nil, fmt.Errorf("error creating %s host plugin: %w", pluginType, err) } conf.ShutdownFuncs = append(conf.ShutdownFuncs, cleanup) - if _, err := conf.RegisterHostPlugin(ctx, pluginType, client, host.WithDescription(fmt.Sprintf("Built-in %s host plugin", enabledPlugin.String()))); err != nil { + if _, err := conf.RegisterHostPlugin(ctx, pluginType, client, iplugin.WithDescription(fmt.Sprintf("Built-in %s host plugin", enabledPlugin.String()))); err != nil { return nil, fmt.Errorf("error registering %s host plugin: %w", pluginType, err) } } @@ -344,8 +344,8 @@ func New(ctx context.Context, conf *Config) (*Controller, error) { c.PluginHostRepoFn = func() (*pluginhost.Repository, error) { return pluginhost.NewRepository(dbase, dbase, c.kms, c.scheduler, c.conf.HostPlugins) } - c.HostPluginRepoFn = func() (*host.Repository, error) { - return host.NewRepository(dbase, dbase, c.kms) + c.HostPluginRepoFn = func() (*iplugin.Repository, error) { + return iplugin.NewRepository(dbase, dbase, c.kms) } c.AuthTokenRepoFn = func() (*authtoken.Repository, error) { return authtoken.NewRepository(dbase, dbase, c.kms, diff --git a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service.go b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service.go index 298f804522..f663a7d3a2 100644 --- a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service.go +++ b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service.go @@ -17,12 +17,12 @@ import ( "github.com/hashicorp/boundary/internal/errors" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" "github.com/hashicorp/boundary/internal/host" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" pluginstore "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/perms" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/requests" "github.com/hashicorp/boundary/internal/types/action" "github.com/hashicorp/boundary/internal/types/resource" @@ -62,7 +62,7 @@ var ( resource.HostSet: host_sets.CollectionActions, resource.Host: hosts.CollectionActions, }, - plugin.Subtype: { + hostplugin.Subtype: { resource.HostSet: host_sets.CollectionActions, resource.Host: action.ActionSet{ action.List, @@ -179,8 +179,8 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs switch item.(type) { case *static.HostCatalog: subtype = static.Subtype - case *plugin.HostCatalog: - subtype = plugin.Subtype + case *hostplugin.HostCatalog: + subtype = hostplugin.Subtype } if subtype != "" { collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, item.GetPublicId()) @@ -191,7 +191,7 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs } } switch hc := item.(type) { - case *plugin.HostCatalog: + case *hostplugin.HostCatalog: if plgInfo, ok := pluginInfoMap[hc.GetPluginId()]; ok { outputOpts = append(outputOpts, handlers.WithPlugin(plgInfo)) } @@ -249,8 +249,8 @@ func (s Service) GetHostCatalog(ctx context.Context, req *pbs.GetHostCatalogRequ switch hc.(type) { case *static.HostCatalog: subtype = static.Subtype - case *plugin.HostCatalog: - subtype = plugin.Subtype + case *hostplugin.HostCatalog: + subtype = hostplugin.Subtype } if subtype != "" { collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId()) @@ -306,8 +306,8 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal switch hc.(type) { case *static.HostCatalog: subtype = static.Subtype - case *plugin.HostCatalog: - subtype = plugin.Subtype + case *hostplugin.HostCatalog: + subtype = hostplugin.Subtype } if subtype != "" { collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId()) @@ -369,8 +369,8 @@ func (s Service) UpdateHostCatalog(ctx context.Context, req *pbs.UpdateHostCatal switch hc.(type) { case *static.HostCatalog: subtype = static.Subtype - case *plugin.HostCatalog: - subtype = plugin.Subtype + case *hostplugin.HostCatalog: + subtype = hostplugin.Subtype } if subtype != "" { collectionActions, err := auth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap[subtype], authResults.Scope.Id, hc.GetPublicId()) @@ -421,7 +421,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, *plu return nil, nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id) } cat = hc - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginHostRepoFn() if err != nil { return nil, nil, err @@ -491,7 +491,7 @@ func (s Service) createStaticInRepo(ctx context.Context, projId string, item *pb return out, nil } -func (s Service) createPluginInRepo(ctx context.Context, projId string, req *pbs.CreateHostCatalogRequest) (*plugin.HostCatalog, *plugins.PluginInfo, error) { +func (s Service) createPluginInRepo(ctx context.Context, projId string, req *pbs.CreateHostCatalogRequest) (*hostplugin.HostCatalog, *plugins.PluginInfo, error) { const op = "host_catalogs.(Service).createPluginInRepo" item := req.GetItem() pluginId := item.GetPluginId() @@ -564,7 +564,7 @@ func (s Service) updateStaticInRepo(ctx context.Context, projId, id string, mask return out, nil } -func (s Service) updatePluginInRepo(ctx context.Context, projId, id string, mask []string, item *pb.HostCatalog) (*plugin.HostCatalog, *plugins.PluginInfo, error) { +func (s Service) updatePluginInRepo(ctx context.Context, projId, id string, mask []string, item *pb.HostCatalog) (*hostplugin.HostCatalog, *plugins.PluginInfo, error) { const op = "host_catalogs.(Service).updatePluginInRepo" h, err := toStoragePluginCatalog(ctx, projId, "", item) if err != nil { @@ -596,7 +596,7 @@ func (s Service) updateInRepo(ctx context.Context, projId string, req *pbs.Updat switch subtypes.SubtypeFromId(domain, req.GetId()) { case static.Subtype: hc, err = s.updateStaticInRepo(ctx, projId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem()) - case plugin.Subtype: + case hostplugin.Subtype: hc, plg, err = s.updatePluginInRepo(ctx, projId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem()) } return @@ -615,7 +615,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) { if err != nil { return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host")) } - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginHostRepoFn() if err != nil { return false, errors.Wrap(ctx, err, op) @@ -669,7 +669,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth. } parentId = cat.GetProjectId() opts = append(opts, auth.WithId(id)) - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginHostRepoFn() if err != nil { res.Error = err @@ -692,7 +692,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth. return auth.Verify(ctx, opts...) } -func toPluginInfo(plg *hostplugin.Plugin) *plugins.PluginInfo { +func toPluginInfo(plg *plugin.Plugin) *plugins.PluginInfo { if plg == nil { return nil } @@ -722,8 +722,8 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb. switch in.(type) { case *static.HostCatalog: out.Type = static.Subtype.String() - case *plugin.HostCatalog: - out.Type = plugin.Subtype.String() + case *hostplugin.HostCatalog: + out.Type = hostplugin.Subtype.String() } } if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" { @@ -754,7 +754,7 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb. out.AuthorizedCollectionActions = opts.WithAuthorizedCollectionActions } switch h := in.(type) { - case *plugin.HostCatalog: + case *hostplugin.HostCatalog: if outputFields.Has(globals.PluginIdField) { out.PluginId = h.GetPluginId() } @@ -793,22 +793,22 @@ func toStorageStaticCatalog(ctx context.Context, projectId string, item *pb.Host return hc, nil } -func toStoragePluginCatalog(ctx context.Context, projectId, plgId string, item *pb.HostCatalog) (*plugin.HostCatalog, error) { +func toStoragePluginCatalog(ctx context.Context, projectId, plgId string, item *pb.HostCatalog) (*hostplugin.HostCatalog, error) { const op = "host_catalog_service.toStoragePluginCatalog" - var opts []plugin.Option + var opts []hostplugin.Option if name := item.GetName(); name != nil { - opts = append(opts, plugin.WithName(item.GetName().GetValue())) + opts = append(opts, hostplugin.WithName(item.GetName().GetValue())) } if desc := item.GetDescription(); desc != nil { - opts = append(opts, plugin.WithDescription(desc.GetValue())) + opts = append(opts, hostplugin.WithDescription(desc.GetValue())) } if attrs := item.GetAttributes(); attrs != nil { - opts = append(opts, plugin.WithAttributes(attrs)) + opts = append(opts, hostplugin.WithAttributes(attrs)) } if secrets := item.GetSecrets(); secrets != nil { - opts = append(opts, plugin.WithSecrets(secrets)) + opts = append(opts, hostplugin.WithSecrets(secrets)) } - hc, err := plugin.NewHostCatalog(ctx, projectId, plgId, opts...) + hc, err := hostplugin.NewHostCatalog(ctx, projectId, plgId, opts...) if err != nil { return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for creation")) } @@ -837,7 +837,7 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error { } switch subtypes.SubtypeFromType(domain, req.GetItem().GetType()) { case static.Subtype: - case plugin.Subtype: + case hostplugin.Subtype: if req.GetItem().GetPlugin() != nil { badFields[globals.PluginField] = "This is a read only field." } @@ -850,7 +850,7 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error { badFields[globals.PluginNameField] = "Can't set the plugin id field along with this field." } default: - badFields[globals.TypeField] = fmt.Sprintf("This is a required field and must be either %q or %q.", static.Subtype.String(), plugin.Subtype.String()) + badFields[globals.TypeField] = fmt.Sprintf("This is a required field and must be either %q or %q.", static.Subtype.String(), hostplugin.Subtype.String()) } return badFields }) @@ -870,8 +870,8 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error { if req.GetItem().GetPlugin() != nil { badFields[globals.PluginField] = "This field is unused for this type of host catalog." } - case plugin.Subtype: - if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != plugin.Subtype { + case hostplugin.Subtype: + if req.GetItem().GetType() != "" && subtypes.SubtypeFromType(domain, req.GetItem().GetType()) != hostplugin.Subtype { badFields[globals.TypeField] = "Cannot modify resource type." } if req.GetItem().GetPlugin() != nil { diff --git a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go index 91ee2e65b5..b121c2a169 100644 --- a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go +++ b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go @@ -20,11 +20,11 @@ import ( "github.com/hashicorp/boundary/internal/daemon/controller/handlers/host_catalogs" "github.com/hashicorp/boundary/internal/db" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - "github.com/hashicorp/boundary/internal/plugin/host" + plugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/types/scope" "github.com/hashicorp/boundary/internal/types/subtypes" @@ -60,7 +60,7 @@ var authorizedCollectionActions = map[subtypes.Subtype]map[string]*structpb.List }, }, }, - plugin.Subtype: { + hostplugin.Subtype: { "host-sets": { Values: []*structpb.Value{ structpb.NewStringValue("create"), @@ -88,11 +88,11 @@ func TestGet_Static(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iam.TestRepo(t, conn, wrapper), nil @@ -178,19 +178,19 @@ func TestGet_Plugin(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iam.TestRepo(t, conn, wrapper), nil } name := "test" - plg := host.TestPlugin(t, conn, name) - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar"))) - hcPrev := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostCatalogPreviousPrefix))) + plg := plugin.TestPlugin(t, conn, name) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), hostplugin.WithSecretsHmac([]byte("foobar"))) + hcPrev := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), hostplugin.WithSecretsHmac([]byte("foobar")), hostplugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostCatalogPreviousPrefix))) toMerge := &pbs.GetHostCatalogRequest{ Id: hc.GetPublicId(), @@ -212,9 +212,9 @@ func TestGet_Plugin(t *testing.T) { }, CreatedTime: hc.CreateTime.GetTimestamp(), UpdatedTime: hc.UpdateTime.GetTimestamp(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), AuthorizedActions: testAuthorizedActions, - AuthorizedCollectionActions: authorizedCollectionActions[plugin.Subtype], + AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype], SecretsHmac: base58.Encode([]byte("foobar")), } @@ -291,11 +291,11 @@ func TestList(t *testing.T) { iamRepoFn := func() (*iam.Repository, error) { return iam.TestRepo(t, conn, wrapper), nil } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -323,9 +323,9 @@ func TestList(t *testing.T) { var testPluginCatalogs []*pb.HostCatalog name := "test" - plg := host.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) for i := 0; i < 3; i++ { - hc := plugin.TestCatalog(t, conn, pWithCatalogs.GetPublicId(), plg.GetPublicId()) + hc := hostplugin.TestCatalog(t, conn, pWithCatalogs.GetPublicId(), plg.GetPublicId()) cat := &pb.HostCatalog{ Id: hc.GetPublicId(), ScopeId: hc.GetProjectId(), @@ -339,9 +339,9 @@ func TestList(t *testing.T) { Description: plg.GetDescription(), }, Version: 1, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), AuthorizedActions: testAuthorizedActions, - AuthorizedCollectionActions: authorizedCollectionActions[plugin.Subtype], + AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype], } wantSomeCatalogs = append(wantSomeCatalogs, cat) testPluginCatalogs = append(testPluginCatalogs, cat) @@ -363,9 +363,9 @@ func TestList(t *testing.T) { } name = "different" - diffPlg := host.TestPlugin(t, conn, name) + diffPlg := plugin.TestPlugin(t, conn, name) for i := 0; i < 3; i++ { - hc := plugin.TestCatalog(t, conn, pWithOtherCatalogs.GetPublicId(), diffPlg.GetPublicId()) + hc := hostplugin.TestCatalog(t, conn, pWithOtherCatalogs.GetPublicId(), diffPlg.GetPublicId()) wantOtherCatalogs = append(wantOtherCatalogs, &pb.HostCatalog{ Id: hc.GetPublicId(), ScopeId: hc.GetProjectId(), @@ -379,9 +379,9 @@ func TestList(t *testing.T) { Description: diffPlg.GetDescription(), }, Version: 1, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), AuthorizedActions: testAuthorizedActions, - AuthorizedCollectionActions: authorizedCollectionActions[plugin.Subtype], + AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype], }) } @@ -435,7 +435,7 @@ func TestList(t *testing.T) { name: "Filter To Catalog Using Test Plugin", req: &pbs.ListHostCatalogsRequest{ ScopeId: scope.Global.String(), Recursive: true, - Filter: `"/item/plugin/name"=="test"`, + Filter: `"/item/hostplugin/name"=="test"`, }, res: &pbs.ListHostCatalogsResponse{Items: testPluginCatalogs}, }, @@ -497,11 +497,11 @@ func TestDelete_Static(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -567,17 +567,17 @@ func TestDelete_Plugin(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil } - plg := host.TestPlugin(t, conn, "test") - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + plg := plugin.TestPlugin(t, conn, "test") + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) s, err := host_catalogs.NewService(repo, pluginHostRepo, pluginRepo, iamRepoFn) require.NoError(t, err, "Couldn't create a new host catalog service.") @@ -639,11 +639,11 @@ func TestDelete_twice(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -675,11 +675,11 @@ func TestCreate_Static(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -827,25 +827,25 @@ func TestCreate_Plugin(t *testing.T) { repo := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil } name := "test" - 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 := plugin.TestPlugin(t, conn, name) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{ + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{ OnCreateCatalogFn: func(ctx context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) { return nil, nil }, }), }) } - defaultHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + defaultHc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) defaultHcCreated := defaultHc.GetCreateTime().GetTimestamp().AsTime() toMerge := &pbs.CreateHostCatalogRequest{} @@ -861,7 +861,7 @@ func TestCreate_Plugin(t *testing.T) { ScopeId: proj.GetPublicId(), Name: &wrappers.StringValue{Value: "name"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, res: &pbs.CreateHostCatalogResponse{ @@ -877,9 +877,9 @@ func TestCreate_Plugin(t *testing.T) { }, Name: &wrappers.StringValue{Value: "name"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), AuthorizedActions: testAuthorizedActions, - AuthorizedCollectionActions: authorizedCollectionActions[plugin.Subtype], + AuthorizedCollectionActions: authorizedCollectionActions[hostplugin.Subtype], }, }, }, @@ -887,7 +887,7 @@ func TestCreate_Plugin(t *testing.T) { name: "Cant create in org", req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{ ScopeId: org.GetParentId(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, err: handlers.ApiErrorWithCode(codes.InvalidArgument), @@ -896,7 +896,7 @@ func TestCreate_Plugin(t *testing.T) { name: "Cant create in global", req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{ ScopeId: scope.Global.String(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, err: handlers.ApiErrorWithCode(codes.InvalidArgument), @@ -923,7 +923,7 @@ func TestCreate_Plugin(t *testing.T) { req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{ Id: "not allowed to be set", ScopeId: proj.GetPublicId(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, res: nil, @@ -934,7 +934,7 @@ func TestCreate_Plugin(t *testing.T) { req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{ CreatedTime: timestamppb.Now(), ScopeId: proj.GetPublicId(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, res: nil, @@ -945,7 +945,7 @@ func TestCreate_Plugin(t *testing.T) { req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{ UpdatedTime: timestamppb.Now(), ScopeId: proj.GetPublicId(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PluginId: plg.GetPublicId(), }}, res: nil, @@ -1004,11 +1004,11 @@ func TestUpdate_Static(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -1371,19 +1371,19 @@ func TestUpdate_Plugin(t *testing.T) { rw := db.New(conn) name := "test" - plg := host.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(plugin.NewLoopbackPlugin()), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(hostplugin.NewLoopbackPlugin()), } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } - pluginRepo := func() (*host.Repository, error) { - return host.NewRepository(rw, rw, kms) + pluginRepo := func() (*plugin.Repository, error) { + return plugin.NewRepository(rw, rw, kms) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -1403,7 +1403,7 @@ func TestUpdate_Plugin(t *testing.T) { PluginId: plg.GetPublicId(), Name: wrapperspb.String("default"), Description: wrapperspb.String("default"), - Type: "plugin", + Type: "hostplugin", Attrs: &pb.HostCatalog_Attributes{ Attributes: attr, }, @@ -1469,7 +1469,7 @@ func TestUpdate_Plugin(t *testing.T) { check: func(t *testing.T, in *pb.HostCatalog) { assert.Equal(t, "new", in.Name.GetValue()) assert.Equal(t, "desc", in.Description.GetValue()) - assert.Empty(t, cmp.Diff(authorizedCollectionActions[plugin.Subtype], in.GetAuthorizedCollectionActions(), cmpopts.IgnoreUnexported(structpb.ListValue{}, structpb.Value{}))) + assert.Empty(t, cmp.Diff(authorizedCollectionActions[hostplugin.Subtype], in.GetAuthorizedCollectionActions(), cmpopts.IgnoreUnexported(structpb.ListValue{}, structpb.Value{}))) }, }, { diff --git a/internal/daemon/controller/handlers/host_sets/host_set_service.go b/internal/daemon/controller/handlers/host_sets/host_set_service.go index b3d0fc1f54..be60ae2731 100644 --- a/internal/daemon/controller/handlers/host_sets/host_set_service.go +++ b/internal/daemon/controller/handlers/host_sets/host_set_service.go @@ -14,13 +14,13 @@ import ( "github.com/hashicorp/boundary/internal/errors" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" "github.com/hashicorp/boundary/internal/host" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" plugstore "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/host/static" staticstore "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/libs/endpoint" "github.com/hashicorp/boundary/internal/perms" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/requests" "github.com/hashicorp/boundary/internal/types/action" "github.com/hashicorp/boundary/internal/types/resource" @@ -49,7 +49,7 @@ var ( action.SetHosts, action.RemoveHosts, }, - plugin.Subtype: { + hostplugin.Subtype: { action.NoOp, action.Read, action.Update, @@ -72,7 +72,7 @@ func init() { if maskManager[static.Subtype], err = handlers.NewMaskManager(handlers.MaskDestination{&staticstore.HostSet{}, &staticstore.UnimplementedSetFields{}}, handlers.MaskSource{&pb.HostSet{}}); err != nil { panic(err) } - if maskManager[plugin.Subtype], err = handlers.NewMaskManager(handlers.MaskDestination{&plugstore.HostSet{}}, handlers.MaskSource{&pb.HostSet{}}); err != nil { + if maskManager[hostplugin.Subtype], err = handlers.NewMaskManager(handlers.MaskDestination{&plugstore.HostSet{}}, handlers.MaskSource{&pb.HostSet{}}); err != nil { panic(err) } } @@ -94,7 +94,7 @@ func NewService(staticRepoFn common.StaticRepoFactory, pluginRepoFn common.Plugi return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing static repository") } if pluginRepoFn == nil { - return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing plugin repository") + return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing hostplugin repository") } return Service{staticRepoFn: staticRepoFn, pluginRepoFn: pluginRepoFn}, nil } @@ -451,7 +451,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H hl = append(hl, h) } hs = hset - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginRepoFn() if err != nil { return nil, nil, nil, err @@ -466,7 +466,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H hs = hset plg = toPluginInfo(hsplg) for _, h := range hset.HostIds { - hl = append(hl, &plugin.Host{ + hl = append(hl, &hostplugin.Host{ Host: &plugstore.Host{ PublicId: h, CatalogId: hset.CatalogId, @@ -502,7 +502,7 @@ func (s Service) createInRepo(ctx context.Context, projectId, catalogId string, return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.") } hSet = out - case plugin.Subtype: + case hostplugin.Subtype: h, err := toStoragePluginSet(ctx, catalogId, item) if err != nil { return nil, nil, err @@ -564,7 +564,7 @@ func (s Service) updatePluginInRepo(ctx context.Context, projectId string, req * return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for update")) } h.PublicId = req.GetId() - dbMask := maskManager[plugin.Subtype].Translate(req.GetUpdateMask().GetPaths(), "attributes") + dbMask := maskManager[hostplugin.Subtype].Translate(req.GetUpdateMask().GetPaths(), "attributes") if len(dbMask) == 0 { return nil, nil, nil, handlers.InvalidArgumentErrorf("No valid fields included in the update mask.", map[string]string{"update_mask": "No valid fields provided in the update mask."}) } @@ -591,7 +591,7 @@ func (s Service) updateInRepo(ctx context.Context, projectId, catalogId string, switch subtypes.SubtypeFromId(domain, req.GetId()) { case static.Subtype: hs, hosts, err = s.updateStaticInRepo(ctx, projectId, catalogId, req) - case plugin.Subtype: + case hostplugin.Subtype: hs, hosts, plg, err = s.updatePluginInRepo(ctx, projectId, req) } return @@ -610,7 +610,7 @@ func (s Service) deleteFromRepo(ctx context.Context, projectId, id string) (bool if err != nil { return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host")) } - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginRepoFn() if err != nil { return false, err @@ -640,7 +640,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host for _, a := range sl { sets = append(sets, a) } - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginRepoFn() if err != nil { return nil, nil, err @@ -763,7 +763,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return nil, res } set = ss - case plugin.Subtype: + case hostplugin.Subtype: ps, _, err := pluginRepo.LookupSet(ctx, id) if err != nil { res.Error = err @@ -792,7 +792,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return nil, res } cat = cs - case plugin.Subtype: + case hostplugin.Subtype: pc, _, err := pluginRepo.LookupCatalog(ctx, parentId) if err != nil { res.Error = err @@ -808,7 +808,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return cat, auth.Verify(ctx, opts...) } -func toPluginInfo(plg *hostplugin.Plugin) *plugins.PluginInfo { +func toPluginInfo(plg *plugin.Plugin) *plugins.PluginInfo { if plg == nil { return nil } @@ -838,8 +838,8 @@ func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handler switch in.(type) { case *static.HostSet: out.Type = static.Subtype.String() - case *plugin.HostSet: - out.Type = plugin.Subtype.String() + case *hostplugin.HostSet: + out.Type = hostplugin.Subtype.String() } } if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" { @@ -873,7 +873,7 @@ func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handler } switch h := in.(type) { - case *plugin.HostSet: + case *hostplugin.HostSet: if outputFields.Has(globals.PreferredEndpointsField) { out.PreferredEndpoints = h.PreferredEndpoints } @@ -913,25 +913,25 @@ func toStorageStaticSet(ctx context.Context, catalogId string, item *pb.HostSet) return hs, nil } -func toStoragePluginSet(ctx context.Context, catalogId string, item *pb.HostSet) (*plugin.HostSet, error) { +func toStoragePluginSet(ctx context.Context, catalogId string, item *pb.HostSet) (*hostplugin.HostSet, error) { const op = "host_set_service.toStoragePluginSet" - var opts []plugin.Option + var opts []hostplugin.Option if item.GetName() != nil { - opts = append(opts, plugin.WithName(item.GetName().GetValue())) + opts = append(opts, hostplugin.WithName(item.GetName().GetValue())) } if item.GetDescription() != nil { - opts = append(opts, plugin.WithDescription(item.GetDescription().GetValue())) + opts = append(opts, hostplugin.WithDescription(item.GetDescription().GetValue())) } if item.GetAttributes() != nil { - opts = append(opts, plugin.WithAttributes(item.GetAttributes())) + opts = append(opts, hostplugin.WithAttributes(item.GetAttributes())) } if item.GetPreferredEndpoints() != nil { - opts = append(opts, plugin.WithPreferredEndpoints(item.GetPreferredEndpoints())) + opts = append(opts, hostplugin.WithPreferredEndpoints(item.GetPreferredEndpoints())) } if item.GetSyncIntervalSeconds() != nil { - opts = append(opts, plugin.WithSyncIntervalSeconds(item.GetSyncIntervalSeconds().GetValue())) + opts = append(opts, hostplugin.WithSyncIntervalSeconds(item.GetSyncIntervalSeconds().GetValue())) } - hs, err := plugin.NewHostSet(ctx, catalogId, opts...) + hs, err := hostplugin.NewHostSet(ctx, catalogId, opts...) if err != nil { return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for creation")) } @@ -969,8 +969,8 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) e if len(req.GetItem().PreferredEndpoints) > 0 { badFields[globals.PreferredEndpointsField] = "This field is not yet supported for static host sets." } - case plugin.Subtype: - if req.GetItem().GetType() != "" && req.GetItem().GetType() != plugin.Subtype.String() { + case hostplugin.Subtype: + if req.GetItem().GetType() != "" && req.GetItem().GetType() != hostplugin.Subtype.String() { badFields[globals.TypeField] = "Doesn't match the parent resource's type." } if val := req.GetItem().GetSyncIntervalSeconds(); val != nil { @@ -997,7 +997,7 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateHostSetRequest) e if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() { badFields[globals.TypeField] = "Cannot modify the resource type." } - case plugin.Subtype: + case hostplugin.Subtype: if val := req.GetItem().GetSyncIntervalSeconds(); val != nil { if val.GetValue() == 0 || val.GetValue() < -1 { badFields[globals.SyncIntervalSecondsField] = "Must be -1 or a positive integer." diff --git a/internal/daemon/controller/handlers/host_sets/host_set_service_test.go b/internal/daemon/controller/handlers/host_sets/host_set_service_test.go index e28687af09..9b39534ad3 100644 --- a/internal/daemon/controller/handlers/host_sets/host_set_service_test.go +++ b/internal/daemon/controller/handlers/host_sets/host_set_service_test.go @@ -20,11 +20,11 @@ import ( "github.com/hashicorp/boundary/internal/db" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" "github.com/hashicorp/boundary/internal/host" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "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" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/types/scope" "github.com/hashicorp/boundary/internal/types/subtypes" @@ -45,8 +45,8 @@ import ( ) var testAuthorizedActions = map[subtypes.Subtype][]string{ - static.Subtype: {"no-op", "read", "update", "delete", "add-hosts", "set-hosts", "remove-hosts"}, - plugin.Subtype: {"no-op", "read", "update", "delete"}, + static.Subtype: {"no-op", "read", "update", "delete", "add-hosts", "set-hosts", "remove-hosts"}, + hostplugin.Subtype: {"no-op", "read", "update", "delete"}, } func TestGet_Static(t *testing.T) { @@ -67,8 +67,8 @@ func TestGet_Static(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] hs := static.TestSets(t, conn, hc.GetPublicId(), 1)[0] @@ -164,17 +164,17 @@ func TestGet_Plugin(t *testing.T) { name := "test" prefEndpoints := []string{"cidr:1.2.3.4", "cidr:2.3.4.5/24"} - plg := hostplugin.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - hs := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1)) - hsPrev := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostSetPreviousPrefix))) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + hs := hostplugin.TestSet(t, conn, kms, sche, hc, plgm, hostplugin.WithPreferredEndpoints(prefEndpoints), hostplugin.WithSyncIntervalSeconds(-1)) + hsPrev := hostplugin.TestSet(t, conn, kms, sche, hc, plgm, hostplugin.WithPreferredEndpoints(prefEndpoints), hostplugin.WithSyncIntervalSeconds(-1), hostplugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostSetPreviousPrefix))) toMerge := &pbs.GetHostSetRequest{} @@ -183,7 +183,7 @@ func TestGet_Plugin(t *testing.T) { Id: hs.GetPublicId(), CreatedTime: hs.CreateTime.GetTimestamp(), UpdatedTime: hs.UpdateTime.GetTimestamp(), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()}, Plugin: &plugins.PluginInfo{ Id: plg.GetPublicId(), @@ -192,7 +192,7 @@ func TestGet_Plugin(t *testing.T) { }, PreferredEndpoints: prefEndpoints, SyncIntervalSeconds: &wrappers.Int32Value{Value: -1}, - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], } cases := []struct { @@ -278,8 +278,8 @@ func TestList_Static(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } hcs := static.TestCatalogs(t, conn, proj.GetPublicId(), 2) hc, hcNoHosts := hcs[0], hcs[1] @@ -378,20 +378,20 @@ func TestList_Plugin(t *testing.T) { return static.NewRepository(rw, rw, kms) } name := "test" - plg := hostplugin.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - hcNoHosts := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + hcNoHosts := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) preferredEndpoints := []string{"cidr:1.2.3.4", "dns:*.foobar.com"} var wantHs []*pb.HostSet for i := 0; i < 10; i++ { - h := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(preferredEndpoints), plugin.WithSyncIntervalSeconds(5)) + h := hostplugin.TestSet(t, conn, kms, sche, hc, plgm, hostplugin.WithPreferredEndpoints(preferredEndpoints), hostplugin.WithSyncIntervalSeconds(5)) wantHs = append(wantHs, &pb.HostSet{ Id: h.GetPublicId(), HostCatalogId: h.GetCatalogId(), @@ -404,8 +404,8 @@ func TestList_Plugin(t *testing.T) { CreatedTime: h.GetCreateTime().GetTimestamp(), UpdatedTime: h.GetUpdateTime().GetTimestamp(), Version: h.GetVersion(), - Type: plugin.Subtype.String(), - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + Type: hostplugin.Subtype.String(), + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], PreferredEndpoints: preferredEndpoints, SyncIntervalSeconds: &wrappers.Int32Value{Value: 5}, }) @@ -491,8 +491,8 @@ func TestDelete_Static(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] h := static.TestSets(t, conn, hc.GetPublicId(), 1)[0] @@ -562,17 +562,17 @@ func TestDelete_Plugin(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } name := "test" - plg := hostplugin.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - h := plugin.TestSet(t, conn, kms, sche, hc, plgm) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + h := hostplugin.TestSet(t, conn, kms, sche, hc, plgm) s, err := host_sets.NewService(repoFn, pluginRepoFn) require.NoError(t, err, "Couldn't create a new host set service.") @@ -640,8 +640,8 @@ func TestDelete_twice(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] h := static.TestSets(t, conn, hc.GetPublicId(), 1)[0] @@ -677,8 +677,8 @@ func TestCreate_Static(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] prefEndpoints := []string{"cidr:1.2.3.4", "cidr:2.3.4.5/24"} @@ -834,17 +834,17 @@ func TestCreate_Plugin(t *testing.T) { return static.NewRepository(rw, rw, kms) } name := "test" - 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 := plugin.TestPlugin(t, conn, name) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{ + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{ OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) { return nil, nil }, }), }) } - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) attrs := map[string]any{ "int": 1, @@ -890,7 +890,7 @@ func TestCreate_Plugin(t *testing.T) { HostCatalogId: hc.GetPublicId(), Name: &wrappers.StringValue{Value: "No Attributes"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), SyncIntervalSeconds: &wrapperspb.Int32Value{Value: -1}, }}, res: &pbs.CreateHostSetResponse{ @@ -905,8 +905,8 @@ func TestCreate_Plugin(t *testing.T) { }, Name: &wrappers.StringValue{Value: "No Attributes"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + Type: hostplugin.Subtype.String(), + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], SyncIntervalSeconds: &wrapperspb.Int32Value{Value: -1}, }, }, @@ -917,7 +917,7 @@ func TestCreate_Plugin(t *testing.T) { HostCatalogId: hc.GetPublicId(), Name: &wrappers.StringValue{Value: "With Attributes"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), SyncIntervalSeconds: &wrapperspb.Int32Value{Value: 90}, Attrs: &pb.HostSet_Attributes{ Attributes: testInputAttrs, @@ -935,9 +935,9 @@ func TestCreate_Plugin(t *testing.T) { }, Name: &wrappers.StringValue{Value: "With Attributes"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), SyncIntervalSeconds: &wrapperspb.Int32Value{Value: 90}, - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], Attrs: &pb.HostSet_Attributes{ Attributes: testOutputAttrs, }, @@ -950,7 +950,7 @@ func TestCreate_Plugin(t *testing.T) { HostCatalogId: hc.GetPublicId(), Name: &wrappers.StringValue{Value: "name"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PreferredEndpoints: prefEndpoints, }}, res: &pbs.CreateHostSetResponse{ @@ -965,9 +965,9 @@ func TestCreate_Plugin(t *testing.T) { }, Name: &wrappers.StringValue{Value: "name"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PreferredEndpoints: prefEndpoints, - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], }, }, }, @@ -977,7 +977,7 @@ func TestCreate_Plugin(t *testing.T) { HostCatalogId: hc.GetPublicId(), Name: &wrappers.StringValue{Value: "name"}, Description: &wrappers.StringValue{Value: "desc"}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), PreferredEndpoints: append(prefEndpoints, "foobar:1.2.3.4"), }}, err: handlers.ApiErrorWithCode(codes.InvalidArgument), @@ -1011,8 +1011,8 @@ func TestCreate_Plugin(t *testing.T) { }, Name: &wrappers.StringValue{Value: "no type name"}, Description: &wrappers.StringValue{Value: "no type desc"}, - Type: plugin.Subtype.String(), - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + Type: hostplugin.Subtype.String(), + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], }, }, }, @@ -1129,8 +1129,8 @@ func TestUpdate_Static(t *testing.T) { Id: hs.GetPublicId(), } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } tested, err := host_sets.NewService(repoFn, plgRepoFn) require.NoError(t, err, "Failed to create a new host set service.") @@ -1474,16 +1474,16 @@ func TestUpdate_Plugin(t *testing.T) { rw := db.New(conn) name := "test" - plg := hostplugin.TestPlugin(t, conn, name) + plg := plugin.TestPlugin(t, conn, name) plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - pluginHostRepo := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginHostRepo := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } iamRepoFn := func() (*iam.Repository, error) { return iamRepo, nil @@ -1491,7 +1491,7 @@ func TestUpdate_Plugin(t *testing.T) { tested, err := host_sets.NewService(repoFn, pluginHostRepo) require.NoError(t, err, "Failed to create a new host catalog service.") - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) ctx := auth.DisabledAuthTestContext(iamRepoFn, proj.GetPublicId()) freshSet := func(t *testing.T) *pb.HostSet { @@ -1503,7 +1503,7 @@ func TestUpdate_Plugin(t *testing.T) { HostCatalogId: hc.GetPublicId(), Name: wrapperspb.String("default"), Description: wrapperspb.String("default"), - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), Attrs: &pb.HostSet_Attributes{ Attributes: attr, }, @@ -1819,8 +1819,8 @@ func TestAddHostSetHosts(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } s, err := host_sets.NewService(repoFn, plgRepoFn) require.NoError(t, err, "Error when getting new host set service.") @@ -1940,8 +1940,8 @@ func TestSetHostSetHosts(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } s, err := host_sets.NewService(repoFn, plgRepoFn) require.NoError(t, err, "Error when getting new host set service.") @@ -2057,8 +2057,8 @@ func TestRemoveHostSetHosts(t *testing.T) { repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plgRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + plgRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } s, err := host_sets.NewService(repoFn, plgRepoFn) require.NoError(t, err, "Error when getting new host set service.") diff --git a/internal/daemon/controller/handlers/hosts/host_service.go b/internal/daemon/controller/handlers/hosts/host_service.go index 17cd4c3824..7f3eed41df 100644 --- a/internal/daemon/controller/handlers/hosts/host_service.go +++ b/internal/daemon/controller/handlers/hosts/host_service.go @@ -16,11 +16,11 @@ import ( "github.com/hashicorp/boundary/internal/errors" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" "github.com/hashicorp/boundary/internal/host" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/perms" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + plugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/requests" "github.com/hashicorp/boundary/internal/types/action" "github.com/hashicorp/boundary/internal/types/resource" @@ -43,7 +43,7 @@ var ( action.Update, action.Delete, }, - plugin.Subtype: { + hostplugin.Subtype: { action.NoOp, action.Read, }, @@ -310,7 +310,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Host, *plugin if h == nil { return nil, nil, handlers.NotFoundErrorf("Host %q doesn't exist.", id) } - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginRepoFn() if err != nil { return nil, nil, err @@ -425,7 +425,7 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string) ([]host.Hos for _, h := range hl { hosts = append(hosts, h) } - case plugin.Subtype: + case hostplugin.Subtype: repo, err := s.pluginRepoFn() if err != nil { return nil, nil, err @@ -473,7 +473,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return nil, res } parentId = h.GetCatalogId() - case plugin.Subtype: + case hostplugin.Subtype: h, _, err := pluginRepo.LookupHost(ctx, id) if err != nil { res.Error = err @@ -501,7 +501,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return nil, res } cat = stcat - case plugin.Subtype: + case hostplugin.Subtype: plcat, _, err := pluginRepo.LookupCatalog(ctx, parentId) if err != nil { res.Error = err @@ -517,7 +517,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty return cat, auth.Verify(ctx, opts...) } -func toPluginInfo(plg *hostplugin.Plugin) *plugins.PluginInfo { +func toPluginInfo(plg *plugin.Plugin) *plugins.PluginInfo { if plg == nil { return nil } @@ -546,8 +546,8 @@ func toProto(ctx context.Context, in host.Host, opt ...handlers.Option) (*pb.Hos switch in.(type) { case *static.Host: out.Type = static.Subtype.String() - case *plugin.Host: - out.Type = plugin.Subtype.String() + case *hostplugin.Host: + out.Type = hostplugin.Subtype.String() } } if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" { @@ -588,7 +588,7 @@ func toProto(ctx context.Context, in host.Host, opt ...handlers.Option) (*pb.Hos out.Plugin = opts.WithPlugin } switch h := in.(type) { - case *plugin.Host: + case *hostplugin.Host: if outputFields.Has(globals.IpAddressesField) { out.IpAddresses = h.IpAddresses } @@ -658,7 +658,7 @@ func validateCreateRequest(req *pbs.CreateHostRequest) error { } } } - case plugin.Subtype: + case hostplugin.Subtype: badFields[globals.HostCatalogIdField] = "Cannot manually create hosts for this type of catalog." } return badFields @@ -696,7 +696,7 @@ func validateUpdateRequest(req *pbs.UpdateHostRequest) error { } } } - case plugin.Subtype: + case hostplugin.Subtype: badFields[globals.IdField] = "Cannot modify this type of host." default: badFields["id"] = "Improperly formatted identifier used." @@ -709,7 +709,7 @@ func validateDeleteRequest(req *pbs.DeleteHostRequest) error { return handlers.ValidateDeleteRequest(func() map[string]string { badFields := map[string]string{} switch subtypes.SubtypeFromId(domain, req.GetId()) { - case plugin.Subtype: + case hostplugin.Subtype: badFields[globals.IdField] = "Cannot manually delete this type of host." } return badFields diff --git a/internal/daemon/controller/handlers/hosts/host_service_test.go b/internal/daemon/controller/handlers/hosts/host_service_test.go index 1f588cb728..f8e6110c96 100644 --- a/internal/daemon/controller/handlers/hosts/host_service_test.go +++ b/internal/daemon/controller/handlers/hosts/host_service_test.go @@ -19,11 +19,11 @@ import ( "github.com/hashicorp/boundary/internal/daemon/controller/handlers/hosts" "github.com/hashicorp/boundary/internal/db" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" - "github.com/hashicorp/boundary/internal/host/plugin" + hostplugin "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "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" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/types/scope" "github.com/hashicorp/boundary/internal/types/subtypes" @@ -42,8 +42,8 @@ import ( ) var testAuthorizedActions = map[subtypes.Subtype][]string{ - static.Subtype: {"no-op", "read", "update", "delete"}, - plugin.Subtype: {"no-op", "read"}, + static.Subtype: {"no-op", "read", "update", "delete"}, + hostplugin.Subtype: {"no-op", "read"}, } func TestGet_Static(t *testing.T) { @@ -61,8 +61,8 @@ func TestGet_Static(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -151,24 +151,24 @@ func TestGet_Plugin(t *testing.T) { org, proj := iam.TestScopes(t, iamRepo) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - h := plugin.TestHost(t, conn, hc.GetPublicId(), "test") - hPrev := plugin.TestHost(t, conn, hc.GetPublicId(), "test-prev", plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostPreviousPrefix))) - hs := plugin.TestSet(t, conn, kms, sche, hc, plgm) - plugin.TestSetMembers(t, conn, hs.GetPublicId(), []*plugin.Host{h, hPrev}) + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + h := hostplugin.TestHost(t, conn, hc.GetPublicId(), "test") + hPrev := hostplugin.TestHost(t, conn, hc.GetPublicId(), "test-prev", hostplugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostPreviousPrefix))) + hs := hostplugin.TestSet(t, conn, kms, sche, hc, plgm) + hostplugin.TestSetMembers(t, conn, hs.GetPublicId(), []*hostplugin.Host{h, hPrev}) pHost := &pb.Host{ HostCatalogId: hc.GetPublicId(), @@ -176,7 +176,7 @@ func TestGet_Plugin(t *testing.T) { CreatedTime: h.CreateTime.GetTimestamp(), UpdatedTime: h.UpdateTime.GetTimestamp(), Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()}, - Type: plugin.Subtype.String(), + Type: hostplugin.Subtype.String(), Plugin: &plugins.PluginInfo{ Id: plg.GetPublicId(), Name: plg.GetName(), @@ -184,7 +184,7 @@ func TestGet_Plugin(t *testing.T) { }, HostSetIds: []string{hs.GetPublicId()}, ExternalId: "test", - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], } cases := []struct { @@ -265,8 +265,8 @@ func TestList_Static(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -377,28 +377,28 @@ func TestList_Plugin(t *testing.T) { } org, proj := iam.TestScopes(t, iamRepo) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ - plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), + plg.GetPublicId(): hostplugin.NewWrappingPluginClient(&hostplugin.TestPluginServer{}), } rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, plgm) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, plgm) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - hcs := plugin.TestCatalogs(t, conn, proj.GetPublicId(), plg.GetPublicId(), 2) + hcs := hostplugin.TestCatalogs(t, conn, proj.GetPublicId(), plg.GetPublicId(), 2) hc, hcNoHosts := hcs[0], hcs[1] - hs := plugin.TestSet(t, conn, kms, sche, hc, plgm) + hs := hostplugin.TestSet(t, conn, kms, sche, hc, plgm) var wantHs []*pb.Host for i := 0; i < 10; i++ { extId := fmt.Sprintf("host %d", i) - h := plugin.TestHost(t, conn, hc.GetPublicId(), extId) - plugin.TestSetMembers(t, conn, hs.GetPublicId(), []*plugin.Host{h}) + h := hostplugin.TestHost(t, conn, hc.GetPublicId(), extId) + hostplugin.TestSetMembers(t, conn, hs.GetPublicId(), []*hostplugin.Host{h}) wantHs = append(wantHs, &pb.Host{ Id: h.GetPublicId(), HostCatalogId: h.GetCatalogId(), @@ -413,8 +413,8 @@ func TestList_Plugin(t *testing.T) { HostSetIds: []string{hs.GetPublicId()}, Version: 1, ExternalId: extId, - Type: plugin.Subtype.String(), - AuthorizedActions: testAuthorizedActions[plugin.Subtype], + Type: hostplugin.Subtype.String(), + AuthorizedActions: testAuthorizedActions[hostplugin.Subtype], }) } sort.Slice(wantHs, func(i, j int) bool { @@ -506,8 +506,8 @@ func TestDelete(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -515,9 +515,9 @@ func TestDelete(t *testing.T) { hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] h := static.TestHosts(t, conn, hc.GetPublicId(), 1)[0] - plg := hostplugin.TestPlugin(t, conn, "test") - pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - pluginH := plugin.TestHost(t, conn, pluginHc.GetPublicId(), "test") + plg := plugin.TestPlugin(t, conn, "test") + pluginHc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + pluginH := hostplugin.TestHost(t, conn, pluginHc.GetPublicId(), "test") s, err := hosts.NewService(repoFn, pluginRepoFn) require.NoError(t, err, "Couldn't create a new host set service.") @@ -537,7 +537,7 @@ func TestDelete(t *testing.T) { }, }, { - name: "Delete a plugin Host", + name: "Delete a hostplugin Host", projectId: proj.GetPublicId(), req: &pbs.DeleteHostRequest{ Id: pluginH.GetPublicId(), @@ -590,8 +590,8 @@ func TestDelete_twice(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -627,16 +627,16 @@ func TestCreate(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] - plg := hostplugin.TestPlugin(t, conn, "test") - pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + plg := plugin.TestPlugin(t, conn, "test") + pluginHc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) defaultHcCreated := hc.GetCreateTime().GetTimestamp().AsTime() @@ -689,10 +689,10 @@ func TestCreate(t *testing.T) { wantErrContains: `Details: {{name: "attributes", desc: "This is a required field."}}`, }, { - name: "Create a plugin Host", + name: "Create a hostplugin Host", req: &pbs.CreateHostRequest{Item: &pb.Host{ HostCatalogId: pluginHc.GetPublicId(), - Type: "plugin", + Type: "hostplugin", }}, err: handlers.ApiErrorWithCode(codes.InvalidArgument), }, @@ -863,8 +863,8 @@ func TestUpdate_Static(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) @@ -1330,16 +1330,16 @@ func TestUpdate_Plugin(t *testing.T) { rw := db.New(conn) sche := scheduler.TestScheduler(t, conn, wrapper) - pluginRepoFn := func() (*plugin.Repository, error) { - return plugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) + pluginRepoFn := func() (*hostplugin.Repository, error) { + return hostplugin.NewRepository(rw, rw, kms, sche, map[string]plgpb.HostPluginServiceClient{}) } repoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } - plg := hostplugin.TestPlugin(t, conn, "test") - hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) - h := plugin.TestHost(t, conn, hc.GetPublicId(), "test") + plg := plugin.TestPlugin(t, conn, "test") + hc := hostplugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId()) + h := hostplugin.TestHost(t, conn, hc.GetPublicId(), "test") tested, err := hosts.NewService(repoFn, pluginRepoFn) require.NoError(t, err) diff --git a/internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql b/internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql new file mode 100644 index 0000000000..f284f01feb --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql @@ -0,0 +1,65 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: MPL-2.0 + +begin; + +alter table plugin add column description text; +alter table plugin add column create_time wt_timestamp; +alter table plugin add column update_time wt_timestamp; +alter table plugin add column version wt_version; + +-- TODO: check if this needs to be an update or an insert +update plugin as p +set description = ph.description, + create_time = ph.create_time, + update_time = ph.update_time, + version = ph.version +from plugin_host as ph +where p.public_id = ph.public_id; + +-- create new triggers on plugin +create trigger update_version_column after update on plugin + for each row execute procedure update_version_column(); + +create trigger update_time_column before update on plugin + for each row execute procedure update_time_column(); + +create trigger default_create_time_column before insert on plugin + for each row execute procedure default_create_time(); + +drop trigger immutable_columns on plugin; +create trigger immutable_columns before update on plugin + for each row execute procedure immutable_columns('public_id', 'create_time'); + +-- TODO: should these functions be deleted entirely (not dropped as functions)? +drop trigger insert_plugin_subtype on plugin_host; +drop trigger update_plugin_subtype on plugin_host; +drop trigger delete_plugin_subtype on plugin_host; + +create table plugin_host_supported ( + public_id wt_plugin_id primary key + references plugin(public_id) + on delete cascade + on update cascade +); + +-- flag all existing host plugins as being host plugins +insert into plugin_host_supported +(public_id) +select public_id +from plugin_host; + +-- drop existing references to plugin_host, remake to plugin +alter table host_plugin_catalog +drop constraint plugin_host_fkey; + +alter table host_plugin_catalog + add constraint plugin_host_supported_fkey + foreign key (plugin_id) + references plugin_host_supported (public_id) + on delete cascade + on update cascade; + +drop table plugin_host; -- TODO: cascade? + +commit; diff --git a/internal/host/plugin/host_address_test.go b/internal/host/plugin/host_address_test.go index 21723bacaf..6a164cb334 100644 --- a/internal/host/plugin/host_address_test.go +++ b/internal/host/plugin/host_address_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/host" "github.com/hashicorp/boundary/internal/host/store" "github.com/hashicorp/boundary/internal/iam" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -22,7 +22,7 @@ func TestHostDnsName_Create(t *testing.T) { w := db.New(conn) wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) host1 := TestHost(t, conn, cat.GetPublicId(), "external") @@ -153,7 +153,7 @@ func TestHostIpAddress_Create(t *testing.T) { w := db.New(conn) wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) host1 := TestHost(t, conn, cat.GetPublicId(), "external") @@ -292,7 +292,7 @@ func TestHostDnsName_Delete(t *testing.T) { w := db.New(conn) wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) host1 := TestHost(t, conn, cat.GetPublicId(), "external") addr1, err := host.NewDnsName(ctx, host1.GetPublicId(), "addr1.foo.com") @@ -359,7 +359,7 @@ func TestHostIpAddress_Delete(t *testing.T) { w := db.New(conn) wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplugin.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) host1 := TestHost(t, conn, cat.GetPublicId(), "external") addr1, err := host.NewIpAddress(ctx, host1.GetPublicId(), "1.2.3.4") diff --git a/internal/host/plugin/host_catalog_secret_test.go b/internal/host/plugin/host_catalog_secret_test.go index e17fb019c8..cc8bfd4589 100644 --- a/internal/host/plugin/host_catalog_secret_test.go +++ b/internal/host/plugin/host_catalog_secret_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/host/plugin/store" "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" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -27,7 +27,7 @@ func TestHostCatalogSecret_New(t *testing.T) { kkms := kms.TestKms(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) type args struct { @@ -127,7 +127,7 @@ func TestHostCatalogSecret_Create_Upsert_Update_Delete(t *testing.T) { kkms := kms.TestKms(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) ctx := context.Background() diff --git a/internal/host/plugin/host_catalog_test.go b/internal/host/plugin/host_catalog_test.go index c2ac695a91..9a05afc287 100644 --- a/internal/host/plugin/host_catalog_test.go +++ b/internal/host/plugin/host_catalog_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/host/plugin/store" "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" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/aead" "github.com/mr-tron/base58" @@ -29,7 +29,7 @@ func TestHostCatalog_Create(t *testing.T) { conn, _ := db.TestSetup(t, "postgres") wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") type args struct { pluginId string @@ -187,8 +187,8 @@ func TestHostCatalog_Create_DuplicateNames(t *testing.T) { wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) _, prj2 := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test1") - plg2 := host.TestPlugin(t, conn, "test2") + plg := plugin.TestPlugin(t, conn, "test1") + plg2 := plugin.TestPlugin(t, conn, "test2") got, err := NewHostCatalog(ctx, prj.GetPublicId(), plg.GetPublicId(), WithName("duplicate")) require.NoError(t, err) @@ -220,7 +220,7 @@ func TestHostCatalog_Delete(t *testing.T) { conn, _ := db.TestSetup(t, "postgres") wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) ignoredCat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) _ = ignoredCat @@ -271,7 +271,7 @@ func TestHostCatalog_Delete_Cascading(t *testing.T) { t.Run("delete-project", func(t *testing.T) { _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "deletescope") + plg := plugin.TestPlugin(t, conn, "deletescope") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) deleted, err := w.Delete(ctx, prj) @@ -285,7 +285,7 @@ func TestHostCatalog_Delete_Cascading(t *testing.T) { t.Run("delete-plugin", func(t *testing.T) { _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "deleteplugin") + plg := plugin.TestPlugin(t, conn, "deleteplugin") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) deleted, err := w.Delete(ctx, plg) @@ -343,7 +343,7 @@ func TestHostCatalog_SecretsHmac(t *testing.T) { databaseWrapper, err := kmsCache.GetWrapper(ctx, prj.PublicId, kms.KeyPurposeDatabase) require.NoError(t, err) - plg := host.TestPlugin(t, conn, "testplugin") + plg := plugin.TestPlugin(t, conn, "testplugin") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) // stableValue checks that HMACing the same value returns the same result. diff --git a/internal/host/plugin/host_set_member_test.go b/internal/host/plugin/host_set_member_test.go index 56bd579409..a84ddce278 100644 --- a/internal/host/plugin/host_set_member_test.go +++ b/internal/host/plugin/host_set_member_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" "github.com/hashicorp/boundary/internal/oplog" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -33,7 +33,7 @@ func TestHostSetMember_InsertDelete(t *testing.T) { sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "create") + plg := plugin.TestPlugin(t, conn, "create") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}), } diff --git a/internal/host/plugin/host_set_test.go b/internal/host/plugin/host_set_test.go index e483ecac6d..d783cfff66 100644 --- a/internal/host/plugin/host_set_test.go +++ b/internal/host/plugin/host_set_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/iam" - "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" @@ -21,7 +21,7 @@ func TestHostSet_Create(t *testing.T) { conn, _ := db.TestSetup(t, "postgres") wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) cat2 := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) diff --git a/internal/host/plugin/host_test.go b/internal/host/plugin/host_test.go index 6b9609d4ce..2c300e5481 100644 --- a/internal/host/plugin/host_test.go +++ b/internal/host/plugin/host_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/iam" - "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -19,7 +19,7 @@ func TestHost_Create(t *testing.T) { conn, _ := db.TestSetup(t, "postgres") wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) cat2 := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) diff --git a/internal/host/plugin/immutable_fields_test.go b/internal/host/plugin/immutable_fields_test.go index 342f7cc604..e53fd14b3a 100644 --- a/internal/host/plugin/immutable_fields_test.go +++ b/internal/host/plugin/immutable_fields_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/boundary/internal/host/plugin/store" "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" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -28,8 +28,8 @@ func TestPluginCatalog_ImmutableFields(t *testing.T) { wrapper := db.TestWrapper(t) ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} o, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") - plg2 := host.TestPlugin(t, conn, "test2") + plg := plugin.TestPlugin(t, conn, "test") + plg2 := plugin.TestPlugin(t, conn, "test2") new := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) tests := []struct { @@ -105,7 +105,7 @@ func TestPluginSet_ImmutableFields(t *testing.T) { ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) new := TestSet(t, conn, kmsCache, sched, cat, map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), diff --git a/internal/host/plugin/job_orphaned_host_cleanup_test.go b/internal/host/plugin/job_orphaned_host_cleanup_test.go index 2976ffc158..cf48c0c071 100644 --- a/internal/host/plugin/job_orphaned_host_cleanup_test.go +++ b/internal/host/plugin/job_orphaned_host_cleanup_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -106,7 +106,7 @@ func TestOrphanedHostCleanupJob_Run(t *testing.T) { sched := scheduler.TestScheduler(t, conn, wrapper) plgServer := &TestPluginServer{} - plg := hostplg.TestPlugin(t, conn, "run") + plg := plugin.TestPlugin(t, conn, "run") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(plgServer), } diff --git a/internal/host/plugin/job_set_sync_test.go b/internal/host/plugin/job_set_sync_test.go index c47023a932..a980be77af 100644 --- a/internal/host/plugin/job_set_sync_test.go +++ b/internal/host/plugin/job_set_sync_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" assertpkg "github.com/stretchr/testify/assert" @@ -29,7 +29,7 @@ func TestNewSetSyncJob(t *testing.T) { wrapper := db.TestWrapper(t) kmsCache := kms.TestKms(t, conn, wrapper) - plg := hostplg.TestPlugin(t, conn, "lookup") + plg := plugin.TestPlugin(t, conn, "lookup") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), } @@ -143,7 +143,7 @@ func TestSetSyncJob_Run(t *testing.T) { sched := scheduler.TestScheduler(t, conn, wrapper) plgServer := &TestPluginServer{} - plg := hostplg.TestPlugin(t, conn, "run") + plg := plugin.TestPlugin(t, conn, "run") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(plgServer), } @@ -411,7 +411,7 @@ func TestSetSyncJob_NextRunIn(t *testing.T) { kmsCache := kms.TestKms(t, conn, wrapper) iamRepo := iam.TestRepo(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "lookup") + plg := plugin.TestPlugin(t, conn, "lookup") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), } diff --git a/internal/host/plugin/repository_host.go b/internal/host/plugin/repository_host.go index 51b36a1238..8ba6ed0eb2 100644 --- a/internal/host/plugin/repository_host.go +++ b/internal/host/plugin/repository_host.go @@ -9,12 +9,12 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/errors" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" ) // LookupHost will look up a host in the repository. If the host is not // found, it will return nil, nil. All options are ignored. -func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, *hostplugin.Plugin, error) { +func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, *plugin.Plugin, error) { const op = "plugin.(Repository).LookupHost" if publicId == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "no public id") @@ -37,7 +37,7 @@ func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Opt // ListHostsByCatalogId returns a slice of Hosts for the catalogId. // WithLimit is the only option supported. -func (r *Repository) ListHostsByCatalogId(ctx context.Context, catalogId string, opt ...Option) ([]*Host, *hostplugin.Plugin, error) { +func (r *Repository) ListHostsByCatalogId(ctx context.Context, catalogId string, opt ...Option) ([]*Host, *plugin.Plugin, error) { const op = "plugin.(Repository).ListHostsByCatalogId" if catalogId == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "no catalog id") diff --git a/internal/host/plugin/repository_host_catalog.go b/internal/host/plugin/repository_host_catalog.go index 2150202f19..fa43d12e1e 100644 --- a/internal/host/plugin/repository_host_catalog.go +++ b/internal/host/plugin/repository_host_catalog.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/boundary/internal/libs/patchstruct" "github.com/hashicorp/boundary/internal/observability/event" "github.com/hashicorp/boundary/internal/oplog" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + plg "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/util" pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostcatalogs" @@ -71,7 +71,7 @@ func normalizeCatalogAttributes(ctx context.Context, plgClient plgpb.HostPluginS // not included in the returned *HostCatalog. // // Both c.CreateTime and c.UpdateTime are ignored. -func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, _ ...Option) (*HostCatalog, *hostplugin.Plugin, error) { +func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, _ ...Option) (*HostCatalog, *plg.Plugin, error) { const op = "plugin.(Repository).CreateCatalog" if c == nil { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "nil HostCatalog") @@ -236,7 +236,7 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, _ ...Opt // updated, along with any secrets included in the new request. This // request may alter the returned persisted state. Update of the // record in the database is aborted if this call fails. -func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, _ ...Option) (*HostCatalog, *hostplugin.Plugin, int, error) { +func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, _ ...Option) (*HostCatalog, *plg.Plugin, int, error) { const op = "plugin.(Repository).UpdateCatalog" if c == nil { return nil, nil, db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "nil HostCatalog") @@ -570,7 +570,7 @@ func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version // LookupCatalog returns the HostCatalog for id. Returns nil, nil if no // HostCatalog is found for id. -func (r *Repository) LookupCatalog(ctx context.Context, id string, _ ...Option) (*HostCatalog, *hostplugin.Plugin, error) { +func (r *Repository) LookupCatalog(ctx context.Context, id string, _ ...Option) (*HostCatalog, *plg.Plugin, error) { const op = "plugin.(Repository).LookupCatalog" if id == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "no public id") @@ -590,7 +590,7 @@ func (r *Repository) LookupCatalog(ctx context.Context, id string, _ ...Option) } // ListCatalogs returns a slice of HostCatalogs for the project IDs. WithLimit is the only option supported. -func (r *Repository) ListCatalogs(ctx context.Context, projectIds []string, opt ...host.Option) ([]*HostCatalog, []*hostplugin.Plugin, error) { +func (r *Repository) ListCatalogs(ctx context.Context, projectIds []string, opt ...host.Option) ([]*HostCatalog, []*plg.Plugin, error) { const op = "plugin.(Repository).ListCatalogs" if len(projectIds) == 0 { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "no project id") @@ -612,7 +612,7 @@ func (r *Repository) ListCatalogs(ctx context.Context, projectIds []string, opt for _, c := range hostCatalogs { plgIds = append(plgIds, c.PluginId) } - var plgs []*hostplugin.Plugin + var plgs []*plg.Plugin if err := r.reader.SearchWhere(ctx, &plgs, "public_id in (?)", []any{plgIds}); err != nil { return nil, nil, errors.Wrap(ctx, err, op) } @@ -725,12 +725,12 @@ func (r *Repository) getCatalog(ctx context.Context, id string) (*HostCatalog, * return c, p, nil } -func (r *Repository) getPlugin(ctx context.Context, plgId string) (*hostplugin.Plugin, error) { +func (r *Repository) getPlugin(ctx context.Context, plgId string) (*plg.Plugin, error) { const op = "plugin.(Repository).getPlugin" if plgId == "" { return nil, errors.New(ctx, errors.InvalidParameter, op, "no plugin id") } - plg := hostplugin.NewPlugin() + plg := plg.NewPlugin() plg.PublicId = plgId if err := r.reader.LookupByPublicId(ctx, plg); err != nil { return nil, errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("unable to get host plugin with id %q", plgId))) diff --git a/internal/host/plugin/repository_host_catalog_test.go b/internal/host/plugin/repository_host_catalog_test.go index bba0b11584..e5db80dc5a 100644 --- a/internal/host/plugin/repository_host_catalog_test.go +++ b/internal/host/plugin/repository_host_catalog_test.go @@ -20,8 +20,7 @@ import ( "github.com/hashicorp/boundary/internal/kms" "github.com/hashicorp/boundary/internal/libs/patchstruct" "github.com/hashicorp/boundary/internal/oplog" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/scheduler/job" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" @@ -41,8 +40,8 @@ func TestRepository_CreateCatalog(t *testing.T) { wrapper := db.TestWrapper(t) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "test") - unimplementedPlugin := hostplg.TestPlugin(t, conn, "unimplemented") + plg := plugin.TestPlugin(t, conn, "test") + unimplementedPlugin := plugin.TestPlugin(t, conn, "unimplemented") const normalizeToSliceKey = "normalize_to_slice" @@ -495,7 +494,7 @@ func TestRepository_UpdateCatalog(t *testing.T) { var setRespSecretsNil bool var gotOnUpdateCatalogRequest *plgpb.OnUpdateCatalogRequest var pluginError error - testPlugin := hostplg.TestPlugin(t, dbConn, "test") + testPlugin := plugin.TestPlugin(t, dbConn, "test") testPluginMap := map[string]plgpb.HostPluginServiceClient{ testPlugin.GetPublicId(): &WrappingPluginClient{ Server: &TestPluginServer{ @@ -1232,7 +1231,7 @@ func TestRepository_UpdateCatalog(t *testing.T) { } setRespSecretsNil = tt.withRespSecretsNil - var gotPlugin *hostplugin.Plugin + var gotPlugin *plugin.Plugin gotCatalog, gotPlugin, gotNumUpdated, err = repo.UpdateCatalog(ctx, workingCat, tt.version, tt.fieldMask) if tt.wantIsErr != 0 { require.Equal(db.NoRowsAffected, gotNumUpdated) @@ -1263,7 +1262,7 @@ func TestRepository_LookupCatalog(t *testing.T) { wrapper := db.TestWrapper(t) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}}, } @@ -1330,7 +1329,7 @@ func TestRepository_ListCatalogs_Multiple_Scopes(t *testing.T) { rw := db.New(conn) kms := kms.TestKms(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) - plg := hostplg.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}}, } @@ -1363,7 +1362,7 @@ func TestRepository_DeleteCatalog(t *testing.T) { wrapper := db.TestWrapper(t) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") pluginInstance := &TestPluginServer{} plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): &WrappingPluginClient{Server: pluginInstance}, @@ -1449,7 +1448,7 @@ func TestRepository_DeleteCatalogX(t *testing.T) { wrapper := db.TestWrapper(t) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "test") + plg := plugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}}, } @@ -1537,7 +1536,7 @@ func TestRepository_UpdateCatalog_SyncSets(t *testing.T) { dbKmsCache := kms.TestKms(t, dbConn, dbWrapper) _, projectScope := iam.TestScopes(t, iam.TestRepo(t, dbConn, dbWrapper)) - testPlugin := hostplg.TestPlugin(t, dbConn, "test") + testPlugin := plugin.TestPlugin(t, dbConn, "test") dummyPluginMap := map[string]plgpb.HostPluginServiceClient{ testPlugin.GetPublicId(): &WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}}, } diff --git a/internal/host/plugin/repository_host_set.go b/internal/host/plugin/repository_host_set.go index ef93818c97..5736b790f0 100644 --- a/internal/host/plugin/repository_host_set.go +++ b/internal/host/plugin/repository_host_set.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/boundary/internal/libs/endpoint" "github.com/hashicorp/boundary/internal/libs/patchstruct" "github.com/hashicorp/boundary/internal/oplog" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/util" pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets" @@ -68,7 +68,7 @@ func normalizeSetAttributes(ctx context.Context, plgClient plgpb.HostPluginServi // // Both s.Name and s.Description are optional. If s.Name is set, it must be // unique within s.CatalogId. -func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet, _ ...Option) (*HostSet, *hostplugin.Plugin, error) { +func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet, _ ...Option) (*HostSet, *iplugin.Plugin, error) { const op = "plugin.(Repository).CreateSet" if s == nil { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "nil HostSet") @@ -239,7 +239,7 @@ func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet // record written, but some plugins may perform some actions on this // call. Update of the record in the database is aborted if this call // fails. -func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet, version uint32, fieldMask []string, opt ...Option) (*HostSet, []*Host, *hostplugin.Plugin, int, error) { +func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet, version uint32, fieldMask []string, opt ...Option) (*HostSet, []*Host, *iplugin.Plugin, int, error) { const op = "plugin.(Repository).UpdateSet" if s == nil { return nil, nil, nil, db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "nil HostSet") @@ -572,7 +572,7 @@ func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet // LookupSet will look up a host set in the repository and return the host set, // as well as host IDs that match. If the host set is not found, it will return // nil, nil, nil. No options are currently supported. -func (r *Repository) LookupSet(ctx context.Context, publicId string, _ ...host.Option) (*HostSet, *hostplugin.Plugin, error) { +func (r *Repository) LookupSet(ctx context.Context, publicId string, _ ...host.Option) (*HostSet, *iplugin.Plugin, error) { const op = "plugin.(Repository).LookupSet" if publicId == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "no public id") @@ -595,7 +595,7 @@ func (r *Repository) LookupSet(ctx context.Context, publicId string, _ ...host.O // ListSets returns a slice of HostSets for the catalogId. WithLimit is the // only option supported. -func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...host.Option) ([]*HostSet, *hostplugin.Plugin, error) { +func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...host.Option) ([]*HostSet, *iplugin.Plugin, error) { const op = "plugin.(Repository).ListSets" if catalogId == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing catalog id") @@ -683,7 +683,7 @@ func (r *Repository) DeleteSet(ctx context.Context, projectId string, publicId s return rowsDeleted, nil } -func (r *Repository) getSets(ctx context.Context, publicId string, catalogId string, opt ...host.Option) ([]*HostSet, *hostplugin.Plugin, error) { +func (r *Repository) getSets(ctx context.Context, publicId string, catalogId string, opt ...host.Option) ([]*HostSet, *iplugin.Plugin, error) { const op = "plugin.(Repository).getSets" if publicId == "" && catalogId == "" { return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing search criteria: both host set id and catalog id are empty") @@ -741,7 +741,7 @@ func (r *Repository) getSets(ctx context.Context, publicId string, catalogId str } sets = append(sets, hs) } - var plg *hostplugin.Plugin + var plg *iplugin.Plugin if plgId != "" { plg, err = r.getPlugin(ctx, plgId) if err != nil { diff --git a/internal/host/plugin/repository_host_set_test.go b/internal/host/plugin/repository_host_set_test.go index e123e4655b..069a43653b 100644 --- a/internal/host/plugin/repository_host_set_test.go +++ b/internal/host/plugin/repository_host_set_test.go @@ -23,7 +23,7 @@ import ( "github.com/hashicorp/boundary/internal/kms" "github.com/hashicorp/boundary/internal/libs/patchstruct" "github.com/hashicorp/boundary/internal/oplog" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/mitchellh/mapstructure" @@ -43,8 +43,8 @@ func TestRepository_CreateSet(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "create") - unimplementedPlugin := hostplg.TestPlugin(t, conn, "unimplemented") + plg := iplugin.TestPlugin(t, conn, "create") + unimplementedPlugin := iplugin.TestPlugin(t, conn, "unimplemented") catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) unimplementedPluginCatalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) @@ -459,7 +459,7 @@ func TestRepository_UpdateSet(t *testing.T) { dbKmsCache := kms.TestKms(t, dbConn, dbWrapper) _, projectScope := iam.TestScopes(t, iam.TestRepo(t, dbConn, dbWrapper)) - testPlugin := hostplg.TestPlugin(t, dbConn, "test") + testPlugin := iplugin.TestPlugin(t, dbConn, "test") dummyPluginMap := map[string]plgpb.HostPluginServiceClient{ testPlugin.GetPublicId(): &WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}}, } @@ -1349,7 +1349,7 @@ func TestRepository_LookupSet(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "lookup") + plg := iplugin.TestPlugin(t, conn, "lookup") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), } @@ -1418,7 +1418,7 @@ func TestRepository_Endpoints(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "endpoints") + plg := iplugin.TestPlugin(t, conn, "endpoints") hostlessCatalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) plgm := map[string]plgpb.HostPluginServiceClient{ @@ -1554,7 +1554,7 @@ func TestRepository_ListSets(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "list") + plg := iplugin.TestPlugin(t, conn, "list") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), } @@ -1626,7 +1626,7 @@ func TestRepository_ListSets_Limits(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "listlimit") + plg := iplugin.TestPlugin(t, conn, "listlimit") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}), } @@ -1705,7 +1705,7 @@ func TestRepository_DeleteSet(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) sched := scheduler.TestScheduler(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "create") + plg := iplugin.TestPlugin(t, conn, "create") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) { diff --git a/internal/host/plugin/repository_host_test.go b/internal/host/plugin/repository_host_test.go index 144da9961e..1d935be6b6 100644 --- a/internal/host/plugin/repository_host_test.go +++ b/internal/host/plugin/repository_host_test.go @@ -19,8 +19,8 @@ import ( "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" "github.com/hashicorp/boundary/internal/oplog" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" - hostplgstore "github.com/hashicorp/boundary/internal/plugin/host/store" + iplugin "github.com/hashicorp/boundary/internal/plugin" + plgstore "github.com/hashicorp/boundary/internal/plugin/store" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -37,7 +37,7 @@ func TestJob_UpsertHosts(t *testing.T) { iamRepo := iam.TestRepo(t, conn, wrapper) _, prj := iam.TestScopes(t, iamRepo) - plg := hostplg.TestPlugin(t, conn, "create") + plg := iplugin.TestPlugin(t, conn, "create") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}), } @@ -228,7 +228,7 @@ func TestJob_UpsertHosts(t *testing.T) { require.NotNil(repo) // Check again, but via performing an explicit list - var gotPlg *hostplg.Plugin + var gotPlg *iplugin.Plugin got, gotPlg, err = repo.ListHostsByCatalogId(ctx, in.catalog.GetPublicId()) require.NoError(err) assert.Len(got, len(in.phs)) @@ -251,7 +251,7 @@ func TestJob_UpsertHosts(t *testing.T) { cmp.Diff( plg, gotPlg, - cmpopts.IgnoreUnexported(hostplg.Plugin{}, hostplgstore.Plugin{}), + cmpopts.IgnoreUnexported(iplugin.Plugin{}, plgstore.Plugin{}), cmpopts.IgnoreTypes(×tamp.Timestamp{}), ), ) @@ -279,7 +279,7 @@ func TestJob_UpsertHosts(t *testing.T) { cmp.Diff( plg, gotPlg, - cmpopts.IgnoreUnexported(hostplg.Plugin{}, hostplgstore.Plugin{}), + cmpopts.IgnoreUnexported(iplugin.Plugin{}, plgstore.Plugin{}), cmpopts.IgnoreTypes(×tamp.Timestamp{}), ), ) diff --git a/internal/host/plugin/rewrapping_test.go b/internal/host/plugin/rewrapping_test.go index 095f9f74de..b73f55bbec 100644 --- a/internal/host/plugin/rewrapping_test.go +++ b/internal/host/plugin/rewrapping_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/go-kms-wrapping/extras/kms/v2/migrations" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -42,7 +42,7 @@ func TestRewrap_hostCatalogSecretRewrapFn(t *testing.T) { rw := db.New(conn) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") cat := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId()) secret, err := newHostCatalogSecret(ctx, cat.GetPublicId(), mustStruct(map[string]any{ "foo": "bar", diff --git a/internal/host/plugin/testing.go b/internal/host/plugin/testing.go index b1ba852d17..f9c90cdb97 100644 --- a/internal/host/plugin/testing.go +++ b/internal/host/plugin/testing.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/boundary/internal/host" "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/kms" - hostplugin "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/hashicorp/go-secure-stdlib/base62" @@ -48,7 +48,7 @@ func TestCatalog(t testing.TB, conn *db.DB, projectId, pluginId string, opt ...O require.NoError(t, err) assert.NotNil(t, cat) - plg := hostplugin.NewPlugin() + plg := iplugin.NewPlugin() plg.PublicId = pluginId require.NoError(t, w.LookupByPublicId(ctx, plg)) @@ -77,7 +77,7 @@ func TestSet(t testing.TB, conn *db.DB, kmsCache *kms.Kms, sched *scheduler.Sche require.NoError(err) require.NotNil(set) - plg := hostplugin.NewPlugin() + plg := iplugin.NewPlugin() plg.PublicId = hc.GetPluginId() require.NoError(rw.LookupByPublicId(ctx, plg)) diff --git a/internal/host/plugin/testing_test.go b/internal/host/plugin/testing_test.go index 1642fa44c6..e62cc6eaf3 100644 --- a/internal/host/plugin/testing_test.go +++ b/internal/host/plugin/testing_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -26,7 +26,7 @@ func Test_TestCatalogs(t *testing.T) { require.NotNil(proj) assert.NotEmpty(proj.GetPublicId()) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) @@ -47,7 +47,7 @@ func Test_TestSet(t *testing.T) { require.NotNil(prj) assert.NotEmpty(prj.GetPublicId()) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) @@ -65,7 +65,7 @@ func Test_TestHosts(t *testing.T) { wrapper := db.TestWrapper(t) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) @@ -88,7 +88,7 @@ func Test_TestSetMembers(t *testing.T) { require.NotNil(prj) assert.NotEmpty(prj.GetPublicId()) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) @@ -112,7 +112,7 @@ func Test_TestRunSetSync(t *testing.T) { require.NotNil(prj) assert.NotEmpty(prj.GetPublicId()) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) pluginServer := &TestPluginServer{} diff --git a/internal/plugin/host/doc.go b/internal/plugin/host/doc.go deleted file mode 100644 index 653404f113..0000000000 --- a/internal/plugin/host/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -// Package host provides a plugin type used to interface with boundary's host -// related resources. Additionally it provides a repository for performing -// CRUDL and custom operations on this plugin type. -package host diff --git a/internal/plugin/host/immutable_fields_test.go b/internal/plugin/host/immutable_fields_test.go deleted file mode 100644 index f857a10a78..0000000000 --- a/internal/plugin/host/immutable_fields_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package host - -import ( - "context" - "testing" - - "github.com/hashicorp/boundary/internal/db" - "github.com/hashicorp/boundary/internal/db/timestamp" - "github.com/hashicorp/boundary/internal/plugin/host/store" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/timestamppb" -) - -func TestHostPlugin_ImmutableFields(t *testing.T) { - t.Parallel() - conn, _ := db.TestSetup(t, "postgres") - w := db.New(conn) - - ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} - plg := TestPlugin(t, conn, "test") - - newPlugin := plg - - tests := []struct { - name string - update *Plugin - fieldMask []string - }{ - { - name: "public_id", - update: func() *Plugin { - c := newPlugin.testClonePlugin() - c.PublicId = "hc_thisIsNotAValidId" - return c - }(), - fieldMask: []string{"PublicId"}, - }, - { - name: "create time", - update: func() *Plugin { - c := newPlugin.testClonePlugin() - c.CreateTime = &ts - return c - }(), - fieldMask: []string{"CreateTime"}, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - assert, require := assert.New(t), require.New(t) - orig := newPlugin.testClonePlugin() - err := w.LookupById(context.Background(), orig) - require.NoError(err) - - rowsUpdated, err := w.Update(context.Background(), tt.update, tt.fieldMask, nil, db.WithSkipVetForWrite(true)) - require.Error(err) - assert.Equal(0, rowsUpdated) - - after := newPlugin.testClonePlugin() - err = w.LookupById(context.Background(), after) - require.NoError(err) - - assert.True(proto.Equal(orig, after)) - }) - } -} - -func (c *Plugin) testClonePlugin() *Plugin { - cp := proto.Clone(c.Plugin) - return &Plugin{ - Plugin: cp.(*store.Plugin), - } -} diff --git a/internal/plugin/host/store/plugin.pb.go b/internal/plugin/host/store/plugin.pb.go deleted file mode 100644 index 2d6f46890b..0000000000 --- a/internal/plugin/host/store/plugin.pb.go +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.30.0 -// protoc (unknown) -// source: controller/storage/plugin/host/store/v1/plugin.proto - -// Package store provides protobufs for storing types in the host package. - -package store - -import ( - timestamp "github.com/hashicorp/boundary/internal/db/timestamp" - _ "github.com/hashicorp/boundary/sdk/pbs/controller/protooptions" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Plugin struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // public_id is a surrogate key suitable for use in a public API. - // @inject_tag: `gorm:"primary_key"` - PublicId string `protobuf:"bytes,10,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty" gorm:"primary_key"` - // The create_time is set by the database. - // @inject_tag: `gorm:"default:current_timestamp"` - CreateTime *timestamp.Timestamp `protobuf:"bytes,20,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"` - // The update_time is set by the database. - // @inject_tag: `gorm:"default:current_timestamp"` - UpdateTime *timestamp.Timestamp `protobuf:"bytes,30,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"` - // name is optional. If set, it must be unique within scope_id. - // @inject_tag: `gorm:"default:null"` - Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"` - // description is optional. - // @inject_tag: `gorm:"default:null"` - Description string `protobuf:"bytes,50,opt,name=description,proto3" json:"description,omitempty" gorm:"default:null"` - // The scope_id of the owning scope and must be set. - // @inject_tag: `gorm:"not_null"` - ScopeId string `protobuf:"bytes,60,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty" gorm:"not_null"` - // @inject_tag: `gorm:"default:null"` - Version uint32 `protobuf:"varint,70,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"` -} - -func (x *Plugin) Reset() { - *x = Plugin{} - if protoimpl.UnsafeEnabled { - mi := &file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Plugin) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Plugin) ProtoMessage() {} - -func (x *Plugin) ProtoReflect() protoreflect.Message { - mi := &file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Plugin.ProtoReflect.Descriptor instead. -func (*Plugin) Descriptor() ([]byte, []int) { - return file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescGZIP(), []int{0} -} - -func (x *Plugin) GetPublicId() string { - if x != nil { - return x.PublicId - } - return "" -} - -func (x *Plugin) GetCreateTime() *timestamp.Timestamp { - if x != nil { - return x.CreateTime - } - return nil -} - -func (x *Plugin) GetUpdateTime() *timestamp.Timestamp { - if x != nil { - return x.UpdateTime - } - return nil -} - -func (x *Plugin) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Plugin) GetDescription() string { - if x != nil { - return x.Description - } - return "" -} - -func (x *Plugin) GetScopeId() string { - if x != nil { - return x.ScopeId - } - return "" -} - -func (x *Plugin) GetVersion() uint32 { - if x != nil { - return x.Version - } - return 0 -} - -var File_controller_storage_plugin_host_store_v1_plugin_proto protoreflect.FileDescriptor - -var file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc = []byte{ - 0x0a, 0x34, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, 0x6f, - 0x72, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x68, 0x6f, 0x73, 0x74, - 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x27, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, - 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, - 0x6e, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x76, 0x31, 0x1a, - 0x2a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x63, 0x75, 0x73, 0x74, - 0x6f, 0x6d, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2f, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2f, - 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x69, 0x6d, - 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdc, 0x02, 0x0a, - 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, - 0x63, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, - 0x69, 0x63, 0x49, 0x64, 0x12, 0x4b, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, - 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, - 0x65, 0x12, 0x4b, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, - 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x24, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x10, 0xc2, 0xdd, - 0x29, 0x0c, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x40, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x32, 0x20, 0x01, 0x28, 0x09, 0x42, 0x1e, 0xc2, 0xdd, 0x29, 0x1a, 0x0a, - 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x64, 0x65, - 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, - 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f, - 0x69, 0x64, 0x18, 0x3c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x49, - 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x46, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x40, 0x5a, 0x3e, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, - 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x68, 0x6f, 0x73, - 0x74, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescOnce sync.Once - file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData = file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc -) - -func file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescGZIP() []byte { - file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescOnce.Do(func() { - file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData = protoimpl.X.CompressGZIP(file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData) - }) - return file_controller_storage_plugin_host_store_v1_plugin_proto_rawDescData -} - -var file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes = []interface{}{ - (*Plugin)(nil), // 0: controller.storage.plugin.host.store.v1.Plugin - (*timestamp.Timestamp)(nil), // 1: controller.storage.timestamp.v1.Timestamp -} -var file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs = []int32{ - 1, // 0: controller.storage.plugin.host.store.v1.Plugin.create_time:type_name -> controller.storage.timestamp.v1.Timestamp - 1, // 1: controller.storage.plugin.host.store.v1.Plugin.update_time:type_name -> controller.storage.timestamp.v1.Timestamp - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_controller_storage_plugin_host_store_v1_plugin_proto_init() } -func file_controller_storage_plugin_host_store_v1_plugin_proto_init() { - if File_controller_storage_plugin_host_store_v1_plugin_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Plugin); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes, - DependencyIndexes: file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs, - MessageInfos: file_controller_storage_plugin_host_store_v1_plugin_proto_msgTypes, - }.Build() - File_controller_storage_plugin_host_store_v1_plugin_proto = out.File - file_controller_storage_plugin_host_store_v1_plugin_proto_rawDesc = nil - file_controller_storage_plugin_host_store_v1_plugin_proto_goTypes = nil - file_controller_storage_plugin_host_store_v1_plugin_proto_depIdxs = nil -} diff --git a/internal/plugin/host/testing.go b/internal/plugin/host/testing.go deleted file mode 100644 index d77b370dd5..0000000000 --- a/internal/plugin/host/testing.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package host - -import ( - "context" - "testing" - - "github.com/hashicorp/boundary/internal/db" - "github.com/stretchr/testify/require" -) - -func TestPlugin(t testing.TB, conn *db.DB, name string) *Plugin { - t.Helper() - 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)) - return p -} diff --git a/internal/plugin/host/testing_test.go b/internal/plugin/host/testing_test.go deleted file mode 100644 index 5d79c24cce..0000000000 --- a/internal/plugin/host/testing_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package host - -import ( - "testing" - - "github.com/hashicorp/boundary/internal/db" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func Test_TestPlugins(t *testing.T) { - assert, require := assert.New(t), require.New(t) - conn, _ := db.TestSetup(t, "postgres") - - plg := TestPlugin(t, conn, "test") - require.NotNil(plg) - assert.NotEmpty(plg.GetPublicId()) -} diff --git a/internal/plugin/host/ids.go b/internal/plugin/ids.go similarity index 96% rename from internal/plugin/host/ids.go rename to internal/plugin/ids.go index 513529aaa2..dce9587fd6 100644 --- a/internal/plugin/host/ids.go +++ b/internal/plugin/ids.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "github.com/hashicorp/boundary/internal/db" diff --git a/internal/plugin/immutable_fields_test.go b/internal/plugin/immutable_fields_test.go index e2dcc89a1d..930f04abc5 100644 --- a/internal/plugin/immutable_fields_test.go +++ b/internal/plugin/immutable_fields_test.go @@ -8,42 +8,46 @@ import ( "testing" "github.com/hashicorp/boundary/internal/db" + "github.com/hashicorp/boundary/internal/db/timestamp" "github.com/hashicorp/boundary/internal/plugin/store" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" ) -func TestPlugin_ImmutableFields(t *testing.T) { +func TestHostPlugin_ImmutableFields(t *testing.T) { t.Parallel() conn, _ := db.TestSetup(t, "postgres") w := db.New(conn) - plg := testPlugin(t, conn, "test") + + ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}} + plg := TestPlugin(t, conn, "test") newPlugin := plg tests := []struct { name string - update *plugin + update *Plugin fieldMask []string }{ { name: "public_id", - update: func() *plugin { + update: func() *Plugin { c := newPlugin.testClonePlugin() - c.PublicId = "pi_thisIsNotAValidId" + c.PublicId = "hc_thisIsNotAValidId" return c }(), fieldMask: []string{"PublicId"}, }, { - name: "scope", - update: func() *plugin { + name: "create time", + update: func() *Plugin { c := newPlugin.testClonePlugin() - c.ScopeId = "o_1234567890" + c.CreateTime = &ts return c }(), - fieldMask: []string{"ScopeId"}, + fieldMask: []string{"CreateTime"}, }, } for _, tt := range tests { @@ -67,9 +71,9 @@ func TestPlugin_ImmutableFields(t *testing.T) { } } -func (c *plugin) testClonePlugin() *plugin { +func (c *Plugin) testClonePlugin() *Plugin { cp := proto.Clone(c.Plugin) - return &plugin{ + return &Plugin{ Plugin: cp.(*store.Plugin), } } diff --git a/internal/plugin/host/options.go b/internal/plugin/options.go similarity index 98% rename from internal/plugin/host/options.go rename to internal/plugin/options.go index ce6ed24f96..57aadd06f1 100644 --- a/internal/plugin/host/options.go +++ b/internal/plugin/options.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin // GetOpts - iterate the inbound Options and return a struct func GetOpts(opt ...Option) options { diff --git a/internal/plugin/host/options_test.go b/internal/plugin/options_test.go similarity index 98% rename from internal/plugin/host/options_test.go rename to internal/plugin/options_test.go index e7e29c1eef..7f5de942e1 100644 --- a/internal/plugin/host/options_test.go +++ b/internal/plugin/options_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "testing" diff --git a/internal/plugin/host/plugin.go b/internal/plugin/plugin.go similarity index 78% rename from internal/plugin/host/plugin.go rename to internal/plugin/plugin.go index c53933f403..7e5291de89 100644 --- a/internal/plugin/host/plugin.go +++ b/internal/plugin/plugin.go @@ -1,15 +1,28 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "github.com/hashicorp/boundary/internal/oplog" - "github.com/hashicorp/boundary/internal/plugin/host/store" + "github.com/hashicorp/boundary/internal/plugin/store" "github.com/hashicorp/boundary/internal/types/scope" "google.golang.org/protobuf/proto" ) +type PluginType int + +const ( + PluginTypeUnknown PluginType = 0 + PluginTypeHost PluginType = 1 +) + +// pluginTypeDbMap is a map from PluginType to the db table name where the flag for that plugin type lives +// these tables are usually named "plugin__supported" +var pluginTypeDbMap = map[PluginType]string{ + PluginTypeHost: "plugin_host_supported", +} + // A Plugin enables additional logic to be used by boundary. // It is owned by a scope. type Plugin struct { @@ -36,7 +49,7 @@ func (c *Plugin) TableName() string { if c.tableName != "" { return c.tableName } - return "plugin_host" + return "plugin" } // SetTableName sets the table name. If the caller attempts to diff --git a/internal/plugin/host/plugin_test.go b/internal/plugin/plugin_test.go similarity index 96% rename from internal/plugin/host/plugin_test.go rename to internal/plugin/plugin_test.go index c970a11d66..00b65ff685 100644 --- a/internal/plugin/host/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "context" @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/hashicorp/boundary/internal/db" - "github.com/hashicorp/boundary/internal/plugin/host/store" + "github.com/hashicorp/boundary/internal/plugin/store" ) func TestPlugin_Create(t *testing.T) { @@ -121,7 +121,7 @@ func TestPlugin_Delete(t *testing.T) { } func TestPlugin_SetTableName(t *testing.T) { - defaultTableName := "plugin_host" + defaultTableName := "plugin" tests := []struct { name string initialName string diff --git a/internal/plugin/query.go b/internal/plugin/query.go new file mode 100644 index 0000000000..b18056b52b --- /dev/null +++ b/internal/plugin/query.go @@ -0,0 +1,5 @@ +package plugin + +const ( + addSupportFlagQuery = "insert into %s (public_id) values (?) on conflict do nothing;" +) diff --git a/internal/plugin/host/repository.go b/internal/plugin/repository.go similarity index 99% rename from internal/plugin/host/repository.go rename to internal/plugin/repository.go index 3660a25259..964ab9ae1c 100644 --- a/internal/plugin/host/repository.go +++ b/internal/plugin/repository.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "github.com/hashicorp/boundary/internal/db" diff --git a/internal/plugin/host/repository_plugin.go b/internal/plugin/repository_plugin.go similarity index 84% rename from internal/plugin/host/repository_plugin.go rename to internal/plugin/repository_plugin.go index 42fc36be03..ad71929ba0 100644 --- a/internal/plugin/host/repository_plugin.go +++ b/internal/plugin/repository_plugin.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "context" @@ -24,7 +24,7 @@ import ( // // Both p.CreateTime and c.UpdateTime are ignored. func (r *Repository) CreatePlugin(ctx context.Context, p *Plugin, opt ...Option) (*Plugin, error) { - const op = "host.(Repository).CreatePlugin" + const op = "plugin.(Repository).CreatePlugin" if p == nil { return nil, errors.New(ctx, errors.InvalidParameter, op, "nil Plugin") } @@ -91,7 +91,7 @@ func (r *Repository) CreatePlugin(ctx context.Context, p *Plugin, opt ...Option) // LookupPlugin returns the Plugin for id. Returns nil, nil if no // Plugin is found for id. func (r *Repository) LookupPlugin(ctx context.Context, id string, _ ...Option) (*Plugin, error) { - const op = "host.(Repository).LookupPlugin" + const op = "plugin.(Repository).LookupPlugin" if id == "" { return nil, errors.New(ctx, errors.InvalidParameter, op, "no public id") } @@ -109,7 +109,7 @@ func (r *Repository) LookupPlugin(ctx context.Context, id string, _ ...Option) ( // LookupPluginByName returns the Plugin for a given name. Returns nil, nil if no // Plugin is found with that plugin name. func (r *Repository) LookupPluginByName(ctx context.Context, name string, _ ...Option) (*Plugin, error) { - const op = "host.(Repository).LookupPluginByName" + const op = "plugin.(Repository).LookupPluginByName" if name == "" { return nil, errors.New(ctx, errors.InvalidParameter, op, "no plugin name") } @@ -126,7 +126,7 @@ func (r *Repository) LookupPluginByName(ctx context.Context, name string, _ ...O // ListPlugins returns a slice of Plugins for the scope IDs. WithLimit is the only option supported. func (r *Repository) ListPlugins(ctx context.Context, scopeIds []string, opt ...Option) ([]*Plugin, error) { - const op = "host.(Repository).ListPlugins" + const op = "plugin.(Repository).ListPlugins" if len(scopeIds) == 0 { return nil, errors.New(ctx, errors.InvalidParameter, op, "no scope id") } @@ -143,3 +143,20 @@ func (r *Repository) ListPlugins(ctx context.Context, scopeIds []string, opt ... } return plugins, nil } + +// AddSupportFlag adds a flag in the database for the current plugin to specify that it is capable +// of that type's functions +func (r *Repository) AddSupportFlag(ctx context.Context, plugin *Plugin, flag PluginType) error { + const op = "plugin.(Repository).AddSupportFlag" + + tableName, ok := pluginTypeDbMap[flag] + if !ok { + return errors.New(ctx, errors.InvalidParameter, op, "plugin type does not exist") + } + + sql := fmt.Sprintf(addSupportFlagQuery, tableName) + if _, err := r.writer.Exec(ctx, sql, []any{plugin.PublicId}); err != nil { + return errors.Wrap(ctx, err, op) + } + return nil +} diff --git a/internal/plugin/host/repository_plugin_test.go b/internal/plugin/repository_plugin_test.go similarity index 65% rename from internal/plugin/host/repository_plugin_test.go rename to internal/plugin/repository_plugin_test.go index a3ecbb65a3..43a7b1d3c8 100644 --- a/internal/plugin/host/repository_plugin_test.go +++ b/internal/plugin/repository_plugin_test.go @@ -1,10 +1,11 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "context" + "fmt" "strings" "testing" @@ -12,7 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - "github.com/hashicorp/boundary/internal/plugin/host/store" + "github.com/hashicorp/boundary/internal/plugin/store" "github.com/hashicorp/boundary/internal/types/scope" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -259,3 +260,129 @@ func TestRepository_LookupPluginByName(t *testing.T) { }) } } + +func TestRepository_AddSupportFlag(t *testing.T) { + conn, _ := db.TestSetup(t, "postgres") + rw := db.New(conn) + wrapper := db.TestWrapper(t) + + tests := []struct { + name string + pluginName string + flag PluginType + flagExists bool + forceErr bool + err string + }{ + { + name: "flag doesn't exist and is added", + pluginName: "test1", + flag: PluginTypeHost, + flagExists: false, + forceErr: false, + err: "", + }, + { + name: "flag exists and is unchanged", + pluginName: "test2", + flag: PluginTypeHost, + flagExists: true, + forceErr: false, + err: "", + }, + { + name: "err thrown and is handled", + pluginName: "test3", + flag: PluginTypeHost, + flagExists: false, + forceErr: true, + err: "wt_plugin_id_check constraint failed", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + ctx := context.Background() + + require.Contains(pluginTypeDbMap, tt.flag) + plg := TestPlugin(t, conn, tt.pluginName) + + // we want the flag to already be in the db, so add it before hand + if tt.flagExists { + rowCount, err := rw.Exec(ctx, fmt.Sprintf("insert into %s (public_id) values (?);", pluginTypeDbMap[tt.flag]), []any{plg.PublicId}) + assert.Equal(1, rowCount) + require.NoError(err) + } + + // check to make sure the start state is as expected + rows, err := rw.Query(ctx, fmt.Sprintf("select public_id from %s where public_id = ?;", pluginTypeDbMap[tt.flag]), []any{plg.PublicId}) + require.NoError(err) + + rowCount := 0 + var plgid string + + for rows.Next() { + rowCount++ + require.NoError(rows.Scan(&plgid)) + } + + if tt.flagExists { + assert.Equal(1, rowCount) + assert.Equal(plg.PublicId, plgid) + } else { + assert.Equal(0, rowCount) + assert.Equal("", plgid) + } + + // create the plugin repo + kms := kms.TestKms(t, conn, wrapper) + repo, err := NewRepository(rw, rw, kms) + assert.NoError(err) + assert.NotNil(repo) + + if tt.forceErr { + plg.PublicId = "biscuit" + } + + // do the thing + err = repo.AddSupportFlag(ctx, plg, tt.flag) + + if tt.err != "" { + require.ErrorContains(err, tt.err) + return + } + require.NoError(err) + + // check to make sure the end state is as expected + rows, err = rw.Query(ctx, fmt.Sprintf("select public_id from %s where public_id = ?;", pluginTypeDbMap[tt.flag]), []any{plg.PublicId}) + require.NoError(err) + rowCount = 0 + for rows.Next() { + rowCount++ + } + assert.Equal(1, rowCount) + }) + } + + // this needs it's own test becaues of the setup required for above tests + t.Run("plugin type unknown", func(t *testing.T) { + assert := assert.New(t) + require := require.New(t) + ctx := context.Background() + plg := TestPlugin(t, conn, "test12345") + + // create the plugin repo + kms := kms.TestKms(t, conn, wrapper) + repo, err := NewRepository(rw, rw, kms) + assert.NoError(err) + assert.NotNil(repo) + + // do the thing + err = repo.AddSupportFlag(ctx, plg, PluginTypeUnknown) + + require.ErrorContains(err, "plugin type does not exist: parameter violation") + }) +} diff --git a/internal/plugin/host/repository_test.go b/internal/plugin/repository_test.go similarity index 99% rename from internal/plugin/host/repository_test.go rename to internal/plugin/repository_test.go index 6e1ed3117d..eac6bcbb2d 100644 --- a/internal/plugin/host/repository_test.go +++ b/internal/plugin/repository_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package host +package plugin import ( "testing" diff --git a/internal/plugin/store/plugin.pb.go b/internal/plugin/store/plugin.pb.go index 7112aafab2..707815212f 100644 --- a/internal/plugin/store/plugin.pb.go +++ b/internal/plugin/store/plugin.pb.go @@ -12,6 +12,8 @@ package store import ( + timestamp "github.com/hashicorp/boundary/internal/db/timestamp" + _ "github.com/hashicorp/boundary/sdk/pbs/controller/protooptions" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -25,8 +27,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a typeless plugin. In practice this should never be used directly. -// This is included for testing purposes only. type Plugin struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -41,6 +41,17 @@ type Plugin struct { // name is optional. If set, it must be unique within scope_id. // @inject_tag: `gorm:"default:null"` Name string `protobuf:"bytes,30,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"` + // description is optional. + // @inject_tag: `gorm:"default:null"` + Description string `protobuf:"bytes,40,opt,name=description,proto3" json:"description,omitempty" gorm:"default:null"` + // The create_time is set by the database. + // @inject_tag: `gorm:"default:current_timestamp"` + CreateTime *timestamp.Timestamp `protobuf:"bytes,50,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:current_timestamp"` + // The update_time is set by the database. + // @inject_tag: `gorm:"default:current_timestamp"` + UpdateTime *timestamp.Timestamp `protobuf:"bytes,60,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:current_timestamp"` + // @inject_tag: `gorm:"default:null"` + Version uint32 `protobuf:"varint,70,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"` } func (x *Plugin) Reset() { @@ -96,6 +107,34 @@ func (x *Plugin) GetName() string { return "" } +func (x *Plugin) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Plugin) GetCreateTime() *timestamp.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *Plugin) GetUpdateTime() *timestamp.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *Plugin) GetVersion() uint32 { + if x != nil { + return x.Version + } + return 0 +} + var File_controller_storage_plugin_store_v1_plugin_proto protoreflect.FileDescriptor var file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = []byte{ @@ -104,16 +143,39 @@ var file_controller_storage_plugin_store_v1_plugin_proto_rawDesc = []byte{ 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x73, 0x74, 0x6f, - 0x72, 0x65, 0x2e, 0x76, 0x31, 0x22, 0x54, 0x0a, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, - 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, - 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x73, 0x63, 0x6f, 0x70, 0x65, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x3b, 0x5a, 0x39, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, - 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x73, 0x74, 0x6f, - 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x2a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, + 0x72, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x74, + 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2f, + 0x76, 0x31, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0xdc, 0x02, 0x0a, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x1b, 0x0a, + 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x63, + 0x6f, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x63, + 0x6f, 0x70, 0x65, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x1e, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x10, 0xc2, 0xdd, 0x29, 0x0c, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x40, 0x0a, 0x0b, 0x64, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x28, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x1e, 0xc2, 0xdd, 0x29, 0x1a, 0x0a, 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x4b, 0x0a, + 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x32, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, + 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x4b, 0x0a, 0x0b, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x3c, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x2a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, + 0x72, 0x61, 0x67, 0x65, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x76, + 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x18, 0x46, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, + 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, + 0x69, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -130,14 +192,17 @@ func file_controller_storage_plugin_store_v1_plugin_proto_rawDescGZIP() []byte { var file_controller_storage_plugin_store_v1_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_controller_storage_plugin_store_v1_plugin_proto_goTypes = []interface{}{ - (*Plugin)(nil), // 0: controller.storage.plugin.store.v1.Plugin + (*Plugin)(nil), // 0: controller.storage.plugin.store.v1.Plugin + (*timestamp.Timestamp)(nil), // 1: controller.storage.timestamp.v1.Timestamp } var file_controller_storage_plugin_store_v1_plugin_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 1, // 0: controller.storage.plugin.store.v1.Plugin.create_time:type_name -> controller.storage.timestamp.v1.Timestamp + 1, // 1: controller.storage.plugin.store.v1.Plugin.update_time:type_name -> controller.storage.timestamp.v1.Timestamp + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_controller_storage_plugin_store_v1_plugin_proto_init() } diff --git a/internal/plugin/testing.go b/internal/plugin/testing.go index 90802b115b..d3d70dbd48 100644 --- a/internal/plugin/testing.go +++ b/internal/plugin/testing.go @@ -44,10 +44,10 @@ func (c *plugin) SetTableName(n string) { c.tableName = n } -func testPlugin(t testing.TB, conn *db.DB, name string) *plugin { +func TestPlugin(t testing.TB, conn *db.DB, name string) *Plugin { t.Helper() - p := newPlugin(name) - id, err := db.NewPublicId("plg") + p := NewPlugin(WithName(name)) + id, err := newPluginId() require.NoError(t, err) p.PublicId = id diff --git a/internal/plugin/testing_test.go b/internal/plugin/testing_test.go index c069f566a6..85b7e1ff09 100644 --- a/internal/plugin/testing_test.go +++ b/internal/plugin/testing_test.go @@ -11,11 +11,11 @@ import ( "github.com/stretchr/testify/require" ) -func Test_testPlugin(t *testing.T) { +func Test_TestPlugins(t *testing.T) { assert, require := assert.New(t), require.New(t) conn, _ := db.TestSetup(t, "postgres") - plg := testPlugin(t, conn, "test") + plg := TestPlugin(t, conn, "test") require.NotNil(plg) assert.NotEmpty(plg.GetPublicId()) } diff --git a/internal/proto/controller/storage/plugin/host/store/v1/plugin.proto b/internal/proto/controller/storage/plugin/host/store/v1/plugin.proto deleted file mode 100644 index e08c7e808e..0000000000 --- a/internal/proto/controller/storage/plugin/host/store/v1/plugin.proto +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -syntax = "proto3"; - -// Package store provides protobufs for storing types in the host package. -package controller.storage.plugin.host.store.v1; - -import "controller/custom_options/v1/options.proto"; -import "controller/storage/timestamp/v1/timestamp.proto"; - -option go_package = "github.com/hashicorp/boundary/internal/plugin/host/store;store"; - -message Plugin { - // public_id is a surrogate key suitable for use in a public API. - // @inject_tag: `gorm:"primary_key"` - string public_id = 10; - - // The create_time is set by the database. - // @inject_tag: `gorm:"default:current_timestamp"` - timestamp.v1.Timestamp create_time = 20; - - // The update_time is set by the database. - // @inject_tag: `gorm:"default:current_timestamp"` - timestamp.v1.Timestamp update_time = 30; - - // name is optional. If set, it must be unique within scope_id. - // @inject_tag: `gorm:"default:null"` - string name = 4 [(custom_options.v1.mask_mapping) = { - this: "Name" - that: "name" - }]; - - // description is optional. - // @inject_tag: `gorm:"default:null"` - string description = 50 [(custom_options.v1.mask_mapping) = { - this: "Description" - that: "description" - }]; - - // The scope_id of the owning scope and must be set. - // @inject_tag: `gorm:"not_null"` - string scope_id = 60; - - // @inject_tag: `gorm:"default:null"` - uint32 version = 70; -} diff --git a/internal/proto/controller/storage/plugin/store/v1/plugin.proto b/internal/proto/controller/storage/plugin/store/v1/plugin.proto index f80d3c4610..8ed05a6c81 100644 --- a/internal/proto/controller/storage/plugin/store/v1/plugin.proto +++ b/internal/proto/controller/storage/plugin/store/v1/plugin.proto @@ -6,10 +6,11 @@ syntax = "proto3"; // Package store provides protobufs for storing types in the host package. package controller.storage.plugin.store.v1; +import "controller/custom_options/v1/options.proto"; +import "controller/storage/timestamp/v1/timestamp.proto"; + option go_package = "github.com/hashicorp/boundary/internal/plugin/store;store"; -// This is a typeless plugin. In practice this should never be used directly. -// This is included for testing purposes only. message Plugin { // public_id is a surrogate key suitable for use in a public API. // @inject_tag: `gorm:"primary_key"` @@ -21,5 +22,26 @@ message Plugin { // name is optional. If set, it must be unique within scope_id. // @inject_tag: `gorm:"default:null"` - string name = 30; + string name = 30 [(custom_options.v1.mask_mapping) = { + this: "Name" + that: "name" + }]; + + // description is optional. + // @inject_tag: `gorm:"default:null"` + string description = 40 [(custom_options.v1.mask_mapping) = { + this: "Description" + that: "description" + }]; + + // The create_time is set by the database. + // @inject_tag: `gorm:"default:current_timestamp"` + timestamp.v1.Timestamp create_time = 50; + + // The update_time is set by the database. + // @inject_tag: `gorm:"default:current_timestamp"` + timestamp.v1.Timestamp update_time = 60; + + // @inject_tag: `gorm:"default:null"` + uint32 version = 70; } From 85360ebb3b8c7a19e95e50045a0fc11c43a76825 Mon Sep 17 00:00:00 2001 From: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:34:28 -0400 Subject: [PATCH 2/4] move migration, fix one more file --- .../handlers/targets/tcp/target_service_test.go | 10 +++++----- .../postgres/{64 => 67}/01_plugins_restructure.up.sql | 4 +--- internal/host/preferred_endpoint_test.go | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) rename internal/db/schema/migrations/oss/postgres/{64 => 67}/01_plugins_restructure.up.sql (91%) diff --git a/internal/daemon/controller/handlers/targets/tcp/target_service_test.go b/internal/daemon/controller/handlers/targets/tcp/target_service_test.go index c4664cecf8..62f10e1bf1 100644 --- a/internal/daemon/controller/handlers/targets/tcp/target_service_test.go +++ b/internal/daemon/controller/handlers/targets/tcp/target_service_test.go @@ -37,7 +37,7 @@ import ( "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/requests" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/server" @@ -1354,7 +1354,7 @@ func TestAddTargetHostSources(t *testing.T) { hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] hs := static.TestSets(t, conn, hc.GetPublicId(), 2) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.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{}), @@ -1516,7 +1516,7 @@ func TestSetTargetHostSources(t *testing.T) { hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] hs := static.TestSets(t, conn, hc.GetPublicId(), 2) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.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{}), @@ -1666,7 +1666,7 @@ func TestRemoveTargetHostSources(t *testing.T) { hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0] hs := static.TestSets(t, conn, hc.GetPublicId(), 2) - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.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{}), @@ -2443,7 +2443,7 @@ func TestAuthorizeSession(t *testing.T) { return ldap.NewRepository(ctx, rw, rw, kms) } - plg := host.TestPlugin(t, conn, "test") + plg := iplugin.TestPlugin(t, conn, "test") plgm := map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): plugin.NewWrappingPluginClient(plugin.TestPluginServer{ ListHostsFn: func(_ context.Context, req *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error) { diff --git a/internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql b/internal/db/schema/migrations/oss/postgres/67/01_plugins_restructure.up.sql similarity index 91% rename from internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql rename to internal/db/schema/migrations/oss/postgres/67/01_plugins_restructure.up.sql index f284f01feb..3c237f0b0a 100644 --- a/internal/db/schema/migrations/oss/postgres/64/01_plugins_restructure.up.sql +++ b/internal/db/schema/migrations/oss/postgres/67/01_plugins_restructure.up.sql @@ -8,7 +8,6 @@ alter table plugin add column create_time wt_timestamp; alter table plugin add column update_time wt_timestamp; alter table plugin add column version wt_version; --- TODO: check if this needs to be an update or an insert update plugin as p set description = ph.description, create_time = ph.create_time, @@ -31,7 +30,6 @@ drop trigger immutable_columns on plugin; create trigger immutable_columns before update on plugin for each row execute procedure immutable_columns('public_id', 'create_time'); --- TODO: should these functions be deleted entirely (not dropped as functions)? drop trigger insert_plugin_subtype on plugin_host; drop trigger update_plugin_subtype on plugin_host; drop trigger delete_plugin_subtype on plugin_host; @@ -60,6 +58,6 @@ alter table host_plugin_catalog on delete cascade on update cascade; -drop table plugin_host; -- TODO: cascade? +drop table plugin_host; commit; diff --git a/internal/host/preferred_endpoint_test.go b/internal/host/preferred_endpoint_test.go index cb499d6083..c705edc0cb 100644 --- a/internal/host/preferred_endpoint_test.go +++ b/internal/host/preferred_endpoint_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" - hostplg "github.com/hashicorp/boundary/internal/plugin/host" + iplugin "github.com/hashicorp/boundary/internal/plugin" "github.com/hashicorp/boundary/internal/scheduler" plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" "github.com/stretchr/testify/assert" @@ -30,7 +30,7 @@ func TestPreferredEndpoint_Create(t *testing.T) { kmsCache := kms.TestKms(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "create") + plg := iplugin.TestPlugin(t, conn, "create") catalog := plugin.TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) set := plugin.TestSet(t, conn, kmsCache, sched, catalog, map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}), @@ -161,7 +161,7 @@ func TestPreferredEndpoint_Delete(t *testing.T) { kmsCache := kms.TestKms(t, conn, wrapper) _, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper)) - plg := hostplg.TestPlugin(t, conn, "create") + plg := iplugin.TestPlugin(t, conn, "create") catalog := plugin.TestCatalog(t, conn, prj.PublicId, plg.GetPublicId()) set := plugin.TestSet(t, conn, kmsCache, sched, catalog, map[string]plgpb.HostPluginServiceClient{ plg.GetPublicId(): plugin.NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}), From f4d19404e9348ef470cfa173a5d4cad1e6073709 Mon Sep 17 00:00:00 2001 From: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com> Date: Thu, 30 Mar 2023 13:52:38 -0400 Subject: [PATCH 3/4] fixes for main --- internal/daemon/controller/controller.go | 2 +- .../host_catalog_service_test.go | 4 +- .../handlers/hosts/host_service_test.go | 6 +-- internal/plugin/repository_plugin_test.go | 9 +--- internal/plugin/testing.go | 45 ++++++++++++++++++- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/internal/daemon/controller/controller.go b/internal/daemon/controller/controller.go index 8c9d153385..47bd522747 100644 --- a/internal/daemon/controller/controller.go +++ b/internal/daemon/controller/controller.go @@ -251,7 +251,7 @@ func New(ctx context.Context, conf *Config) (*Controller, error) { if _, err = conf.RegisterHostPlugin(ctx, "loopback", plg, opts...); err != nil { return nil, err } - case base.EnabledPluginHostAzure, base.EnabledPluginHostAws: // TODO: add + case base.EnabledPluginHostAzure, base.EnabledPluginHostAws: // TODO: add storage plugin flag here pluginType := strings.ToLower(enabledPlugin.String()) client, cleanup, err := external_host_plugins.CreateHostPlugin( ctx, diff --git a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go index b121c2a169..c7bc9228e2 100644 --- a/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go +++ b/internal/daemon/controller/handlers/host_catalogs/host_catalog_service_test.go @@ -435,7 +435,7 @@ func TestList(t *testing.T) { name: "Filter To Catalog Using Test Plugin", req: &pbs.ListHostCatalogsRequest{ ScopeId: scope.Global.String(), Recursive: true, - Filter: `"/item/hostplugin/name"=="test"`, + Filter: `"/item/plugin/name"=="test"`, }, res: &pbs.ListHostCatalogsResponse{Items: testPluginCatalogs}, }, @@ -1403,7 +1403,7 @@ func TestUpdate_Plugin(t *testing.T) { PluginId: plg.GetPublicId(), Name: wrapperspb.String("default"), Description: wrapperspb.String("default"), - Type: "hostplugin", + Type: "plugin", Attrs: &pb.HostCatalog_Attributes{ Attributes: attr, }, diff --git a/internal/daemon/controller/handlers/hosts/host_service_test.go b/internal/daemon/controller/handlers/hosts/host_service_test.go index f8e6110c96..f93d61f673 100644 --- a/internal/daemon/controller/handlers/hosts/host_service_test.go +++ b/internal/daemon/controller/handlers/hosts/host_service_test.go @@ -537,7 +537,7 @@ func TestDelete(t *testing.T) { }, }, { - name: "Delete a hostplugin Host", + name: "Delete a plugin Host", projectId: proj.GetPublicId(), req: &pbs.DeleteHostRequest{ Id: pluginH.GetPublicId(), @@ -689,10 +689,10 @@ func TestCreate(t *testing.T) { wantErrContains: `Details: {{name: "attributes", desc: "This is a required field."}}`, }, { - name: "Create a hostplugin Host", + name: "Create a plugin Host", req: &pbs.CreateHostRequest{Item: &pb.Host{ HostCatalogId: pluginHc.GetPublicId(), - Type: "hostplugin", + Type: "plugin", }}, err: handlers.ApiErrorWithCode(codes.InvalidArgument), }, diff --git a/internal/plugin/repository_plugin_test.go b/internal/plugin/repository_plugin_test.go index 43a7b1d3c8..dcd47c750c 100644 --- a/internal/plugin/repository_plugin_test.go +++ b/internal/plugin/repository_plugin_test.go @@ -308,14 +308,7 @@ func TestRepository_AddSupportFlag(t *testing.T) { ctx := context.Background() require.Contains(pluginTypeDbMap, tt.flag) - plg := TestPlugin(t, conn, tt.pluginName) - - // we want the flag to already be in the db, so add it before hand - if tt.flagExists { - rowCount, err := rw.Exec(ctx, fmt.Sprintf("insert into %s (public_id) values (?);", pluginTypeDbMap[tt.flag]), []any{plg.PublicId}) - assert.Equal(1, rowCount) - require.NoError(err) - } + plg := TestPlugin(t, conn, tt.pluginName, WithHostFlag(tt.flagExists)) // check to make sure the start state is as expected rows, err := rw.Query(ctx, fmt.Sprintf("select public_id from %s where public_id = ?;", pluginTypeDbMap[tt.flag]), []any{plg.PublicId}) diff --git a/internal/plugin/testing.go b/internal/plugin/testing.go index d3d70dbd48..42ee438a5b 100644 --- a/internal/plugin/testing.go +++ b/internal/plugin/testing.go @@ -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,7 +45,39 @@ 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 +} + +func getDefaultTestOptions() testOptions { + return testOptions{ + withHostFlag: true, + } +} + +// 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 + } +} + +// TestPlugin creates a plugin and inserts it into the database. enables the "host" flag by default +func TestPlugin(t testing.TB, conn *db.DB, name string, opt ...TestOption) *Plugin { + opts := getTestOpts(opt...) t.Helper() p := NewPlugin(WithName(name)) id, err := newPluginId() @@ -53,5 +86,15 @@ func TestPlugin(t testing.TB, conn *db.DB, name string) *Plugin { w := db.New(conn) require.NoError(t, w.Create(context.Background(), p)) + + if opts.withHostFlag { + // add the host supported flag + wrapper := db.TestWrapper(t) + kmsCache := kms.TestKms(t, conn, wrapper) + repo, err := NewRepository(w, w, kmsCache) + require.NoError(t, err) + repo.AddSupportFlag(context.Background(), p, PluginTypeHost) + } + return p } From 15922d71f47700e06e42fd36ec7a59cb359bce3c Mon Sep 17 00:00:00 2001 From: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com> Date: Thu, 30 Mar 2023 15:26:46 -0400 Subject: [PATCH 4/4] fix sql --- internal/db/sqltest/initdb.d/03_widgets_persona.sql | 7 ++++++- internal/plugin/query.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/db/sqltest/initdb.d/03_widgets_persona.sql b/internal/db/sqltest/initdb.d/03_widgets_persona.sql index e7fa270b9a..91e10ba445 100644 --- a/internal/db/sqltest/initdb.d/03_widgets_persona.sql +++ b/internal/db/sqltest/initdb.d/03_widgets_persona.sql @@ -270,11 +270,16 @@ begin; where h.catalog_id = s.catalog_id and h.address like '%.widget'; - insert into plugin_host + insert into plugin (scope_id, public_id, name) values ('global', 'plg___wb-hplg', 'Short Host Plugin'); + insert into plugin_host_supported + (public_id) + values + ('plg___wb-hplg'); + insert into host_plugin_catalog (project_id, public_id, plugin_id, name, attributes) values diff --git a/internal/plugin/query.go b/internal/plugin/query.go index b18056b52b..52c35db3bb 100644 --- a/internal/plugin/query.go +++ b/internal/plugin/query.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package plugin const (