Skip to content

Commit 7f63dbf

Browse files
committed
Upd: Hide sensitive information in output logs
1 parent 38cc939 commit 7f63dbf

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

pkg/control/control.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package control
33
import (
44
"context"
55
"github.com/Driver-C/tryssh/pkg/launcher"
6+
"github.com/cheggaaa/pb/v3"
67
"sync"
78
"time"
89
)
@@ -17,8 +18,10 @@ const (
1718
)
1819

1920
func ConcurrencyTryToConnect(concurrency int, connectors []launcher.Connector) []launcher.Connector {
20-
var hitConnectors []launcher.Connector
21-
var mutex sync.Mutex
21+
hitConnectors := make([]launcher.Connector, 0)
22+
mutex := new(sync.Mutex)
23+
bar := pb.StartNew(len(connectors))
24+
bar.Set("prefix", "Attempting:")
2225
// If the number of connectors is less than the set concurrency, change the concurrency to the number of connectors
2326
if concurrency > len(connectors) {
2427
concurrency = len(connectors)
@@ -56,13 +59,16 @@ func ConcurrencyTryToConnect(concurrency int, connectors []launcher.Connector) [
5659
mutex.Lock()
5760
hitConnectors = append(hitConnectors, connector)
5861
mutex.Unlock()
62+
bar.Finish()
5963
cancelFunc()
6064
}
65+
bar.Increment()
6166
}
6267
}
63-
}(ctx, cancelFunc, connectorsChan, &wg, &mutex)
68+
}(ctx, cancelFunc, connectorsChan, &wg, mutex)
6469
}
6570
wg.Wait()
71+
bar.Finish()
6672
cancelFunc()
6773
return hitConnectors
6874
}

pkg/control/scp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (cc *ScpController) tryCopyWithoutCache(user string) {
8484
connectors[i] = l
8585
}
8686
hitLaunchers := ConcurrencyTryToConnect(cc.concurrency, connectors)
87-
if hitLaunchers != nil {
87+
if len(hitLaunchers) > 0 {
8888
utils.Logger.Infoln("Login succeeded. The cache will be added.\n")
8989
hitLauncher := hitLaunchers[0].(*launcher.ScpLauncher)
9090
// The new server cache information

pkg/control/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (sc *SshController) tryLoginWithoutCache(user string) {
5656
connectors[i] = l
5757
}
5858
hitLaunchers := ConcurrencyTryToConnect(sc.concurrency, connectors)
59-
if hitLaunchers != nil {
59+
if len(hitLaunchers) > 0 {
6060
utils.Logger.Infoln("Login succeeded. The cache will be added.\n")
6161
hitLauncher := hitLaunchers[0].(*launcher.SshLauncher)
6262
// The new server cache information

pkg/launcher/base.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ func (sc *SshConnector) CreateConnection() (sshClient *ssh.Client, err error) {
8181
if err != nil {
8282
if strings.Contains(err.Error(), SSHKeyKeyword) {
8383
// If it's a public key verification issue, just exit
84-
utils.Logger.Fatalf("Unable to connect: %s@%s, Password:%s Cause: %s\n",
85-
sc.User, addr, sc.Password, err.Error())
86-
} else {
87-
utils.Logger.Warnf("Unable to connect: %s@%s, Password:%s Cause: %s\n",
88-
sc.User, addr, sc.Password, err.Error())
84+
utils.Logger.Fatalf("Unable to connect: %s Cause: %s\n", addr, err.Error())
8985
}
9086
}
9187
return

pkg/launcher/ssh.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ func (h *SshLauncher) dialServer() (res bool) {
3737
if err == nil {
3838
utils.Logger.Infoln("[ LOGIN SUCCESSFUL ]\n")
3939
utils.Logger.Infoln("User:", sshClient.User())
40-
utils.Logger.Infoln("Password:", h.Password)
4140
utils.Logger.Infoln("Port:", h.Port)
42-
utils.Logger.Infoln("Ssh Server Version:", string(sshClient.ServerVersion()))
43-
utils.Logger.Infof("Ssh Client Version: %s\n\n", string(sshClient.ClientVersion()))
4441
res = true
4542
h.createTerminal(sshClient)
4643
} else {

0 commit comments

Comments
 (0)