Return empty strings for host and ssh keys if container is down
This commit is contained in:
parent
8c8ecc6379
commit
16bb4e71d5
1 changed files with 28 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue