-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* (fix) reuse ssh client donot create multiple clients if client already exists this is to not kill the remote server with a lot of ssh open agents * (feat) auto recover a client * (feat) minor UI improvement
- Loading branch information
1 parent
db3445e
commit 6dbfc64
Showing
9 changed files
with
89 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package pkg | ||
|
||
import ( | ||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
var GlobalFilePaths []FileInfo | ||
var GlobalPipeTmpFilePath string | ||
var GlobalPathSSHConfig []SSHPathConfig | ||
var GlobalSSHClients = make(map[string]*ssh.Client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package pkg | ||
|
||
import ( | ||
"sync" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
var ( | ||
clientMutex = &sync.Mutex{} | ||
) | ||
|
||
func NewSession(config *SSHConfig) (*ssh.Session, error) { | ||
client, err := NewOrReusableClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
session, err := client.NewSession() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return session, nil | ||
} | ||
|
||
func NewOrReusableClient(config *SSHConfig) (*ssh.Client, error) { | ||
key := config.Host + ":" + config.Port | ||
|
||
clientMutex.Lock() | ||
client := GlobalSSHClients[key] | ||
clientMutex.Unlock() | ||
|
||
if client == nil { | ||
c, err := sshConnect(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
clientMutex.Lock() | ||
GlobalSSHClients[key] = c | ||
clientMutex.Unlock() | ||
client = c | ||
} | ||
|
||
// check if client is still connected | ||
_, _, err := client.SendRequest("", true, nil) | ||
if err != nil { | ||
clientMutex.Lock() | ||
delete(GlobalSSHClients, key) | ||
clientMutex.Unlock() | ||
return NewOrReusableClient(config) | ||
} | ||
|
||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters