Fix error about unimplemented HcpbWorkers call (#2361)

Although there is a compile time check on the type, it will always
succeed due to the Unimplemented embedding requirement.

As a result, this PR also changes Unimplemented calls to Unsafe calls,
which were added later "for those that prefer their code to break"; the
comments on these state:

// UnsafeXServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to XServiceServer will
// result in compilation errors.

See https://github.com/grpc/grpc-go/issues/4500#issuecomment-852597871
for some more context.

I think we're fine with compilation errors though; we own both the
server and client side of things and generally are going to add new
methods only when we intend to also add them on the client side.
Notably, what the comment does not indicate is that it will break at
runtime; already it should return a suitable (404 or 405) error if the
client requests a method that does not exist.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2022-08-30 14:22:10 -04:00
1 parent 17ddc301a8
commit 9b271d7dd8
21 files changed
+72 -66

No files matched your search

@@ -16,7 +16,7 @@ import (
)
type multihopServiceServer struct {
multihop.UnimplementedMultihopServiceServer
multihop.UnsafeMultihopServiceServer
storage nodeenrollment.Storage
direct bool
@@ -24,6 +24,8 @@ type multihopServiceServer struct {
options []nodeenrollment.Option
}
var _ multihop.MultihopServiceServer = (*multihopServiceServer)(nil)
// NewMultihopServiceServer creates a new service implementing
// MultihopServiceServer, storing values used for the implementing functions.
func NewMultihopServiceServer(storage nodeenrollment.Storage, direct bool, client *atomic.Value, opt ...nodeenrollment.Option) (*multihopServiceServer, error) {
@@ -44,8 +46,6 @@ func NewMultihopServiceServer(storage nodeenrollment.Storage, direct bool, clien
}, nil
}
var _ multihop.MultihopServiceServer = (*multihopServiceServer)(nil)
// FetchNodeCredentials implements the MultihopServiceServer interface. If it's
// direct (e.g. running on a controller) it handles the request directly,
// otherwise sends it to its next hop.
@@ -25,8 +25,8 @@ import (
const ManagedWorkerTagKey = "boundary.cloud.hashicorp.com:managed"
type workerServiceServer struct {
pbs.UnimplementedServerCoordinationServiceServer
pbs.UnimplementedSessionServiceServer
pbs.UnsafeServerCoordinationServiceServer
pbs.UnsafeSessionServiceServer
serversRepoFn common.ServersRepoFactory
sessionRepoFn common.SessionRepoFactory
@@ -35,6 +35,11 @@ type workerServiceServer struct {
kms *kms.Kms
}
var (
_ pbs.SessionServiceServer = &workerServiceServer{}
_ pbs.ServerCoordinationServiceServer = &workerServiceServer{}
)
func NewWorkerServiceServer(
serversRepoFn common.ServersRepoFactory,
sessionRepoFn common.SessionRepoFactory,
@@ -51,11 +56,6 @@ func NewWorkerServiceServer(
}
}
var (
_ pbs.SessionServiceServer = &workerServiceServer{}
_ pbs.ServerCoordinationServiceServer = &workerServiceServer{}
)
func (ws *workerServiceServer) Status(ctx context.Context, req *pbs.StatusRequest) (*pbs.StatusResponse, error) {
const op = "workers.(workerServiceServer).Status"
// TODO: on the worker, if we get errors back from this repeatedly, do we