Merge pull request #424 from kyriakosoikonomakos/ssh-agent

authenticate using ssh agent
This commit is contained in:
Carlos Martín Nieto
2014-10-10 11:44:05 +02:00
4 changed files with 23 additions and 3 deletions

View File

@@ -85,3 +85,8 @@ class Keypair(object):
def __call__(self, _url, _username, _allowed):
return self
class KeypairFromAgent(Keypair):
def __init__(self, username):
super(KeypairFromAgent, self).__init__(username, None, None, None)

View File

@@ -204,6 +204,9 @@ int git_cred_ssh_key_new(
const char *publickey,
const char *privatekey,
const char *passphrase);
int git_cred_ssh_key_from_agent(
git_cred **out,
const char *username);
/*
* git_diff

View File

@@ -32,6 +32,7 @@ from __future__ import absolute_import
from _pygit2 import Oid
from .errors import check_error, GitError
from .ffi import ffi, C
from .credentials import KeypairFromAgent
from .refspec import Refspec
from .utils import to_bytes, strarray_to_strings, strings_to_strarray
@@ -456,9 +457,12 @@ def get_credentials(fn, url, username, allowed):
elif cred_type == C.GIT_CREDTYPE_SSH_KEY:
name, pubkey, privkey, passphrase = creds.credential_tuple
err = C.git_cred_ssh_key_new(ccred, to_bytes(name), to_bytes(pubkey),
to_bytes(privkey), to_bytes(passphrase))
if pubkey is None and privkey is None:
err = C.git_cred_ssh_key_from_agent(ccred, to_bytes(name))
else:
err = C.git_cred_ssh_key_new(ccred, to_bytes(name),
to_bytes(pubkey), to_bytes(privkey),
to_bytes(passphrase))
else:
raise TypeError("unsupported credential type")

View File

@@ -31,6 +31,7 @@
import unittest
import pygit2
from pygit2 import GIT_CREDTYPE_USERPASS_PLAINTEXT
from pygit2 import UserPass, Keypair, KeypairFromAgent
from pygit2 import UserPass, Keypair
from . import utils
@@ -60,6 +61,13 @@ class CredentialCreateTest(utils.NoRepoTestCase):
cred = Keypair(username, pubkey, privkey, passphrase)
self.assertEqual((username, pubkey, privkey, passphrase), cred.credential_tuple)
def test_ssh_agent(self):
username = "git"
cred = KeypairFromAgent(username)
self.assertEqual((username, None, None, None), cred.credential_tuple)
class CredentialCallback(utils.RepoTestCase):
def test_callback(self):
def credentials_cb(url, username, allowed):