Fix canonical tags not getting assigned in the api resource. (#2144)
This commit is contained in:
4 files changed
+78
-15
No files matched your search
@@ -395,7 +395,7 @@ func toProto(ctx context.Context, in *servers.Worker, opt ...handlers.Option) (*
|
|||||||
}
|
}
|
||||||
if outputFields.Has(globals.CanonicalTagsField) && len(in.CanonicalTags()) > 0 {
|
if outputFields.Has(globals.CanonicalTagsField) && len(in.CanonicalTags()) > 0 {
|
||||||
var err error
|
var err error
|
||||||
out.Tags, err = tagsToMapProto(in.CanonicalTags())
|
out.CanonicalTags, err = tagsToMapProto(in.CanonicalTags())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error preparing canonical tags proto"))
|
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error preparing canonical tags proto"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ import (
|
|||||||
|
|
||||||
var testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
|
var testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
|
||||||
|
|
||||||
|
func structListValue(t *testing.T, ss ...string) *structpb.ListValue {
|
||||||
|
t.Helper()
|
||||||
|
var val []interface{}
|
||||||
|
for _, s := range ss {
|
||||||
|
val = append(val, s)
|
||||||
|
}
|
||||||
|
lv, err := structpb.NewList(val)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return lv
|
||||||
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
conn, _ := db.TestSetup(t, "postgres")
|
conn, _ := db.TestSetup(t, "postgres")
|
||||||
wrap := db.TestWrapper(t)
|
wrap := db.TestWrapper(t)
|
||||||
@@ -40,14 +51,29 @@ func TestGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
rw := db.New(conn)
|
rw := db.New(conn)
|
||||||
kms := kms.TestKms(t, conn, wrap)
|
kms := kms.TestKms(t, conn, wrap)
|
||||||
|
repo, err := servers.NewRepository(rw, rw, kms)
|
||||||
|
require.NoError(t, err)
|
||||||
repoFn := func() (*servers.Repository, error) {
|
repoFn := func() (*servers.Repository, error) {
|
||||||
return servers.NewRepository(rw, rw, kms)
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
worker := servers.TestWorker(t, conn, wrap,
|
worker := servers.TestWorker(t, conn, wrap,
|
||||||
servers.WithName("test worker names"),
|
servers.WithName("test worker names"),
|
||||||
servers.WithDescription("test worker description"),
|
servers.WithDescription("test worker description"),
|
||||||
servers.WithAddress("test worker address"))
|
servers.WithAddress("test worker address"),
|
||||||
|
servers.WithWorkerTags(&servers.Tag{"key", "val"}))
|
||||||
|
// Add config tags to the created worker
|
||||||
|
worker, err = repo.UpsertWorkerStatus(context.Background(),
|
||||||
|
servers.NewWorkerForStatus(worker.GetScopeId(),
|
||||||
|
servers.WithName(worker.GetWorkerReportedName()),
|
||||||
|
servers.WithAddress(worker.GetWorkerReportedAddress()),
|
||||||
|
servers.WithWorkerTags(&servers.Tag{
|
||||||
|
Key: "config",
|
||||||
|
Value: "test",
|
||||||
|
})),
|
||||||
|
servers.WithUpdateTags(true),
|
||||||
|
servers.WithPublicId(worker.GetPublicId()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
wantWorker := &pb.Worker{
|
wantWorker := &pb.Worker{
|
||||||
Id: worker.GetPublicId(),
|
Id: worker.GetPublicId(),
|
||||||
@@ -62,9 +88,19 @@ func TestGet(t *testing.T) {
|
|||||||
AuthorizedActions: testAuthorizedActions,
|
AuthorizedActions: testAuthorizedActions,
|
||||||
CanonicalAddress: worker.CanonicalAddress(),
|
CanonicalAddress: worker.CanonicalAddress(),
|
||||||
LastStatusTime: worker.GetLastStatusTime().GetTimestamp(),
|
LastStatusTime: worker.GetLastStatusTime().GetTimestamp(),
|
||||||
|
CanonicalTags: map[string]*structpb.ListValue{
|
||||||
|
"key": structListValue(t, "val"),
|
||||||
|
"config": structListValue(t, "test"),
|
||||||
|
},
|
||||||
|
Tags: map[string]*structpb.ListValue{
|
||||||
|
"key": structListValue(t, "val"),
|
||||||
|
},
|
||||||
WorkerConfig: &pb.WorkerConfig{
|
WorkerConfig: &pb.WorkerConfig{
|
||||||
Address: worker.GetWorkerReportedAddress(),
|
Address: worker.GetWorkerReportedAddress(),
|
||||||
Name: worker.GetWorkerReportedName(),
|
Name: worker.GetWorkerReportedName(),
|
||||||
|
Tags: map[string]*structpb.ListValue{
|
||||||
|
"config": structListValue(t, "test"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,11 +667,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Item: &pb.Worker{
|
Item: &pb.Worker{
|
||||||
Tags: map[string]*structpb.ListValue{
|
Tags: map[string]*structpb.ListValue{
|
||||||
"foo": func() *structpb.ListValue {
|
"foo": structListValue(t, "bar"),
|
||||||
l, err := structpb.NewList([]interface{}{"bar"})
|
|
||||||
require.NoError(t, err)
|
|
||||||
return l
|
|
||||||
}(),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -650,11 +682,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Item: &pb.Worker{
|
Item: &pb.Worker{
|
||||||
CanonicalTags: map[string]*structpb.ListValue{
|
CanonicalTags: map[string]*structpb.ListValue{
|
||||||
"foo": func() *structpb.ListValue {
|
"foo": structListValue(t, "bar"),
|
||||||
l, err := structpb.NewList([]interface{}{"bar"})
|
|
||||||
require.NoError(t, err)
|
|
||||||
return l
|
|
||||||
}(),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -145,11 +145,33 @@ func TestLookupWorker(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
w := servers.TestWorker(t, conn, wrapper)
|
w := servers.TestWorker(t, conn, wrapper,
|
||||||
|
servers.WithName("name"),
|
||||||
|
servers.WithDescription("description"),
|
||||||
|
servers.WithAddress("address"),
|
||||||
|
servers.WithWorkerTags(&servers.Tag{"key", "val"}))
|
||||||
|
w, err = repo.UpsertWorkerStatus(context.Background(),
|
||||||
|
servers.NewWorkerForStatus(w.GetScopeId(),
|
||||||
|
servers.WithName(w.GetWorkerReportedName()),
|
||||||
|
servers.WithAddress(w.GetWorkerReportedAddress()),
|
||||||
|
servers.WithWorkerTags(&servers.Tag{
|
||||||
|
Key: "config",
|
||||||
|
Value: "test",
|
||||||
|
})),
|
||||||
|
servers.WithUpdateTags(true),
|
||||||
|
servers.WithPublicId(w.GetPublicId()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("success", func(t *testing.T) {
|
t.Run("success", func(t *testing.T) {
|
||||||
got, err := repo.LookupWorker(ctx, w.GetPublicId())
|
got, err := repo.LookupWorker(ctx, w.GetPublicId())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Empty(t, cmp.Diff(w.Worker, got.Worker, protocmp.Transform()))
|
assert.Empty(t, cmp.Diff(w, got, protocmp.Transform()))
|
||||||
|
assert.Equal(t, map[string][]string{"key": {"val"}}, got.GetApiTags())
|
||||||
|
assert.Equal(t, map[string][]string{"config": {"test"}}, got.GetConfigTags())
|
||||||
|
assert.Equal(t, map[string][]string{
|
||||||
|
"key": {"val"},
|
||||||
|
"config": {"test"},
|
||||||
|
}, got.CanonicalTags())
|
||||||
})
|
})
|
||||||
t.Run("not found", func(t *testing.T) {
|
t.Run("not found", func(t *testing.T) {
|
||||||
got, err := repo.LookupWorker(ctx, "w_unknownid")
|
got, err := repo.LookupWorker(ctx, "w_unknownid")
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||||
"github.com/hashicorp/boundary/internal/iam"
|
"github.com/hashicorp/boundary/internal/iam"
|
||||||
"github.com/hashicorp/boundary/internal/kms"
|
"github.com/hashicorp/boundary/internal/kms"
|
||||||
|
"github.com/hashicorp/boundary/internal/servers/store"
|
||||||
"github.com/hashicorp/boundary/internal/types/scope"
|
"github.com/hashicorp/boundary/internal/types/scope"
|
||||||
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -103,6 +104,18 @@ func TestWorker(t *testing.T, conn *db.DB, wrapper wrapping.Wrapper, opt ...Opti
|
|||||||
require.NotNil(t, wrk)
|
require.NotNil(t, wrk)
|
||||||
opts := getOpts(opt...)
|
opts := getOpts(opt...)
|
||||||
|
|
||||||
|
if len(opts.withWorkerTags) > 0 {
|
||||||
|
var tags []interface{}
|
||||||
|
for _, t := range opts.withWorkerTags {
|
||||||
|
tags = append(tags, &store.WorkerTag{
|
||||||
|
WorkerId: wrk.GetPublicId(),
|
||||||
|
Key: t.Key,
|
||||||
|
Value: t.Value,
|
||||||
|
Source: "api",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
require.NoError(t, rw.CreateItems(ctx, tags))
|
||||||
|
}
|
||||||
var mask []string
|
var mask []string
|
||||||
if opts.withName != "" {
|
if opts.withName != "" {
|
||||||
wrk.Name = opts.withName
|
wrk.Name = opts.withName
|
||||||
|
|||||||
Reference in new issue
Block a user