fixing ssh connection
This commit is contained in:
@@ -32,19 +32,35 @@ func (s *gitService) CheckConnection(url string) error {
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to check git connection: %w", err)
|
||||
}
|
||||
fmt.Println("Git connection checked successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *gitService) FetchContents(url string) error {
|
||||
// Remove the repo directory if it already exists from a previous run
|
||||
fmt.Println("Removing repo directory")
|
||||
_ = os.RemoveAll(s.repoDir)
|
||||
|
||||
cmd := exec.Command("git", "clone", url, s.repoDir)
|
||||
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)
|
||||
} else {
|
||||
cmd = exec.Command("git", "clone", url, s.repoDir)
|
||||
}
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to fetch contents: %w, stderr: %s", err, stderr.String())
|
||||
}
|
||||
fmt.Println("Repository cloned successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user