-
-
Notifications
You must be signed in to change notification settings - Fork 404
Closed
Description
Originally I'm trying to do a git fetch, but the git-clone-ssh recipe has the same issue. I'm using a modified version of the recipe to make it a real world example:
- using a path to real SSH keys on my system and assert to proof they exist
- using the
"git@github.com:libgit2/pygit2.git"
url that GitHub suggests for ssh cloning
#! /usr/bin/env python3
import pygit2
import os
class MyRemoteCallbacks(pygit2.RemoteCallbacks):
def credentials(self, url, username_from_url, allowed_types):
if allowed_types & pygit2.credentials.GIT_CREDENTIAL_USERNAME:
return pygit2.Username("git")
elif allowed_types & pygit2.credentials.GIT_CREDENTIAL_SSH_KEY:
sshkeys = os.path.join(os.getenv("HOME"), '.ssh')
pubkey = os.path.join(sshkeys, 'id_rsa.pub')
privkey = os.path.join(sshkeys, 'id_rsa')
assert os.path.isfile(pubkey), f'isfile({pubkey})'
assert os.path.isfile(privkey), f'isfile({pubkey})'
return pygit2.Keypair("git", pubkey, privkey, "")
else:
return None
print("Cloning pygit2 over ssh")
pygit2.clone_repository("git@github.com:libgit2/pygit2.git", "pygit2.git",
callbacks=MyRemoteCallbacks())
After a while (and multiple calls to the callback method) the script fails:
(venv) $ ./gitclone.py
Cloning pygit2 over ssh
Traceback (most recent call last):
File "./gitclone.py", line 21, in <module>
pygit2.clone_repository("git@github.com:libgit2/pygit2.git", "pygit2.git",
File "/home/username/path/to/example/gftools/venv/lib64/python3.8/site-packages/pygit2/__init__.py", line 214, in clone_repository
payload.check_error(err)
File "/home/username/path/to/example/gftools/venv/lib64/python3.8/site-packages/pygit2/callbacks.py", line 93, in check_error
check_error(error_code)
File "/home/username/path/to/example/gftools/venv/lib64/python3.8/site-packages/pygit2/errors.py", line 65, in check_error
raise GitError(message)
_pygit2.GitError: Failed to retrieve list of SSH authentication methods: Failed getting response
If i use the underdocumented pygit2.KeypairFromAgent
Keypair Constructor the script works without problems:
#! /usr/bin/env python3
import pygit2
import os
class MyRemoteCallbacks(pygit2.RemoteCallbacks):
def credentials(self, url, username_from_url, allowed_types):
if allowed_types & pygit2.credentials.GIT_CREDENTIAL_USERNAME:
return pygit2.Username("git")
elif allowed_types & pygit2.credentials.GIT_CREDENTIAL_SSH_KEY:
return pygit2.KeypairFromAgent("git")
else:
return None
print("Cloning pygit2 over ssh")
pygit2.clone_repository("git@github.com:libgit2/pygit2.git", "pygit2.git",
callbacks=MyRemoteCallbacks())
Here's the result:
(venv) $ ./gitclone.py
Cloning pygit2 over ssh
(venv) $ ls pygit2.git/
appveyor.yml AUTHORS.rst CHANGELOG.rst COPYING docs Makefile misc pygit2 pyproject.toml pytest.ini README.rst setup.cfg setup.py SPONSORS.rst src test travis
expected:
- The
return pygit2.Keypair("git", pubkey, privkey, "")
version should be fixed or the documentation should show how to use it correctly in real live. pygit2.KeypairFromAgent("git")
should also be an example in the git-clone-recipe. It is actually really what I'm going to use and what is the best fit for my needs, but because of the issue and the example in the git-clone-recipe I was side tracked a considerable amount of time.
Here's a related issue: saltstack/salt#57121
(I'm also interested in leaving a trace of my findings in the web, so that others can solve their issues faster, hence this is very verbose.)
wtrevena, vincentxed, jwheeler31, tameremad and paulinevos
Metadata
Metadata
Assignees
Labels
No labels