Skip to content

Commit 46002f4

Browse files
feat(cmd): Support Base64 encoded SSH_KEY
This adds a check to see if the value of SSH_KEY is already a Base64 encoded value, which is the case if "deis config:push" is used after using "deis config:pull" on an app that already has SSH_KEY set. This fixes #274.
1 parent 2dddbe1 commit 46002f4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

cmd/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (d *DeisCmd) ConfigSet(appID string, configVars []string) error {
8080

8181
if ok {
8282
sshKey := value.(string)
83+
sshRegex := regexp.MustCompile("^-.+ .SA PRIVATE KEY-*")
8384

8485
if _, err = os.Stat(value.(string)); err == nil {
8586
contents, err := ioutil.ReadFile(value.(string))
@@ -89,9 +90,15 @@ func (d *DeisCmd) ConfigSet(appID string, configVars []string) error {
8990
}
9091

9192
sshKey = string(contents)
92-
}
93+
} else {
94+
// NOTE(felixbuenemann): check if the current value is already a base64 encoded key.
95+
// This is the case if it was fetched using "deis config:pull".
96+
contents, err := base64.StdEncoding.DecodeString(sshKey)
9397

94-
sshRegex := regexp.MustCompile("^-.+ .SA PRIVATE KEY-*")
98+
if err == nil && sshRegex.MatchString(string(contents)) {
99+
sshKey = string(contents)
100+
}
101+
}
95102

96103
if !sshRegex.MatchString(sshKey) {
97104
return fmt.Errorf("Could not parse SSH private key:\n %s", sshKey)

0 commit comments

Comments
 (0)