Skip host and deploy keys in another level
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 12:01:34 +02:00
parent 16bb4e71d5
commit 5b0a46951b
Signed by: cx
GPG Key ID: 018304FFA8988F8D
2 changed files with 13 additions and 29 deletions

View File

@ -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. // 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. // The container has to run for this to work.
func (c *Container) GenerateDeploySSHKeys() (bool, error) { 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() driver := c.getDriver()
privateKey, pubKey, _ := c.GetDeploySSHKeys() privateKey, pubKey, _ := c.GetDeploySSHKeys()
@ -253,7 +245,7 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) {
return false, nil 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 { if err != nil {
return false, err return false, err
} }
@ -275,14 +267,6 @@ func (c *Container) GenerateDeploySSHKeys() (bool, error) {
// Return private key, public key and error. // Return private key, public key and error.
// The container has to run for this to work. // The container has to run for this to work.
func (c *Container) GetDeploySSHKeys() (string, string, error) { 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() driver := c.getDriver()
privateKey, err := driver.Exec(c.App.Name, []string{"cat", "/srv/.ssh/" + deployKeyPrefix + "_id_" + deployKeyType}, "", []string{}, true) 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 // Return host key without hostname
// The container has to run for this to work. // The container has to run for this to work.
func (c *Container) GetHostKey() (string, error) { func (c *Container) GetHostKey() (string, error) {
status, err := c.Status()
if err != nil {
return "", err
}
if status.Status != "running" {
return "", nil
}
driver := c.getDriver() driver := c.getDriver()
hostKeyRaw, err := driver.Exec(c.App.Name, []string{"ssh-keyscan", "localhost"}, "", []string{}, true) hostKeyRaw, err := driver.Exec(c.App.Name, []string{"ssh-keyscan", "localhost"}, "", []string{}, true)

View File

@ -489,15 +489,19 @@ func (p *Processor) SetPassword(password string) error {
// Returns private key, pubkey and error. // Returns private key, pubkey and error.
// Keys are returned every time even if it was already generated // Keys are returned every time even if it was already generated
func (p *Processor) GenerateDeploySSHKeys() (string, string, error) { func (p *Processor) GenerateDeploySSHKeys() (string, string, error) {
err := p.waitForApp() container, err := p.getContainer()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
container, err := p.getContainer() // If the container is not running we skip this code
status, err := container.Status()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
if status.Status != "running" {
return "", "", nil
}
created, err := container.GenerateDeploySSHKeys() created, err := container.GenerateDeploySSHKeys()
if err != nil { 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) // Return SSH host key without hostname (first part of the line)
func (p *Processor) GetHostKey() (string, error) { func (p *Processor) GetHostKey() (string, error) {
err := p.waitForApp() container, err := p.getContainer()
if err != nil { if err != nil {
return "", err return "", err
} }
container, err := p.getContainer() // If the container is not running we skip this code
status, err := container.Status()
if err != nil { if err != nil {
return "", err return "", err
} }
if status.Status != "running" {
return "", nil
}
hostKey, err := container.GetHostKey() hostKey, err := container.GetHostKey()
if err != nil { if err != nil {