Skip to content

Commit acbca79

Browse files
author
mritd
committed
feat(config): change config field name
change config field name Signed-off-by: mritd <[email protected]>
1 parent 0914d61 commit acbca79

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

pkg/mmh/config.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func WriteExampleConfig() {
5959
Proxy: "prod12",
6060
},
6161
{
62-
Name: "prod12",
63-
User: "root",
64-
Tags: []string{"prod"},
65-
Address: "10.10.4.12",
66-
Port: 22,
67-
PublicKey: "/Users/mritd/.ssh/id_rsa",
62+
Name: "prod12",
63+
User: "root",
64+
Tags: []string{"prod"},
65+
Address: "10.10.4.12",
66+
Port: 22,
67+
PrivateKey: "/Users/mritd/.ssh/id_rsa",
6868
},
6969
})
7070
viper.Set(keyTags, []string{
@@ -173,7 +173,7 @@ func AddServer() {
173173
}
174174

175175
// Auth method
176-
var password, publicKey string
176+
var password, privateKey string
177177
cfg := &promptx.SelectConfig{
178178
ActiveTpl: "» {{ . | cyan }}",
179179
InactiveTpl: " {{ . | white }}",
@@ -187,7 +187,7 @@ func AddServer() {
187187

188188
s := &promptx.Select{
189189
Items: []string{
190-
"PublicKey",
190+
"PrivateKey",
191191
"Password",
192192
},
193193
Config: cfg,
@@ -199,13 +199,13 @@ func AddServer() {
199199
// Allow empty
200200
return nil
201201

202-
}, "PublicKey:")
202+
}, "PrivateKey:")
203203

204-
publicKey = p.Run()
205-
if strings.TrimSpace(publicKey) == "" {
204+
privateKey = p.Run()
205+
if strings.TrimSpace(privateKey) == "" {
206206
home, err := homedir.Dir()
207207
utils.CheckAndExit(err)
208-
publicKey = home + string(filepath.Separator) + ".ssh" + string(filepath.Separator) + "id_rsa"
208+
privateKey = home + string(filepath.Separator) + ".ssh" + string(filepath.Separator) + "id_rsa"
209209
}
210210
} else {
211211
p = promptx.NewDefaultPrompt(func(line []rune) error {
@@ -231,14 +231,14 @@ func AddServer() {
231231
proxy := p.Run()
232232

233233
server := Server{
234-
Name: name,
235-
Tags: tags,
236-
User: user,
237-
Address: address,
238-
Port: port,
239-
PublicKey: publicKey,
240-
Password: password,
241-
Proxy: proxy,
234+
Name: name,
235+
Tags: tags,
236+
User: user,
237+
Address: address,
238+
Port: port,
239+
PrivateKey: privateKey,
240+
Password: password,
241+
Proxy: proxy,
242242
}
243243

244244
// Save

pkg/mmh/ssh.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import (
3131
)
3232

3333
type Server struct {
34-
Name string `yml:"Name"`
35-
Tags []string `yml:"Tags"`
36-
User string `yml:"User"`
37-
Password string `yml:"Password"`
38-
PublicKey string `yml:"PublicKey"`
39-
Address string `yml:"Address"`
40-
Port int `yml:"Port"`
41-
Proxy string `yml:"proxy"`
34+
Name string `yml:"Name"`
35+
Tags []string `yml:"Tags"`
36+
User string `yml:"User"`
37+
Password string `yml:"Password"`
38+
PrivateKey string `yml:"PrivateKey"`
39+
Address string `yml:"Address"`
40+
Port int `yml:"Port"`
41+
Proxy string `yml:"proxy"`
4242
}
4343

4444
type Servers []*Server
@@ -53,7 +53,7 @@ func (servers Servers) Swap(i, j int) {
5353
servers[i], servers[j] = servers[j], servers[i]
5454
}
5555

56-
func publicKeyFile(file string) (ssh.AuthMethod, error) {
56+
func privateKeyFile(file string) (ssh.AuthMethod, error) {
5757
buffer, err := ioutil.ReadFile(file)
5858
if err != nil {
5959
return nil, err
@@ -71,8 +71,8 @@ func password(password string) ssh.AuthMethod {
7171

7272
func (s *Server) authMethod() (ssh.AuthMethod, error) {
7373
// Priority use of public key
74-
if strings.TrimSpace(s.PublicKey) != "" {
75-
return publicKeyFile(s.PublicKey)
74+
if strings.TrimSpace(s.PrivateKey) != "" {
75+
return privateKeyFile(s.PrivateKey)
7676
} else {
7777
return password(s.Password), nil
7878
}

0 commit comments

Comments
 (0)