-
Notifications
You must be signed in to change notification settings - Fork 13
/
client_config.go
51 lines (41 loc) · 1.27 KB
/
client_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package go_sftp
import "time"
type ClientConfig struct {
Hostname string
Username string
Password string
Timeout time.Duration
MaxConnections int
PacketSize int
// HostPublicKey configures an SSH public key to validate the remote server's host key.
// If provided, this key will be merged into HostPublicKeys.
// Deprecated: Use HostPublicKeys instead.
HostPublicKey string
// HostPublicKeys configures multiple SSH public keys to validate the remote server's host key.
// Any key provided in HostPublicKey will be appended to this list.
HostPublicKeys []string
// ClientPrivateKey must be a base64 encoded string
ClientPrivateKey string
ClientPrivateKeyPassword string // not base64 encoded
SkipChmodAfterUpload bool
SkipDirectoryCreation bool
}
// HostKeys returns the list of configured public keys to use for host key verification.
func (cfg ClientConfig) HostKeys() []string {
if cfg.HostPublicKey != "" {
cfg.HostPublicKeys = append(cfg.HostPublicKeys, cfg.HostPublicKey)
}
return dedupe(cfg.HostPublicKeys)
}
func dedupe[T comparable](vals []T) []T {
seen := make(map[T]struct{})
var out []T
for i := range vals {
if _, ok := seen[vals[i]]; ok {
continue
}
seen[vals[i]] = struct{}{}
out = append(out, vals[i])
}
return out
}