From 80513106772e29df49ecfcefaaeb9774c47e7a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Tue, 11 Apr 2023 22:56:15 +0200 Subject: [PATCH] Get SSH host keys message handler --- containers/types.go | 20 ++++++++++++++++++++ glue/main.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/containers/types.go b/containers/types.go index 372a01b..0838c87 100644 --- a/containers/types.go +++ b/containers/types.go @@ -280,6 +280,26 @@ func (c *Container) GetDeploySSHKeys() (string, string, error) { return "", "", nil } +// Return host key without hostname +func (c *Container) GetHostKey() (string, error) { + driver := c.getDriver() + + hostKeyRaw, err := driver.Exec(c.App.Name, []string{"ssh-keyscan ", "localhost"}, "", []string{}, true) + if err != nil { + return "", err + } + + if hostKeyRaw != nil { + parts := strings.SplitN(string(*hostKeyRaw), " ", 1) + if len(parts) > 1 { + return parts[1], nil + } + } + + return "", nil +} + +// Append text to a file in the container func (c *Container) AppendOfFile(filename string, text string, mode string) error { driver := c.getDriver() diff --git a/glue/main.go b/glue/main.go index 944864a..c76cde7 100644 --- a/glue/main.go +++ b/glue/main.go @@ -519,6 +519,26 @@ func (p *Processor) GenerateDeploySSHKeys() (string, string, error) { return privateKey, pubKey, nil } +// Return SSH host key without hostname (first part of the line) +func (p *Processor) GetHostKey() (string, error) { + err := p.waitForApp() + if err != nil { + return "", err + } + + container, err := p.getContainer() + if err != nil { + return "", err + } + + hostKey, err := container.GetHostKey() + if err != nil { + return "", err + } + + return hostKey, nil +} + // Processes returns list of supervisord processes func (p *Processor) Processes() ([]docker.Process, error) { container, err := p.getContainer()