feat(host): Add host set information to static host (#1828)
* feat(host): Add host set information to static host Updates LookupHost and ListHost API to include sets a static host is part of, as like with plugin hosts. * test: updated TestList_Plugin and TestCrud to be more consistent under race conditions
This commit is contained in:
1 parent
84f6cc698c
commit
fa00a06bef
9 files changed
+305
-35
No files matched your search
@@ -130,11 +130,7 @@ func (s Service) ListHosts(ctx context.Context, req *pbs.ListHostsRequest) (*pbs
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
|
||||
}
|
||||
|
||||
switch h := item.(type) {
|
||||
case *plugin.Host:
|
||||
outputOpts = append(outputOpts, handlers.WithHostSetIds(h.SetIds))
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithHostSetIds(item.GetSetIds()))
|
||||
item, err := toProto(ctx, item, outputOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -180,11 +176,7 @@ func (s Service) GetHost(ctx context.Context, req *pbs.GetHostRequest) (*pbs.Get
|
||||
idActions := idActionsTypeMap[host.SubtypeFromId(req.GetId())]
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, h.GetPublicId(), idActions).Strings()))
|
||||
}
|
||||
|
||||
switch h := h.(type) {
|
||||
case *plugin.Host:
|
||||
outputOpts = append(outputOpts, handlers.WithHostSetIds(h.SetIds))
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithHostSetIds(h.GetSetIds()))
|
||||
item, err := toProto(ctx, h, outputOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -265,6 +257,7 @@ func (s Service) UpdateHost(ctx context.Context, req *pbs.UpdateHostRequest) (*p
|
||||
idActions := idActionsTypeMap[host.SubtypeFromId(req.GetId())]
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, h.GetPublicId(), idActions).Strings()))
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithHostSetIds(h.GetSetIds()))
|
||||
|
||||
item, err := toProto(ctx, h, outputOpts...)
|
||||
if err != nil {
|
||||
|
||||
@@ -66,6 +66,8 @@ func TestGet_Static(t *testing.T) {
|
||||
}
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
h := static.TestHosts(t, conn, hc.GetPublicId(), 1)[0]
|
||||
s := static.TestSets(t, conn, hc.GetPublicId(), 1)[0]
|
||||
static.TestSetMembers(t, conn, s.GetPublicId(), []*static.Host{h})
|
||||
|
||||
pHost := &pb.Host{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
@@ -78,6 +80,7 @@ func TestGet_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue(h.GetAddress()),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
@@ -253,8 +256,11 @@ func TestList_Static(t *testing.T) {
|
||||
hcs := static.TestCatalogs(t, conn, proj.GetPublicId(), 2)
|
||||
hc, hcNoHosts := hcs[0], hcs[1]
|
||||
|
||||
hset := static.TestSets(t, conn, hc.GetPublicId(), 1)[0]
|
||||
var wantHs []*pb.Host
|
||||
for _, h := range static.TestHosts(t, conn, hc.GetPublicId(), 10) {
|
||||
testHosts := static.TestHosts(t, conn, hc.GetPublicId(), 10)
|
||||
static.TestSetMembers(t, conn, hset.GetPublicId(), testHosts)
|
||||
for _, h := range testHosts {
|
||||
wantHs = append(wantHs, &pb.Host{
|
||||
Id: h.GetPublicId(),
|
||||
HostCatalogId: h.GetCatalogId(),
|
||||
@@ -266,8 +272,12 @@ func TestList_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue(h.GetAddress()),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{hset.GetPublicId()},
|
||||
})
|
||||
}
|
||||
sort.Slice(wantHs, func(i int, j int) bool {
|
||||
return wantHs[i].GetId() < wantHs[j].GetId()
|
||||
})
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -793,11 +803,13 @@ func TestUpdate_Static(t *testing.T) {
|
||||
require.NoError(t, err, "Couldn't create new static repo.")
|
||||
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
s := static.TestSets(t, conn, hc.GetPublicId(), 1)[0]
|
||||
|
||||
h, err := static.NewHost(hc.GetPublicId(), static.WithName("default"), static.WithDescription("default"), static.WithAddress("defaultaddress"))
|
||||
require.NoError(t, err)
|
||||
h, err = repo.CreateHost(context.Background(), proj.GetPublicId(), h)
|
||||
require.NoError(t, err)
|
||||
static.TestSetMembers(t, conn, s.GetPublicId(), []*static.Host{h})
|
||||
|
||||
var version uint32 = 1
|
||||
|
||||
@@ -847,6 +859,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -875,6 +888,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -945,6 +959,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -970,6 +985,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -997,6 +1013,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1024,6 +1041,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
"address": structpb.NewStringValue("defaultaddress"),
|
||||
}},
|
||||
AuthorizedActions: testAuthorizedActions[static.Subtype],
|
||||
HostSetIds: []string{s.GetPublicId()},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user