Skip to content

Commit 8867526

Browse files
committed
Update git auth key check
1 parent ba6b9f4 commit 8867526

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/server/app_apis.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,28 +713,42 @@ type gitAuthEntry struct {
713713
user string
714714
key []byte
715715
password string
716+
usingSSH bool
716717
}
717718

718719
// loadGitKey gets the git key from the config and loads the key from disk
719720
func (s *Server) loadGitKey(gitAuth string) (*gitAuthEntry, error) {
721+
if gitAuth == "" {
722+
return &gitAuthEntry{
723+
user: "",
724+
key: []byte{},
725+
password: "",
726+
usingSSH: false, // default to non-SSH git url if no auth is specified
727+
}, nil
728+
}
720729
authEntry, ok := s.config.GitAuth[gitAuth]
721730
if !ok {
722731
return nil, fmt.Errorf("git auth entry %s not found in server config", gitAuth)
723732
}
724733

725734
var err error
726735
gitKey := []byte{}
736+
user := authEntry.UserID
737+
usingSSH := false
727738
if authEntry.KeyFilePath != "" {
728739
gitKey, err = os.ReadFile(authEntry.KeyFilePath)
729740
if err != nil {
730741
return nil, fmt.Errorf("error reading git key %s: %w", authEntry.KeyFilePath, err)
731742
}
743+
user = cmp.Or(authEntry.UserID, "git") // https://github.com/src-d/go-git/issues/637, default user to "git"
744+
usingSSH = true
732745
}
733746

734747
return &gitAuthEntry{
735-
user: cmp.Or(authEntry.UserID, "git"), // https://github.com/src-d/go-git/issues/637, default user to "git"
748+
user: user,
736749
key: gitKey,
737750
password: authEntry.Password,
751+
usingSSH: usingSSH,
738752
}, nil
739753
}
740754

internal/server/repo_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *RepoCache) GetSha(sourceUrl, branch, gitAuth string) (string, error) {
5858
}
5959

6060
// Figure on which repo to clone
61-
repo, _, err := parseGithubUrl(sourceUrl, len(authEntry.key) != 0)
61+
repo, _, err := parseGithubUrl(sourceUrl, authEntry.usingSSH)
6262
if err != nil {
6363
return "", err
6464
}
@@ -132,7 +132,7 @@ func (r *RepoCache) CheckoutRepo(sourceUrl, branch, commit, gitAuth string) (str
132132
}
133133

134134
// Figure on which repo to clone
135-
repo, folder, err := parseGithubUrl(sourceUrl, len(authEntry.key) != 0)
135+
repo, folder, err := parseGithubUrl(sourceUrl, authEntry.usingSSH)
136136
if err != nil {
137137
return "", "", "", "", err
138138
}

0 commit comments

Comments
 (0)