Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework plugin/host_plugin sql and accompanying domain #3136

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions internal/cmd/base/initial_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/daemon/controller/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
)
Expand Down
16 changes: 8 additions & 8 deletions internal/daemon/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 storage plugin flag here
pluginType := strings.ToLower(enabledPlugin.String())
client, cleanup, err := external_host_plugins.CreateHostPlugin(
ctx,
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand All @@ -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))
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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() != "" {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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."
}
Expand All @@ -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
})
Expand All @@ -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 {
Expand Down
Loading