Skip to content

Commit f5a8ffb

Browse files
committed
fix(deisctl): properly resolve ~ in path
While `$HOME` is resolved properly in paths, `~` is not and requires special handling. I tested this with the following, on both bash and zsh: ```console $ deisctl config platform set sshPrivateKey=$HOME/.ssh/deis $ deisctl config platform set sshPrivateKey=~/.ssh/deis $ deisctl config platform set sshPrivateKey=/Users/carmstrong/.ssh/deis $ DEISCTL_UNITS=/Users/carmstrong/gocode/src/github.com/deis/deis/deisctl/units deisctl refresh-units $ DEISCTL_UNITS=$HOME/gocode/src/github.com/deis/deis/deisctl/units deisctl refresh-units $ DEISCTL_UNITS=~/gocode/src/github.com/deis/deis/deisctl/units deisctl refresh-units ``` fixes #2677
1 parent b4fd8e3 commit f5a8ffb

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

deisctl/cmd/cmd.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io/ioutil"
77
"net/http"
88
"os"
9-
"path"
109
"path/filepath"
1110
"regexp"
1211
"strconv"
@@ -631,9 +630,7 @@ Options:
631630
os.Exit(2)
632631
}
633632
dir := args["--path"].(string)
634-
if dir == "$HOME/.deis/units" || dir == "~/.deis/units" {
635-
dir = path.Join(os.Getenv("HOME"), ".deis", "units")
636-
}
633+
dir = utils.ResolvePath(dir)
637634
// create the target dir if necessary
638635
if err := os.MkdirAll(dir, 0755); err != nil {
639636
return err

deisctl/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"io/ioutil"
77
"strings"
8+
9+
"github.com/deis/deis/deisctl/utils"
810
)
911

1012
// Config runs the config subcommand
@@ -72,7 +74,7 @@ func doConfigSet(client *etcdClient, root string, kvs []string) ([]string, error
7274

7375
// special handling for sshKey
7476
if path == "/deis/platform/sshPrivateKey" {
75-
b64, err := readSSHPrivateKey(v)
77+
b64, err := readSSHPrivateKey(utils.ResolvePath(v))
7678
if err != nil {
7779
return result, err
7880
}

deisctl/utils/utils.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
package utils
44

5-
import "fmt"
5+
import (
6+
"fmt"
7+
"os"
8+
"strings"
9+
)
610

711
// DeisIfy returns a pretty-printed deis logo along with the corresponding message
812
func DeisIfy(message string) string {
@@ -17,3 +21,11 @@ func DeisIfy(message string) string {
1721
square, circle, triangle, title,
1822
triangle, square, circle, reset)
1923
}
24+
25+
// ResolvePath returns the path with a tilde (~) and $HOME replaced by the actual home directory
26+
func ResolvePath(path string) string {
27+
path = strings.Replace(path, "~", os.Getenv("HOME"), -1)
28+
// Using $HOME seems to work just fine with `deisctl config`, but not `deisctl refresh-units`
29+
path = strings.Replace(path, "$HOME", os.Getenv("HOME"), -1)
30+
return path
31+
}

0 commit comments

Comments
 (0)