Skip to content

Commit fb68c4e

Browse files
authored
Merge pull request #6 from rzkmak/feature-default-user
feat: default user
2 parents 94df42c + db9316a commit fb68c4e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

example/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
password: "MTIzCg==" #123 (b64 encoded)
55
port: "22"
66
alias: "server-name"
7+
default_user: true
78
key: |
89
MTIzNDU2Nzg5MTAK
910
# 123456 (b64 encoded)

reader/config.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import (
44
"encoding/base64"
55
"errors"
66
"fmt"
7-
"gopkg.in/yaml.v2"
87
"io/ioutil"
98
"log"
109
"os"
1110
"strings"
11+
12+
"gopkg.in/yaml.v2"
1213
)
1314

1415
type SshConfigs struct {
1516
Config map[string]SshConfig
1617
}
1718

1819
type SshConfig struct {
19-
Hostname string `yaml:"hostname"`
20-
User string `yaml:"user"`
21-
Password string `yaml:"password"`
22-
Port string `yaml:"port"`
23-
Key string `yaml:"key"`
24-
Alias string `yaml:"alias"`
20+
Hostname string `yaml:"hostname"`
21+
User string `yaml:"user"`
22+
Password string `yaml:"password"`
23+
Port string `yaml:"port"`
24+
Key string `yaml:"key"`
25+
DefaultUser bool `yaml:"default_user"`
26+
Alias string `yaml:"alias"`
2527
}
2628

2729
func ReadYaml() (SshConfigs, error) {
@@ -73,6 +75,15 @@ func ReadYaml() (SshConfigs, error) {
7375
configs[config[i].Alias] = config[i]
7476
}
7577

78+
configs[fmt.Sprintf("%v@%v", config[i].User, config[i].Hostname)] = config[i]
79+
80+
if config[i].DefaultUser {
81+
_, found := configs[config[i].Hostname]
82+
if found {
83+
log.Fatalln("duplicated hostname found for", config[i].Hostname)
84+
}
85+
configs[config[i].Hostname] = config[i]
86+
}
7687
}
7788
}
7889
if len(configs) == 0 {

0 commit comments

Comments
 (0)