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 {
|
func (s *gitService) CheckConnection(url string) error {
|
||||||
cmd := exec.Command("git", "ls-remote", url)
|
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 {
|
if err := cmd.Run(); err != nil {
|
||||||
return fmt.Errorf("failed to check git connection: %w", err)
|
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")
|
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
|
var cmd *exec.Cmd
|
||||||
if useSSH {
|
if shouldUseSSH() {
|
||||||
cmd = exec.Command("git", "clone", "-i", "/root/.ssh/id_rsa", url, s.repoDir)
|
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 {
|
} else {
|
||||||
cmd = exec.Command("git", "clone", url, s.repoDir)
|
cmd = exec.Command("git", "clone", url, s.repoDir)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user