From 07cacfeb2920f8d69517be65bf9a396cec3b91b9 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Sat, 14 Mar 2026 11:59:33 -0300 Subject: [PATCH] fixing ssh again :) --- mindforge.cronjob/internal/git/git.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mindforge.cronjob/internal/git/git.go b/mindforge.cronjob/internal/git/git.go index 0220615..5ca68dc 100644 --- a/mindforge.cronjob/internal/git/git.go +++ b/mindforge.cronjob/internal/git/git.go @@ -27,8 +27,16 @@ func NewGitService() Service { } } +func shouldUseSSH() bool { + _, err := os.Stat("/root/.ssh/id_rsa") + return err == nil +} + func (s *gitService) CheckConnection(url string) error { cmd := exec.Command("git", "ls-remote", url) + if shouldUseSSH() { + cmd.Env = append(os.Environ(), "GIT_SSH_COMMAND=ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no") + } if err := cmd.Run(); err != nil { return fmt.Errorf("failed to check git connection: %w", err) } @@ -43,15 +51,10 @@ func (s *gitService) FetchContents(url string) error { fmt.Println("Cloning repository") - // check for existing /root/.ssh/id_rsa key - useSSH := false - if _, err := os.Stat("/root/.ssh/id_rsa"); err == nil { - useSSH = true - } - var cmd *exec.Cmd - if useSSH { - cmd = exec.Command("git", "clone", "-i", "/root/.ssh/id_rsa", url, s.repoDir) + if shouldUseSSH() { + cmd = exec.Command("git", "clone", url, s.repoDir) + cmd.Env = append(os.Environ(), "GIT_SSH_COMMAND=ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no") } else { cmd = exec.Command("git", "clone", url, s.repoDir) }