agaainnn
This commit is contained in:
@@ -27,15 +27,33 @@ func NewGitService() Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldUseSSH() bool {
|
func prepareSSHKey() (string, bool) {
|
||||||
_, err := os.Stat("/root/.ssh/id_rsa")
|
b, err := os.ReadFile("/root/.ssh/id_rsa")
|
||||||
return err == nil
|
if err != nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix literal escaped newlines and CRLF issues that cause libcrypto errors
|
||||||
|
content := strings.ReplaceAll(string(b), "\\n", "\n")
|
||||||
|
content = strings.ReplaceAll(content, "\r", "")
|
||||||
|
|
||||||
|
// Ensure there is a trailing newline
|
||||||
|
if !strings.HasSuffix(content, "\n") {
|
||||||
|
content += "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpPath := "/tmp/id_rsa"
|
||||||
|
if err := os.WriteFile(tmpPath, []byte(content), 0600); err != nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmpPath, true
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
if keyPath, ok := prepareSSHKey(); ok {
|
||||||
cmd.Env = append(os.Environ(), "GIT_SSH_COMMAND=ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no")
|
cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s -o StrictHostKeyChecking=no", keyPath))
|
||||||
}
|
}
|
||||||
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)
|
||||||
@@ -52,9 +70,9 @@ func (s *gitService) FetchContents(url string) error {
|
|||||||
fmt.Println("Cloning repository")
|
fmt.Println("Cloning repository")
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if shouldUseSSH() {
|
if keyPath, ok := prepareSSHKey(); ok {
|
||||||
cmd = exec.Command("git", "clone", 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")
|
cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s -o StrictHostKeyChecking=no", keyPath))
|
||||||
} 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