mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-20 02:22:28 +01:00
remove two calls to conn.Connect() (#1757)
This commit is contained in:
parent
db7d3dac67
commit
1cd1744317
@ -400,7 +400,7 @@ func (bc *BlockController) setupAndStartShellProcess(logCtx context.Context, rc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conn := conncontroller.GetConn(credentialCtx, opts, false, &wshrpc.ConnKeywords{})
|
||||
conn := conncontroller.GetConn(credentialCtx, opts, &wshrpc.ConnKeywords{})
|
||||
connStatus := conn.DeriveConnStatus()
|
||||
if connStatus.Status != conncontroller.Status_Connected {
|
||||
return nil, fmt.Errorf("not connected, cannot start shellproc")
|
||||
@ -762,7 +762,7 @@ func CheckConnStatus(blockId string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := conncontroller.GetConn(context.Background(), opts, false, &wshrpc.ConnKeywords{})
|
||||
conn := conncontroller.GetConn(context.Background(), opts, &wshrpc.ConnKeywords{})
|
||||
connStatus := conn.DeriveConnStatus()
|
||||
if connStatus.Status != conncontroller.Status_Connected {
|
||||
return fmt.Errorf("not connected: %s", connStatus.Status)
|
||||
|
@ -503,14 +503,6 @@ func (conn *SSHConn) GetClient() *ssh.Client {
|
||||
return conn.Client
|
||||
}
|
||||
|
||||
func (conn *SSHConn) Reconnect(ctx context.Context) error {
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return conn.Connect(ctx, &wshrpc.ConnKeywords{})
|
||||
}
|
||||
|
||||
func (conn *SSHConn) WaitForConnect(ctx context.Context) error {
|
||||
for {
|
||||
status := conn.DeriveConnStatus()
|
||||
@ -819,11 +811,9 @@ func getConnInternal(opts *remote.SSHOpts) *SSHConn {
|
||||
return rtn
|
||||
}
|
||||
|
||||
func GetConn(ctx context.Context, opts *remote.SSHOpts, shouldConnect bool, connFlags *wshrpc.ConnKeywords) *SSHConn {
|
||||
// does NOT connect, can return nil if connection does not exist
|
||||
func GetConn(ctx context.Context, opts *remote.SSHOpts, connFlags *wshrpc.ConnKeywords) *SSHConn {
|
||||
conn := getConnInternal(opts)
|
||||
if conn.Client == nil && shouldConnect {
|
||||
conn.Connect(ctx, connFlags)
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
@ -836,7 +826,7 @@ func EnsureConnection(ctx context.Context, connName string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
|
||||
conn := GetConn(ctx, connOpts, &wshrpc.ConnKeywords{})
|
||||
if conn == nil {
|
||||
return fmt.Errorf("connection not found: %s", connName)
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ func (ws *WshServer) ConnDisconnectCommand(ctx context.Context, connName string)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := conncontroller.GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
|
||||
conn := conncontroller.GetConn(ctx, connOpts, &wshrpc.ConnKeywords{})
|
||||
if conn == nil {
|
||||
return fmt.Errorf("connection not found: %s", connName)
|
||||
}
|
||||
@ -675,7 +675,7 @@ func (ws *WshServer) ConnConnectCommand(ctx context.Context, connRequest wshrpc.
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := conncontroller.GetConn(ctx, connOpts, false, &connRequest.Keywords)
|
||||
conn := conncontroller.GetConn(ctx, connOpts, &connRequest.Keywords)
|
||||
if conn == nil {
|
||||
return fmt.Errorf("connection not found: %s", connName)
|
||||
}
|
||||
@ -698,7 +698,7 @@ func (ws *WshServer) ConnReinstallWshCommand(ctx context.Context, data wshrpc.Co
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := conncontroller.GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
|
||||
conn := conncontroller.GetConn(ctx, connOpts, &wshrpc.ConnKeywords{})
|
||||
if conn == nil {
|
||||
return fmt.Errorf("connection not found: %s", connName)
|
||||
}
|
||||
@ -735,7 +735,7 @@ func (ws *WshServer) ConnUpdateWshCommand(ctx context.Context, remoteInfo wshrpc
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing connection name: %w", err)
|
||||
}
|
||||
conn := conncontroller.GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
|
||||
conn := conncontroller.GetConn(ctx, connOpts, &wshrpc.ConnKeywords{})
|
||||
if conn == nil {
|
||||
return false, fmt.Errorf("connection not found: %s", connName)
|
||||
}
|
||||
@ -787,7 +787,7 @@ func (ws *WshServer) DismissWshFailCommand(ctx context.Context, connName string)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conn := conncontroller.GetConn(ctx, opts, false, nil)
|
||||
conn := conncontroller.GetConn(ctx, opts, nil)
|
||||
if conn == nil {
|
||||
return fmt.Errorf("connection %s not found", connName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user