Skip to content

Commit 72850d1

Browse files
authored
resolve tilde path correctly for identityfile and fix pubfile (#58)
1 parent 4096e51 commit 72850d1

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ NAME := sake
22
PACKAGE := github.com/alajmo/$(NAME)
33
DATE := $(shell date +%FT%T%Z)
44
GIT := $(shell [ -d .git ] && git rev-parse --short HEAD)
5-
VERSION := v0.15.0
5+
VERSION := v0.15.1
66

77
default: build
88

cmd/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ func ssh(args []string, config *dao.Config, runFlags *core.RunFlags) {
5252
}
5353
core.CheckIfError(err)
5454

55-
err = run.SSHToServer(*server, config.DisableVerifyHost, config.KnownHostsFile)
55+
err = run.SSHToServer(servers[0], config.DisableVerifyHost, config.KnownHostsFile)
5656
core.CheckIfError(err)
5757
}

core/run/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ type ErrConnect struct {
3131
}
3232

3333
func (e *ErrConnect) Error() string {
34-
return ""
34+
return e.Reason
3535
}

core/run/exec.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,48 @@ func ParseServers(
612612

613613
// IdentityFile
614614
if len(serv.IdentityFiles) > 0 {
615-
(*servers)[i].IdentityFile = &serv.IdentityFiles[0]
615+
iFile, err := core.ExpandPath(serv.IdentityFiles[0])
616+
if err != nil {
617+
errConnect := &ErrConnect{
618+
Name: (*servers)[i].Name,
619+
User: (*servers)[i].User,
620+
Host: (*servers)[i].Host,
621+
Port: (*servers)[i].Port,
622+
Reason: err.Error(),
623+
}
624+
errConnects = append(errConnects, *errConnect)
625+
continue
626+
}
627+
628+
(*servers)[i].IdentityFile = &iFile
629+
630+
// TODO: Update PubFile as well
631+
if _, err := os.Stat(*(*servers)[i].IdentityFile); errors.Is(err, os.ErrNotExist) {
632+
errConnect := &ErrConnect{
633+
Name: (*servers)[i].Name,
634+
User: (*servers)[i].User,
635+
Host: (*servers)[i].Host,
636+
Port: (*servers)[i].Port,
637+
Reason: err.Error(),
638+
}
639+
errConnects = append(errConnects, *errConnect)
640+
continue
641+
}
642+
643+
pubFile := *(*servers)[i].IdentityFile + ".pub"
644+
if _, err := os.Stat(pubFile); errors.Is(err, os.ErrNotExist) {
645+
errConnect := &ErrConnect{
646+
Name: (*servers)[i].Name,
647+
User: (*servers)[i].User,
648+
Host: (*servers)[i].Host,
649+
Port: (*servers)[i].Port,
650+
Reason: err.Error(),
651+
}
652+
errConnects = append(errConnects, *errConnect)
653+
continue
654+
} else {
655+
*(*servers)[i].PubFile = pubFile
656+
}
616657
}
617658

618659
// HostName

core/sake.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH "SAKE" "1" "2023-06-10T21:39:07CEST" "v0.14.0" "Sake Manual" "sake"
1+
.TH "SAKE" "1" "2023-09-25T11:47:19CEST" "v0.15.1" "Sake Manual" "sake"
22
.SH NAME
33
sake - sake is a task runner for local and remote hosts
44

core/ssh_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/kevinburke/ssh_config"
1515
)
1616

17-
// PraseFile reads and parses the file in the given path.
17+
// Parse reads and parses the file in the given path.
1818
func ParseSSHConfig(path string) (map[string](Endpoint), error) {
1919
f, err := os.Open(path)
2020
if err != nil {
@@ -243,7 +243,7 @@ func parseInternal(r io.Reader, cfg string) (*hostinfoMap, error) {
243243
continue
244244
}
245245

246-
path, err := expandPath(value)
246+
path, err := ExpandPath(value)
247247
if err != nil {
248248
return nil, err
249249
}
@@ -340,7 +340,7 @@ func parseFileInternal(path string) (*hostinfoMap, error) {
340340
return parseInternal(f, path)
341341
}
342342

343-
func expandPath(p string) (string, error) {
343+
func ExpandPath(p string) (string, error) {
344344
if !strings.HasPrefix(p, "~/") {
345345
return p, nil
346346
}

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.15.1
4+
5+
### Fixes
6+
7+
- Fix resolving identity file in ssh config correctly when ~ is used.
8+
- Fix public file not found when using ssh config
9+
310
## 0.15.0
411

512
### Features

0 commit comments

Comments
 (0)