-
Notifications
You must be signed in to change notification settings - Fork 7
/
defaults.go
56 lines (39 loc) · 1.58 KB
/
defaults.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
52
53
54
55
56
package ssh
import (
"github.com/flexkube/libflexkube/internal/util"
)
const (
// User is a default user used for SSH connections.
User = "root"
// ConnectionTimeout is a default time SSH will wait while connecting to unreachable server.
ConnectionTimeout = "30s"
// RetryTimeout is a default time after we give up connecting to unreachable server.
RetryTimeout = "60s"
// RetryInterval is a default time how long we wait between SSH connection attempts.
RetryInterval = "1s"
// Port is a default port used for SSH connections.
Port = 22
)
// BuildConfig takes destination SSH configuration, struct with default values provided by the user
// and merges it together with global SSH default values.
func BuildConfig(sshConfig, defaults *Config) *Config {
if sshConfig == nil {
sshConfig = &Config{}
}
if defaults == nil {
defaults = &Config{}
}
sshConfig.PrivateKey = util.PickString(sshConfig.PrivateKey, defaults.PrivateKey)
sshConfig.User = util.PickString(sshConfig.User, defaults.User, User)
sshConfig.ConnectionTimeout = util.PickString(
sshConfig.ConnectionTimeout,
defaults.ConnectionTimeout,
ConnectionTimeout,
)
sshConfig.RetryTimeout = util.PickString(sshConfig.RetryTimeout, defaults.RetryTimeout, RetryTimeout)
sshConfig.RetryInterval = util.PickString(sshConfig.RetryInterval, defaults.RetryInterval, RetryInterval)
sshConfig.Port = util.PickInt(sshConfig.Port, defaults.Port, Port)
sshConfig.Address = util.PickString(sshConfig.Address, defaults.Address)
sshConfig.Password = util.PickString(sshConfig.Password, defaults.Password)
return sshConfig
}