Skip to content

Commit

Permalink
Fix hardcoded 'git' user in util/git.NewClient (#1556)
Browse files Browse the repository at this point in the history
Closes #1555
  • Loading branch information
pbrit authored and Alexander Matyushentsev committed May 2, 2019
1 parent f268f82 commit d06303c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func pathExists(ss ...string) bool {
func (s *Service) newClientResolveRevision(repo *v1alpha1.Repository, revision string) (git.Client, string, error) {
repoURL := git.NormalizeGitURL(repo.Repo)
appRepoPath := tempRepoPath(repoURL)
gitClient, err := s.gitFactory.NewClient(repoURL, appRepoPath, repo.Username, repo.Password, repo.SSHPrivateKey, repo.InsecureIgnoreHostKey)
gitClient, err := s.gitFactory.NewClient(repo.Repo, appRepoPath, repo.Username, repo.Password, repo.SSHPrivateKey, repo.InsecureIgnoreHostKey)
if err != nil {
return nil, "", err
}
Expand Down
15 changes: 12 additions & 3 deletions util/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package git

import (
"fmt"
"net/url"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -47,17 +48,25 @@ func NewFactory() ClientFactory {
return &factory{}
}

func (f *factory) NewClient(repoURL, path, username, password, sshPrivateKey string, insecureIgnoreHostKey bool) (Client, error) {
func (f *factory) NewClient(rawRepoURL, path, username, password, sshPrivateKey string, insecureIgnoreHostKey bool) (Client, error) {
var repoUser string

if repoURL, err := url.Parse(rawRepoURL); err != nil {
return nil, err
} else {
repoUser = repoURL.User.Username()
}

clnt := nativeGitClient{
repoURL: repoURL,
repoURL: rawRepoURL,
root: path,
}
if sshPrivateKey != "" {
signer, err := ssh.ParsePrivateKey([]byte(sshPrivateKey))
if err != nil {
return nil, err
}
auth := &ssh2.PublicKeys{User: "git", Signer: signer}
auth := &ssh2.PublicKeys{User: repoUser, Signer: signer}
if insecureIgnoreHostKey {
auth.HostKeyCallback = ssh.InsecureIgnoreHostKey()
}
Expand Down

0 comments on commit d06303c

Please sign in to comment.