Add host IDs to plugin host sets read response (#1568)

This also includes tweaks here and there within the service and repos.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-09-28 16:19:32 -04:00
1 parent 7d71618df0
commit 8b1ca4b0b8
7 files changed
+269 -43

No files matched your search

@@ -9,6 +9,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/host"
"github.com/hashicorp/boundary/internal/host/plugin"
plugstore "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/libs/endpoint"
@@ -422,7 +423,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
if err != nil {
return nil, nil, nil, err
}
hset, hsplg, err := repo.LookupSet(ctx, id)
hset, hostIds, hsplg, err := repo.LookupSet(ctx, id, host.WithSetMembers(true))
if err != nil {
return nil, nil, nil, err
}
@@ -431,6 +432,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
}
hs = hset
plg = toPluginInfo(hsplg)
for _, h := range hostIds {
hl = append(hl, &plugin.Host{
Host: &plugstore.Host{
PublicId: h,
CatalogId: hset.CatalogId,
},
})
}
}
return hs, hl, plg, nil
}
@@ -668,7 +677,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
}
set = ss
case plugin.Subtype:
ps, _, err := pluginRepo.LookupSet(ctx, id)
ps, _, _, err := pluginRepo.LookupSet(ctx, id)
if err != nil {
res.Error = err
return nil, res
@@ -148,17 +148,19 @@ func TestGet_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, map[string]plgpb.HostPluginServiceServer{})
}
name := "test"
prefEndpoints := []string{"cidr:1.2.3.4", "cidr:2.3.4.5/24"}
plg := hostplugin.TestPlugin(t, conn, name)
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
hs := plugin.TestSet(t, conn, kms, hc, map[string]plgpb.HostPluginServiceServer{
plgm := map[string]plgpb.HostPluginServiceServer{
plg.GetPublicId(): &plugin.TestPluginServer{},
}, plugin.WithPreferredEndpoints(prefEndpoints))
}
pluginRepoFn := func() (*plugin.Repository, error) {
return plugin.NewRepository(rw, rw, kms, plgm)
}
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
hs := plugin.TestSet(t, conn, kms, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints))
toMerge := &pbs.GetHostSetRequest{}