diff --git a/containers/types.go b/containers/types.go index e9159be..676ec96 100644 --- a/containers/types.go +++ b/containers/types.go @@ -236,7 +236,16 @@ func (c *Container) SetPassword(password string) error { // Generate SSH keys and copies it into authorized keys // Returns true if the key was generated in this call and error if there is any. +// The container has to run for this to work. func (c *Container) GenerateDeploySSHKeys() (bool, error) { + status, err := c.Status() + if err != nil { + return false, err + } + if status.Status != "running" { + return false, nil + } + driver := c.getDriver() privateKey, pubKey, _ := c.GetDeploySSHKeys() @@ -244,7 +253,7 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) { return false, nil } - _, err := driver.Exec(c.App.Name, []string{"mkdir", "-p", "/srv/.ssh"}, "", []string{}, true) + _, err = driver.Exec(c.App.Name, []string{"mkdir", "-p", "/srv/.ssh"}, "", []string{}, true) if err != nil { return false, err } @@ -264,7 +273,16 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) { // Generate SSH keys and copies it into authorized keys // Return private key, public key and error. +// The container has to run for this to work. func (c *Container) GetDeploySSHKeys() (string, string, error) { + status, err := c.Status() + if err != nil { + return "", "", err + } + if status.Status != "running" { + return "", "", nil + } + driver := c.getDriver() privateKey, err := driver.Exec(c.App.Name, []string{"cat", "/srv/.ssh/" + deployKeyPrefix + "_id_" + deployKeyType}, "", []string{}, true) @@ -284,7 +302,16 @@ func (c *Container) GetDeploySSHKeys() (string, string, error) { } // Return host key without hostname +// The container has to run for this to work. func (c *Container) GetHostKey() (string, error) { + status, err := c.Status() + if err != nil { + return "", err + } + if status.Status != "running" { + return "", nil + } + driver := c.getDriver() hostKeyRaw, err := driver.Exec(c.App.Name, []string{"ssh-keyscan", "localhost"}, "", []string{}, true)