Description
NOTE: The accepted proposal is #26232 (comment).
Problem
The custom import path mechanism (?go-get=1
and meta tag) works for public URLs, but it doesn't work for auth required URLs. This is because when go-get fetches the URL with ?go-get=1
, it uses net/http.DefaultClient, and it doesn't know the credentials it needs to access the URL. A user cannot run go get
against private source code hosting service because of this.
Goal
Make go get git.mycompany.com/private-repo
work, where https://git.mycompany.com/private-repo requires authentication.
Idea 1 (credential helper)
Introduce a credential helper mechanism like git-credential-helpers. A user specifies a path to a binary via GOGET_CREDENTIAL_HELPER
and go get
executes that with the import path as an argument. The credential helper binary returns HTTP headers (like "Authorization: Basic blah\n", and go get
adds these headers when it tries to fetch go-get=1
URLs.
- PRO: Straightforward solution to the problem description.
- CON: Supporting multiple credential helpers becomes complicated. Git's credential helper mechanism supports multiple credential helper, and Git runs each in order. This sometimes makes an unexpected behavior that is hard to debug.
Idea 2 (go-get helper)
Introduce a custom source code fetching mechanism. When go get
needs to fetch the source code for the import path git.mycompany.com/private-repo
, it looks for the binary go-get-git.mycompany.com
based on the host name of the import path. When such binary exists in $PATH, it executes that binary with the import path and a destination in $GOPATH (for example, go-get-git.mycompany.com git.mycompany.com/private-repo $GOPATH/src/git.mycompany.com/private-repo
). The binary is responsible for fetching the source code to the specified $GOPATH location.
- PRO: As a side effect, this make
go get
work with VCSs other than git/hg/svn/bzr. - CON: I'm not sure how this works with
go get -f
orgo get -insecure
.
Activity