refactor(worker): Move tcp_proxy into its own package (#1458)

* refactor(worker): Move tcp_proxy into its own package

This refactors:

- the tcp_proxy.go into worker/proxy/tcp
- add a missing unit test for the HandleTcpProxyV1
- refactors session.go into worker/session, needed to avoid import cycle
- adds a baseline for a mock controller session client
- go lint fixes

* Add sleep between spinning listener goroutine and dialing

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
This commit is contained in:
Louis RuchandJeff Mitchell authored and GitHub committed 2021-08-18 15:30:55 +02:00
1 parent c79daab68c
commit 31af49e76d
29 files changed
+1229 -773

No files matched your search

@@ -1017,9 +1017,9 @@ HostSourceIterationLoop:
for _, l := range libs {
reqs = append(reqs, credential.Request{
SourceId: l.Id(),
Purpose: credential.Purpose(l.CredentialPurpose()),
Purpose: l.CredentialPurpose(),
})
dynCreds = append(dynCreds, session.NewDynamicCredential(l.Id(), credential.Purpose(l.CredentialPurpose())))
dynCreds = append(dynCreds, session.NewDynamicCredential(l.Id(), l.CredentialPurpose()))
}
expTime := timestamppb.Now()
@@ -367,8 +367,7 @@ func (ws *workerServiceServer) ActivateSession(ctx context.Context, req *pbs.Act
}
func (ws *workerServiceServer) AuthorizeConnection(ctx context.Context, req *pbs.AuthorizeConnectionRequest) (*pbs.AuthorizeConnectionResponse, error) {
const op = "workers.(workerServiceServer"
const op = "workers.(workerServiceServer).AuthorizeConnection"
sessRepo, err := ws.sessionRepoFn()
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting session repo: %v", err)
@@ -399,7 +398,6 @@ func (ws *workerServiceServer) AuthorizeConnection(ctx context.Context, req *pbs
func (ws *workerServiceServer) ConnectConnection(ctx context.Context, req *pbs.ConnectConnectionRequest) (*pbs.ConnectConnectionResponse, error) {
const op = "workers.(workerServiceServer).ConnectConnection"
sessRepo, err := ws.sessionRepoFn()
if err != nil {
return nil, status.Errorf(codes.Internal, "error getting session repo: %v", err)
@@ -419,25 +417,9 @@ func (ws *workerServiceServer) ConnectConnection(ctx context.Context, req *pbs.C
return nil, status.Error(codes.Internal, "Invalid connect connection response.")
}
ret := &pbs.ConnectConnectionResponse{
return &pbs.ConnectConnectionResponse{
Status: connStates[0].Status.ProtoVal(),
}
loggerPairs := []interface{}{
"session_id", connectionInfo.SessionId,
"connection_id", req.ConnectionId,
"client_tcp_address", req.ClientTcpAddress,
"client_tcp_port", req.ClientTcpPort,
}
switch req.GetType() {
case "tcp":
loggerPairs = append(loggerPairs,
"endpoint_tcp_address", connectionInfo.EndpointTcpAddress,
"endpoint_tcp_port", connectionInfo.EndpointTcpPort,
)
}
return ret, nil
}, nil
}
func (ws *workerServiceServer) CloseConnection(ctx context.Context, req *pbs.CloseConnectionRequest) (*pbs.CloseConnectionResponse, error) {