From 9af6c09c364f4a8aa2fc2553bdb5dc1d98eda82e Mon Sep 17 00:00:00 2001 From: Todd Date: Thu, 23 Jun 2022 12:16:16 -0700 Subject: [PATCH] Move generated pb.go file in to the internal/gen directory (#2225) --- Makefile | 2 +- .../handlers/worker_service_status_test.go | 33 +++++++++--------- .../targets/tcp/target_service_test.go | 17 +--------- internal/daemon/worker/status.go | 8 ++--- internal/daemon/worker/worker.go | 9 ++--- .../controller/servers}/servers.pb.go | 11 +++--- .../server_coordination_service.pb.go | 34 +++++++++---------- .../proto/controller/servers/v1/servers.proto | 2 +- 8 files changed, 52 insertions(+), 64 deletions(-) rename internal/{server => gen/controller/servers}/servers.pb.go (96%) diff --git a/Makefile b/Makefile index c0120969b3..d15484bcc6 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,6 @@ protobuild: @protoc-go-inject-tag -input=./internal/credential/store/credential.pb.go @protoc-go-inject-tag -input=./internal/credential/vault/store/vault.pb.go @protoc-go-inject-tag -input=./internal/credential/static/store/static.pb.go - @protoc-go-inject-tag -input=./internal/server/servers.pb.go @protoc-go-inject-tag -input=./internal/kms/store/audit_key.pb.go # inject classification tags (see: https://github.com/hashicorp/go-eventlogger/tree/main/filters/encrypt) @@ -200,6 +199,7 @@ protobuild: @protoc-go-inject-tag -input=./sdk/pbs/controller/api/resources/workers/worker.pb.go @protoc-go-inject-tag -input=./internal/gen/controller/api/services/worker_service.pb.go @protoc-go-inject-tag -input=./internal/gen/controller/servers/services/server_coordination_service.pb.go + @protoc-go-inject-tag -input=./internal/gen/controller/servers/servers.pb.go # these protos, services and openapi artifacts are purely for testing purposes diff --git a/internal/daemon/cluster/handlers/worker_service_status_test.go b/internal/daemon/cluster/handlers/worker_service_status_test.go index d32ff28c7f..2633d02fbd 100644 --- a/internal/daemon/cluster/handlers/worker_service_status_test.go +++ b/internal/daemon/cluster/handlers/worker_service_status_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/authtoken" "github.com/hashicorp/boundary/internal/daemon/cluster/handlers" "github.com/hashicorp/boundary/internal/db" + pb "github.com/hashicorp/boundary/internal/gen/controller/servers" pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" @@ -105,7 +106,7 @@ func TestStatus(t *testing.T) { name: "No Sessions", wantErr: false, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Name: worker1.GetName(), Address: worker1.GetAddress(), @@ -125,7 +126,7 @@ func TestStatus(t *testing.T) { name: "Still Active", wantErr: false, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Name: worker1.GetName(), Address: worker1.GetAddress(), @@ -164,7 +165,7 @@ func TestStatus(t *testing.T) { name: "No Name or keyId", wantErr: true, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Address: worker1.GetAddress(), }, @@ -175,7 +176,7 @@ func TestStatus(t *testing.T) { name: "No Address", wantErr: true, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Name: worker1.GetName(), }, @@ -201,7 +202,7 @@ func TestStatus(t *testing.T) { got, cmpopts.IgnoreUnexported( pbs.StatusResponse{}, - server.ServerWorkerStatus{}, + pb.ServerWorkerStatus{}, pbs.UpstreamServer{}, pbs.JobChangeRequest{}, pbs.Job{}, @@ -209,7 +210,7 @@ func TestStatus(t *testing.T) { pbs.SessionJobInfo{}, pbs.Connection{}, ), - cmpopts.IgnoreFields(server.ServerWorkerStatus{}, "Tags"), + cmpopts.IgnoreFields(pb.ServerWorkerStatus{}, "Tags"), ), ) }) @@ -308,7 +309,7 @@ func TestStatusSessionClosed(t *testing.T) { require.NoError(t, err) }, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Name: worker1.GetName(), Address: worker1.GetAddress(), @@ -379,7 +380,7 @@ func TestStatusSessionClosed(t *testing.T) { got, cmpopts.IgnoreUnexported( pbs.StatusResponse{}, - server.ServerWorkerStatus{}, + pb.ServerWorkerStatus{}, pbs.UpstreamServer{}, pbs.JobChangeRequest{}, pbs.Job{}, @@ -387,7 +388,7 @@ func TestStatusSessionClosed(t *testing.T) { pbs.SessionJobInfo{}, pbs.Connection{}, ), - cmpopts.IgnoreFields(server.ServerWorkerStatus{}, "Tags"), + cmpopts.IgnoreFields(pb.ServerWorkerStatus{}, "Tags"), ), ) }) @@ -475,7 +476,7 @@ func TestStatusDeadConnection(t *testing.T) { require.NotEqual(t, deadConn.PublicId, connection.PublicId) req := &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ PublicId: worker1.GetPublicId(), Name: worker1.GetName(), Address: worker1.GetAddress(), @@ -517,7 +518,7 @@ func TestStatusDeadConnection(t *testing.T) { got, cmpopts.IgnoreUnexported( pbs.StatusResponse{}, - server.ServerWorkerStatus{}, + pb.ServerWorkerStatus{}, pbs.UpstreamServer{}, pbs.JobChangeRequest{}, pbs.Job{}, @@ -525,7 +526,7 @@ func TestStatusDeadConnection(t *testing.T) { pbs.SessionJobInfo{}, pbs.Connection{}, ), - cmpopts.IgnoreFields(server.ServerWorkerStatus{}, "Tags"), + cmpopts.IgnoreFields(pb.ServerWorkerStatus{}, "Tags"), ), ) @@ -635,7 +636,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) { name: "Identify workerID based on keyId in status", wantErr: false, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ Address: "someaddress", KeyId: nodeInfo.Id, }, @@ -654,7 +655,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) { name: "Active keyId Worker", wantErr: false, req: &pbs.StatusRequest{ - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ KeyId: nodeInfo.Id, Address: "someaddress", }, @@ -708,7 +709,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) { got, cmpopts.IgnoreUnexported( pbs.StatusResponse{}, - server.ServerWorkerStatus{}, + pb.ServerWorkerStatus{}, pbs.UpstreamServer{}, pbs.JobChangeRequest{}, pbs.Job{}, @@ -716,7 +717,7 @@ func TestStatusWorkerWithKeyId(t *testing.T) { pbs.SessionJobInfo{}, pbs.Connection{}, ), - cmpopts.IgnoreFields(server.ServerWorkerStatus{}, "Tags"), + cmpopts.IgnoreFields(pb.ServerWorkerStatus{}, "Tags"), ), ) }) 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 14b6607b82..c9b7121e87 100644 --- a/internal/daemon/controller/handlers/targets/tcp/target_service_test.go +++ b/internal/daemon/controller/handlers/targets/tcp/target_service_test.go @@ -8,7 +8,6 @@ import ( "fmt" "path" "strings" - "sync" "testing" "github.com/google/go-cmp/cmp" @@ -16,7 +15,6 @@ import ( "github.com/hashicorp/boundary/internal/credential" credstatic "github.com/hashicorp/boundary/internal/credential/static" "github.com/hashicorp/boundary/internal/credential/vault" - cluster "github.com/hashicorp/boundary/internal/daemon/cluster/handlers" "github.com/hashicorp/boundary/internal/daemon/controller/auth" "github.com/hashicorp/boundary/internal/daemon/controller/handlers" "github.com/hashicorp/boundary/internal/daemon/controller/handlers/credentiallibraries" @@ -25,7 +23,6 @@ import ( "github.com/hashicorp/boundary/internal/db" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" authpb "github.com/hashicorp/boundary/internal/gen/controller/auth" - spbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services" "github.com/hashicorp/boundary/internal/host/plugin" "github.com/hashicorp/boundary/internal/host/static" "github.com/hashicorp/boundary/internal/iam" @@ -34,7 +31,6 @@ import ( "github.com/hashicorp/boundary/internal/requests" "github.com/hashicorp/boundary/internal/scheduler" "github.com/hashicorp/boundary/internal/server" - spb "github.com/hashicorp/boundary/internal/server" "github.com/hashicorp/boundary/internal/session" "github.com/hashicorp/boundary/internal/target" "github.com/hashicorp/boundary/internal/target/tcp" @@ -2937,9 +2933,6 @@ func TestAuthorizeSession_Errors(t *testing.T) { sessionRepoFn := func() (*session.Repository, error) { return session.NewRepository(rw, rw, kms) } - connectionRepoFn := func() (*session.ConnectionRepository, error) { - return session.NewConnectionRepository(ctx, rw, rw, kms) - } staticHostRepoFn := func() (*static.Repository, error) { return static.NewRepository(rw, rw, kms) } @@ -2982,15 +2975,7 @@ func TestAuthorizeSession_Errors(t *testing.T) { store := vault.TestCredentialStore(t, conn, wrapper, proj.GetPublicId(), v.Addr, tok, sec.Auth.Accessor) workerExists := func(tar target.Target) (version uint32) { - workerService := cluster.NewWorkerServiceServer(serversRepoFn, sessionRepoFn, connectionRepoFn, &sync.Map{}, kms) - _, err := workerService.Status(context.Background(), &spbs.StatusRequest{ - WorkerStatus: &spb.ServerWorkerStatus{ - PublicId: "w_1234567890", - Name: "w_1234567890", - Address: "localhost:123", - }, - }) - require.NoError(t, err) + server.TestKmsWorker(t, conn, wrapper) return tar.GetVersion() } diff --git a/internal/daemon/worker/status.go b/internal/daemon/worker/status.go index 5939eba328..e51585087b 100644 --- a/internal/daemon/worker/status.go +++ b/internal/daemon/worker/status.go @@ -7,7 +7,7 @@ import ( "math/rand" "time" - "github.com/hashicorp/boundary/internal/server" + pb "github.com/hashicorp/boundary/internal/gen/controller/servers" "github.com/hashicorp/boundary/internal/daemon/worker/common" "github.com/hashicorp/boundary/internal/daemon/worker/session" @@ -139,11 +139,11 @@ func (w *Worker) sendWorkerStatus(cancelCtx context.Context) { // Send status information client := w.controllerStatusConn.Load().(pbs.ServerCoordinationServiceClient) - var tags []*server.TagPair + var tags []*pb.TagPair // If we're not going to request a tag update, no reason to have these // marshaled on every status call. if w.updateTags.Load() { - tags = w.tags.Load().([]*server.TagPair) + tags = w.tags.Load().([]*pb.TagPair) } statusCtx, statusCancel := context.WithTimeout(cancelCtx, common.StatusTimeout) defer statusCancel() @@ -157,7 +157,7 @@ func (w *Worker) sendWorkerStatus(cancelCtx context.Context) { result, err := client.Status(statusCtx, &pbs.StatusRequest{ Jobs: activeJobs, - WorkerStatus: &server.ServerWorkerStatus{ + WorkerStatus: &pb.ServerWorkerStatus{ Name: w.conf.RawConfig.Worker.Name, Description: w.conf.RawConfig.Worker.Description, Address: w.conf.RawConfig.Worker.PublicAddr, diff --git a/internal/daemon/worker/worker.go b/internal/daemon/worker/worker.go index 9af61d34e8..654d925eaa 100644 --- a/internal/daemon/worker/worker.go +++ b/internal/daemon/worker/worker.go @@ -14,7 +14,8 @@ import ( "sync/atomic" "time" - "github.com/hashicorp/boundary/internal/server" + pb "github.com/hashicorp/boundary/internal/gen/controller/servers" + "github.com/hashicorp/nodeenrollment" "github.com/mr-tron/base58" @@ -388,13 +389,13 @@ func (w *Worker) Resolver() *manual.Resolver { func (w *Worker) ParseAndStoreTags(incoming map[string][]string) { if len(incoming) == 0 { - w.tags.Store([]*server.TagPair{}) + w.tags.Store([]*pb.TagPair{}) return } - tags := []*server.TagPair{} + tags := []*pb.TagPair{} for k, vals := range incoming { for _, v := range vals { - tags = append(tags, &server.TagPair{ + tags = append(tags, &pb.TagPair{ Key: k, Value: v, }) diff --git a/internal/server/servers.pb.go b/internal/gen/controller/servers/servers.pb.go similarity index 96% rename from internal/server/servers.pb.go rename to internal/gen/controller/servers/servers.pb.go index 831a8bc1fa..dcd1cfcb72 100644 --- a/internal/server/servers.pb.go +++ b/internal/gen/controller/servers/servers.pb.go @@ -4,7 +4,7 @@ // protoc (unknown) // source: controller/servers/v1/servers.proto -package server +package servers import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -192,11 +192,12 @@ var file_controller_servers_v1_servers_proto_rawDesc = []byte{ 0x0b, 0x32, 0x1e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x67, 0x50, 0x61, 0x69, 0x72, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x15, 0x0a, 0x06, 0x6b, 0x65, 0x79, 0x5f, 0x69, - 0x64, 0x18, 0x32, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6b, 0x65, 0x79, 0x49, 0x64, 0x42, 0x36, - 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, + 0x64, 0x18, 0x32, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6b, 0x65, 0x79, 0x49, 0x64, 0x42, 0x47, + 0x5a, 0x45, 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, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3b, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x3b, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/gen/controller/servers/services/server_coordination_service.pb.go b/internal/gen/controller/servers/services/server_coordination_service.pb.go index 5f1fe565b7..81afd84eaf 100644 --- a/internal/gen/controller/servers/services/server_coordination_service.pb.go +++ b/internal/gen/controller/servers/services/server_coordination_service.pb.go @@ -7,7 +7,7 @@ package services import ( - server "github.com/hashicorp/boundary/internal/server" + servers "github.com/hashicorp/boundary/internal/gen/controller/servers" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -586,7 +586,7 @@ type StatusRequest struct { // The worker info. We could use information from the TLS connection but this // is easier and going the other route doesn't provide much benefit -- if you // get access to the key and spoof the connection, you're already compromised. - WorkerStatus *server.ServerWorkerStatus `protobuf:"bytes,40,opt,name=worker_status,json=workerStatus,proto3" json:"worker_status,omitempty"` + WorkerStatus *servers.ServerWorkerStatus `protobuf:"bytes,40,opt,name=worker_status,json=workerStatus,proto3" json:"worker_status,omitempty"` } func (x *StatusRequest) Reset() { @@ -635,7 +635,7 @@ func (x *StatusRequest) GetUpdateTags() bool { return false } -func (x *StatusRequest) GetWorkerStatus() *server.ServerWorkerStatus { +func (x *StatusRequest) GetWorkerStatus() *servers.ServerWorkerStatus { if x != nil { return x.WorkerStatus } @@ -924,20 +924,20 @@ func file_controller_servers_services_v1_server_coordination_service_proto_rawDe var file_controller_servers_services_v1_server_coordination_service_proto_enumTypes = make([]protoimpl.EnumInfo, 5) var file_controller_servers_services_v1_server_coordination_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_controller_servers_services_v1_server_coordination_service_proto_goTypes = []interface{}{ - (CONNECTIONSTATUS)(0), // 0: controller.servers.services.v1.CONNECTIONSTATUS - (SESSIONSTATUS)(0), // 1: controller.servers.services.v1.SESSIONSTATUS - (JOBTYPE)(0), // 2: controller.servers.services.v1.JOBTYPE - (CHANGETYPE)(0), // 3: controller.servers.services.v1.CHANGETYPE - (UpstreamServer_TYPE)(0), // 4: controller.servers.services.v1.UpstreamServer.TYPE - (*Connection)(nil), // 5: controller.servers.services.v1.Connection - (*SessionJobInfo)(nil), // 6: controller.servers.services.v1.SessionJobInfo - (*Job)(nil), // 7: controller.servers.services.v1.Job - (*JobStatus)(nil), // 8: controller.servers.services.v1.JobStatus - (*UpstreamServer)(nil), // 9: controller.servers.services.v1.UpstreamServer - (*StatusRequest)(nil), // 10: controller.servers.services.v1.StatusRequest - (*JobChangeRequest)(nil), // 11: controller.servers.services.v1.JobChangeRequest - (*StatusResponse)(nil), // 12: controller.servers.services.v1.StatusResponse - (*server.ServerWorkerStatus)(nil), // 13: controller.servers.v1.ServerWorkerStatus + (CONNECTIONSTATUS)(0), // 0: controller.servers.services.v1.CONNECTIONSTATUS + (SESSIONSTATUS)(0), // 1: controller.servers.services.v1.SESSIONSTATUS + (JOBTYPE)(0), // 2: controller.servers.services.v1.JOBTYPE + (CHANGETYPE)(0), // 3: controller.servers.services.v1.CHANGETYPE + (UpstreamServer_TYPE)(0), // 4: controller.servers.services.v1.UpstreamServer.TYPE + (*Connection)(nil), // 5: controller.servers.services.v1.Connection + (*SessionJobInfo)(nil), // 6: controller.servers.services.v1.SessionJobInfo + (*Job)(nil), // 7: controller.servers.services.v1.Job + (*JobStatus)(nil), // 8: controller.servers.services.v1.JobStatus + (*UpstreamServer)(nil), // 9: controller.servers.services.v1.UpstreamServer + (*StatusRequest)(nil), // 10: controller.servers.services.v1.StatusRequest + (*JobChangeRequest)(nil), // 11: controller.servers.services.v1.JobChangeRequest + (*StatusResponse)(nil), // 12: controller.servers.services.v1.StatusResponse + (*servers.ServerWorkerStatus)(nil), // 13: controller.servers.v1.ServerWorkerStatus } var file_controller_servers_services_v1_server_coordination_service_proto_depIdxs = []int32{ 0, // 0: controller.servers.services.v1.Connection.status:type_name -> controller.servers.services.v1.CONNECTIONSTATUS diff --git a/internal/proto/controller/servers/v1/servers.proto b/internal/proto/controller/servers/v1/servers.proto index 3a89da65cc..a22763f03d 100644 --- a/internal/proto/controller/servers/v1/servers.proto +++ b/internal/proto/controller/servers/v1/servers.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package controller.servers.v1; -option go_package = "github.com/hashicorp/boundary/internal/server;server"; +option go_package = "github.com/hashicorp/boundary/internal/gen/controller/servers;servers"; // TagPair matches a key to a value. message TagPair {