Return empty strings for host and ssh keys if container is down
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
Adam Štrauch 2023-04-21 11:13:02 +02:00
parent 8c8ecc6379
commit 16bb4e71d5
Signed by: cx
GPG key ID: 018304FFA8988F8D

View file

@ -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)