fixing ssh again :)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user