func()

in fast-build-update-tool/internal/tools/file_uploader.go [88:108]


func (f *FileUploader) generateKnownHostsFile(ctx context.Context, remotePublicKey ssh.PublicKey) (string, error) {
	khFile, err := os.CreateTemp("", "known_hosts")
	if err != nil {
		return "", err
	}

	defer func() {
		if err = khFile.Close(); err != nil {
			f.logger.Warn("error closing known hosts file", "error", err)
		}
	}()

	hostPort := net.JoinHostPort(f.remoteIpAddress, fmt.Sprintf("%d", f.sshPort))
	line := knownhosts.Line([]string{hostPort}, remotePublicKey)
	_, err = khFile.Write([]byte(line))
	if err != nil {
		return "", err
	}

	return khFile.Name(), err
}