I am looking for a way to clone a private git repository.
My restrictions:
- use http
- use "Authorization" header (Basic/Bearer)
Using the "PlainClone" function where the credentials are contained inside the url (http://username:password@mygitrepo.com) does not work (forbidden by the server).
Source of my problem is some code in portainer:
// ClonePrivateRepositoryWithBasicAuth clones a private git repository using the specified URL in the specified
// destination folder. It will use the specified username and password for basic HTTP authentication.
func (service *Service) ClonePrivateRepositoryWithBasicAuth(repositoryURL, destination, username, password string) error {
credentials := username + ":" + url.PathEscape(password)
repositoryURL = strings.Replace(repositoryURL, "://", "://"+credentials+"@", 1)
return cloneRepository(repositoryURL, destination)
}
func cloneRepository(repositoryURL, destination string) error {
_, err := git.PlainClone(destination, false, &git.CloneOptions{
URL: repositoryURL,
})
return err
}
As far as I understood it is possible to add some "clone configuration" (CloneOptions) containing the method (Auth transport.AuthMethod). But that is all I know - and that just in theory... :-|
Any idea? I am really brand new to go :-)