/
types.go
117 lines (99 loc) · 2.97 KB
/
types.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package myssh
import (
"time"
)
type Environment struct {
StorePath string
SSHPath string
SKMPath string
}
// ListOption options for List
type ListOption struct {
// Keywords set Keyword filter records
Keywords []string
// IgnoreCase ignore case
IgnoreCase bool
}
// ServerConfig server config
type ServerConfig struct {
Name string `yaml:"name"`
Address string `yaml:"address"`
Port int `yaml:"port,omitempty"`
User string `yaml:"user,omitempty"`
Password string `yaml:"password,omitempty"`
PrivateKey string `yaml:"privateKey,omitempty"`
PrivateKeyPassword string `yaml:"privateKey_password,omitempty"`
Method string `yaml:"method"` // auth method default:key,options:password、key
SuRoot bool `yaml:"su_root"`
UseSudo bool `yaml:"use_sudo"`
NoPasswordSudo bool `yaml:"no_password_sudo"`
RootPassword string `yaml:"root_password"`
ServerAliveInterval time.Duration `yaml:"server_alive_interval"`
}
// Servers myssh servers
type Servers []*ServerConfig
func (servers Servers) Len() int {
return len(servers)
}
func (servers Servers) Less(i, j int) bool {
return servers[i].Name < servers[j].Name
}
func (servers Servers) Swap(i, j int) {
servers[i], servers[j] = servers[j], servers[i]
}
// ************************************************************************
type Clusters []*ClusterConfig
func (cs Clusters) Len() int {
return len(cs)
}
func (cs Clusters) Less(i, j int) bool {
return cs[i].Name < cs[j].Name
}
func (cs Clusters) Swap(i, j int) {
cs[i], cs[j] = cs[j], cs[i]
}
type ClusterConfig struct {
Name string `yaml:"name"`
HostPattern string `yaml:"hostPattern"`
}
type ClustersConfig struct {
configPath string
Default DefaultClusterConfig `yaml:"default"`
Clusters Clusters `yaml:"clusters"`
}
type DefaultClusterConfig struct {
User string `yaml:"user"`
PrivateKey string `yaml:"privateKey"`
Port int `yaml:"port"`
ServerAliveInterval time.Duration `yaml:"server_alive_interval"`
}
func (cfg *ClustersConfig) SetConfigPath(configPath string) {
cfg.configPath = configPath
}
func (cfg *ClustersConfig) ConfigPath() string {
return cfg.configPath
}
// Context myssh context
type Context struct {
Name string `yaml:"name"`
SSHConfig string `yaml:"sshconfig"`
ClusterConfig string `yaml:"clusterCfg"`
}
// Contexts myssh contexts
type Contexts []Context
func (cs Contexts) Len() int {
return len(cs)
}
func (cs Contexts) Less(i, j int) bool {
return cs[i].Name < cs[j].Name
}
func (cs Contexts) Swap(i, j int) {
cs[i], cs[j] = cs[j], cs[i]
}
// MainConfig main config struct
type MainConfig struct {
configPath string
Basic string `yaml:"basic"`
Contexts Contexts `yaml:"contexts"`
Current string `yaml:"current"`
}