maj*_*aja 4 git authentication go gitea go-git
我使用 go 项目go-git作为 git 客户端,并希望从通过gitea托管的私有 git 存储库中获取数据。
执行此操作的适当函数是func (r *Remote) Fetch(o *FetchOptions) error,它需要一个transport.AuthMethod对象进行身份验证。
我尝试了以下方法:
repo, _ := git.PlainOpen("/path/to/project/folder")
err := repo.Fetch(&git.FetchOptions{
Auth: http.NewBasicAuth("someUser", "andThePassword"),
})
Run Code Online (Sandbox Code Playgroud)
...它只是返回:
无效的身份验证方法
如果我使用也会发生同样的情况
authenticator, _ := ssh.NewSSHAgentAuth("git")
Run Code Online (Sandbox Code Playgroud)
从包装中"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"。
另外,如果我使用证书:
authenticator, _:= ssh.NewPublicKeysFromFile("gitea name", "/home/name/.ssh/id_rsa", "passphrase")
Run Code Online (Sandbox Code Playgroud)
如何找出支持哪种身份验证方法,以及是否有transport.AuthMethod我可以使用的现有实现?
这里的问题是,我使用了错误的 http 包来获取身份验证器。
我使用了BasicAuth()包中的net/http- 但是,正确使用的 http 包是gopkg.in/src-d/go-git.v4/plumbing/transport/http。
当更改导入并从那里使用(兼容的)BasicAuth-authenticator 时,它可以完美地工作。
| 归档时间: |
|
| 查看次数: |
9067 次 |
| 最近记录: |