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.
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
|
|
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type workerProxyServiceServer struct {
|
|
pbs.UnsafeServerCoordinationServiceServer
|
|
pbs.UnsafeSessionServiceServer
|
|
|
|
scsClient *atomic.Value
|
|
ssClient pbs.SessionServiceClient
|
|
}
|
|
|
|
var (
|
|
_ pbs.ServerCoordinationServiceServer = (*workerProxyServiceServer)(nil)
|
|
_ pbs.SessionServiceServer = (*workerProxyServiceServer)(nil)
|
|
)
|
|
|
|
func NewWorkerProxyServiceServer(
|
|
cc *grpc.ClientConn,
|
|
scsClient *atomic.Value,
|
|
) *workerProxyServiceServer {
|
|
return &workerProxyServiceServer{
|
|
scsClient: scsClient,
|
|
ssClient: pbs.NewSessionServiceClient(cc),
|
|
}
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) Status(ctx context.Context, req *pbs.StatusRequest) (*pbs.StatusResponse, error) {
|
|
resp, err := ws.scsClient.Load().(pbs.ServerCoordinationServiceClient).Status(ctx, req)
|
|
|
|
if resp != nil {
|
|
// We don't currently support distributing new addreses to workers
|
|
// multiple hops away so ensure they're stripped out
|
|
resp.CalculatedUpstreams = nil
|
|
}
|
|
|
|
return resp, err
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) ListHcpbWorkers(ctx context.Context, req *pbs.ListHcpbWorkersRequest) (*pbs.ListHcpbWorkersResponse, error) {
|
|
return ws.scsClient.Load().(pbs.ServerCoordinationServiceClient).ListHcpbWorkers(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) LookupSession(ctx context.Context, req *pbs.LookupSessionRequest) (*pbs.LookupSessionResponse, error) {
|
|
return ws.ssClient.LookupSession(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) CancelSession(ctx context.Context, req *pbs.CancelSessionRequest) (*pbs.CancelSessionResponse, error) {
|
|
return ws.ssClient.CancelSession(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) ActivateSession(ctx context.Context, req *pbs.ActivateSessionRequest) (*pbs.ActivateSessionResponse, error) {
|
|
return ws.ssClient.ActivateSession(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) AuthorizeConnection(ctx context.Context, req *pbs.AuthorizeConnectionRequest) (*pbs.AuthorizeConnectionResponse, error) {
|
|
return ws.ssClient.AuthorizeConnection(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) ConnectConnection(ctx context.Context, req *pbs.ConnectConnectionRequest) (*pbs.ConnectConnectionResponse, error) {
|
|
return ws.ssClient.ConnectConnection(ctx, req)
|
|
}
|
|
|
|
func (ws *workerProxyServiceServer) CloseConnection(ctx context.Context, req *pbs.CloseConnectionRequest) (*pbs.CloseConnectionResponse, error) {
|
|
return ws.ssClient.CloseConnection(ctx, req)
|
|
}
|