-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
75 lines (66 loc) · 1.51 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tclientlib
import (
"regexp"
"time"
)
type TerminalOptions struct {
Wide int
High int
TermType string
}
func defaultTerminalOptions() TerminalOptions {
return TerminalOptions{
Wide: 80,
High: 24,
TermType: "xterm",
}
}
type Config struct {
Username string
Password string
Timeout time.Duration
TTYOptions *TerminalOptions
UsernamePromptRegex *regexp.Regexp
PasswordPromptRegex *regexp.Regexp
LoginSuccessPromptRegex *regexp.Regexp
BuiltinUsernamePromptRegex *regexp.Regexp
BuiltinPasswordPromptRegex *regexp.Regexp
BuiltinSuccessPromptRegex *regexp.Regexp
BuiltinFailureRegex *regexp.Regexp
}
func (conf *Config) SetDefaults() {
if conf.Timeout == 0 || conf.Timeout < defaultTimeout {
conf.Timeout = defaultTimeout
}
t := defaultTerminalOptions()
opts := conf.TTYOptions
if opts == nil {
conf.TTYOptions = &t
} else {
if opts.Wide == 0 {
opts.Wide = t.Wide
}
if opts.High == 0 {
opts.High = t.High
}
if opts.TermType == "" {
opts.TermType = "xterm"
}
}
if conf.BuiltinUsernamePromptRegex == nil {
conf.BuiltinUsernamePromptRegex = DefaultUsernamePattern
}
if conf.BuiltinPasswordPromptRegex == nil {
conf.BuiltinPasswordPromptRegex = DefaultPasswordPattern
}
if conf.BuiltinSuccessPromptRegex == nil {
conf.BuiltinSuccessPromptRegex = DefaultLoginSuccessPattern
}
if conf.BuiltinFailureRegex == nil {
conf.BuiltinFailureRegex = DefaultLoginFailedPattern
}
}
type status struct {
usernameDone bool
passwordDone bool
}