From 5b0a46951b26fdf0b63c8450b71460ca30c69b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Fri, 21 Apr 2023 12:01:34 +0200 Subject: [PATCH] Skip host and deploy keys in another level --- containers/types.go | 26 +------------------------- glue/main.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/containers/types.go b/containers/types.go index 676ec96..c7f1ce3 100644 --- a/containers/types.go +++ b/containers/types.go @@ -238,14 +238,6 @@ func (c *Container) SetPassword(password string) error { // 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() @@ -253,7 +245,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 } @@ -275,14 +267,6 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) { // 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) @@ -304,14 +288,6 @@ 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) diff --git a/glue/main.go b/glue/main.go index b850cd2..d0ecb36 100644 --- a/glue/main.go +++ b/glue/main.go @@ -489,15 +489,19 @@ func (p *Processor) SetPassword(password string) error { // Returns private key, pubkey and error. // Keys are returned every time even if it was already generated func (p *Processor) GenerateDeploySSHKeys() (string, string, error) { - err := p.waitForApp() + container, err := p.getContainer() if err != nil { return "", "", err } - container, err := p.getContainer() + // If the container is not running we skip this code + status, err := container.Status() if err != nil { return "", "", err } + if status.Status != "running" { + return "", "", nil + } created, err := container.GenerateDeploySSHKeys() if err != nil { @@ -521,15 +525,19 @@ func (p *Processor) GenerateDeploySSHKeys() (string, string, error) { // Return SSH host key without hostname (first part of the line) func (p *Processor) GetHostKey() (string, error) { - err := p.waitForApp() + container, err := p.getContainer() if err != nil { return "", err } - container, err := p.getContainer() + // If the container is not running we skip this code + status, err := container.Status() if err != nil { return "", err } + if status.Status != "running" { + return "", nil + } hostKey, err := container.GetHostKey() if err != nil {