Skip to content

Commit 6fac24e

Browse files
code changes (#19)
1 parent f8d1236 commit 6fac24e

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

pkg/actions/download.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func Download(c *cli.Context) error {
6363
}
6464
if err := utils.WriteConfig(lo.Map(data.SshConfig, func(config dto.SshConfigDto, i int) models.Host {
6565
return models.Host{
66-
Host: config.Host,
67-
Values: config.Values,
68-
IdentityFile: config.IdentityFile,
66+
Host: config.Host,
67+
Values: config.Values,
68+
IdentityFiles: config.IdentityFiles,
6969
}
7070
})); err != nil {
7171
return err
@@ -76,5 +76,6 @@ func Download(c *cli.Context) error {
7676
return err
7777
}
7878
}
79+
fmt.Println("Successfully downloaded keys.")
7980
return nil
8081
}

pkg/dto/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type KeyDto struct {
2222
}
2323

2424
type SshConfigDto struct {
25-
Host string `json:"host"`
26-
Values map[string]string `json:"values"`
27-
IdentityFile string `json:"identity_file"`
25+
Host string `json:"host"`
26+
Values map[string][]string `json:"values"`
27+
IdentityFiles []string `json:"identity_files"`
2828
}
2929

3030
type MachineDto struct {

pkg/models/host.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package models
22

33
type Host struct {
4-
Host string `json:"host"`
5-
IdentityFile string `json:"identity_file"`
6-
Values map[string]string `json:"values"`
4+
Host string `json:"host"`
5+
IdentityFiles []string `json:"identity_files"`
6+
Values map[string][]string `json:"values"`
77
}

pkg/utils/parseconfig.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ func ParseConfig() ([]models.Host, error) {
3636
}
3737
currentHost = &models.Host{
3838
Host: strings.TrimPrefix(line, "Host "),
39-
Values: make(map[string]string),
39+
Values: make(map[string][]string),
4040
}
4141
} else if re.Match([]byte(line)) {
4242
key := re.FindStringSubmatch(line)[1]
4343
value := re.FindStringSubmatch(line)[2]
44-
if key == "IdentityFile" {
44+
if strings.ToLower(key) == "identityfile" {
4545
homeDir := user.HomeDir
4646
if runtime.GOOS == "windows" {
4747
value = strings.ToLower(value)
4848
homeDir = strings.ToLower(user.HomeDir)
4949
}
5050
identityFile := strings.TrimPrefix(value, homeDir)
5151
normalizedIdentityFilePath := filepath.ToSlash(identityFile)
52-
currentHost.IdentityFile = normalizedIdentityFilePath
52+
currentHost.IdentityFiles = append(currentHost.IdentityFiles, normalizedIdentityFilePath)
5353
} else {
54-
currentHost.Values[key] = value
54+
currentHost.Values[key] = append(currentHost.Values[key], value)
5555
}
5656

5757
}

pkg/utils/write.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ func WriteConfig(hosts []models.Host) error {
3131
if _, err := file.WriteString(fmt.Sprintf("Host %s\n", host.Host)); err != nil {
3232
return err
3333
}
34-
if host.IdentityFile != "" {
35-
if _, err := file.WriteString(fmt.Sprintf("\t%s %s\n", "IdentityFile", filepath.Join(user.HomeDir, host.IdentityFile))); err != nil {
36-
return err
34+
if host.IdentityFiles != nil {
35+
for _, identityFile := range host.IdentityFiles {
36+
if _, err := file.WriteString(fmt.Sprintf("\t%s %s\n", "IdentityFile", filepath.Join(user.HomeDir, identityFile))); err != nil {
37+
return err
38+
}
3739
}
3840
}
3941
for key, value := range host.Values {
40-
if _, err := file.WriteString(fmt.Sprintf("\t%s %s\n", key, value)); err != nil {
41-
return err
42+
for _, item := range value {
43+
if _, err := file.WriteString(fmt.Sprintf("\t%s %s\n", key, item)); err != nil {
44+
return err
45+
}
4246
}
4347
}
4448
}

todo.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
MUST HAVES:
22
- data conflicts - how to resolve merging?
3-
- currently it is possible to upload a duplicate ssh_configs entry where host, identity_file, etc. are the same. Probably need to figure this one out
43
- Allow users to delete certain keys or config entries
5-
- allow users to obtain a list of their machines
64
- test delete code more
75
- if EOF is received, need to have nicer error message. Also cleanup better - what if part way thru setup and EOF happens?
86
- server seems to sometimes panic when websocket connection gets closed in a strange way.

0 commit comments

Comments
 (0)