Fix obtaining host key
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/promote/production Build is passing Details

This commit is contained in:
Adam Štrauch 2023-04-19 23:40:55 +02:00
parent d465421fa0
commit 8c8ecc6379
Signed by: cx
GPG Key ID: 018304FFA8988F8D
1 changed files with 16 additions and 4 deletions

View File

@ -292,14 +292,26 @@ func (c *Container) GetHostKey() (string, error) {
return "", err return "", err
} }
// Loop over lines and search for localhost ssh
line := ""
if hostKeyRaw != nil { if hostKeyRaw != nil {
hostKeyRawString := strings.TrimSpace(string(*hostKeyRaw)) for _, line = range strings.Split(string(*hostKeyRaw), "\n") {
parts := strings.SplitN(hostKeyRawString, " ", 2) if strings.HasPrefix(line, "localhost ssh") {
if len(parts) > 1 { line = strings.TrimSpace(line)
return parts[1], nil break
}
} }
} }
if line == "" {
return "", errors.New("key not found")
}
parts := strings.SplitN(line, " ", 2)
if len(parts) > 1 {
return parts[1], nil
}
return "", errors.New("key not found") return "", errors.New("key not found")
} }