Rev 4311: Respect ~/.ssh/config usernames for bzr+ssh connections in http://bazaar.launchpad.net/%7Evila/bzr/integration
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 29 07:45:26 BST 2009
At http://bazaar.launchpad.net/%7Evila/bzr/integration
------------------------------------------------------------
revno: 4311 [merge]
revision-id: v.ladeuil+lp at free.fr-20090429064512-5wa7iv1vdjmoit64
parent: pqm at pqm.ubuntu.com-20090429035003-lx76v27oxuh6ykwm
parent: v.ladeuil+lp at free.fr-20090427161010-7swfzeagf63cpixd
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Wed 2009-04-29 08:45:12 +0200
message:
Respect ~/.ssh/config usernames for bzr+ssh connections
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
bzrlib/smtp_connection.py smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
bzrlib/transport/ftp/_gssapi.py _gssapi.py-20080611190840-7ejrtp884bk5eu72-2
bzrlib/transport/ssh.py ssh.py-20060824042150-0s9787kng6zv1nwq-1
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-04-28 23:20:23 +0000
+++ b/NEWS 2009-04-29 06:45:12 +0000
@@ -58,6 +58,9 @@
* Non-recursive ``bzr ls`` now works properly when a path is specified.
(Jelmer Vernooij, #357863)
+* ssh usernames (defined in ~/.ssh/config) are honoured for bzr+ssh connections.
+ (Vincent Ladeuil, #367726)
+
Documentation
*************
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2009-04-14 04:33:41 +0000
+++ b/bzrlib/config.py 2009-04-27 16:10:10 +0000
@@ -1132,7 +1132,7 @@
config.update({name: values})
self._save()
- def get_user(self, scheme, host, port=None, realm=None, path=None,
+ def get_user(self, scheme, host, port=None, realm=None, path=None,
prompt=None, ask=False, default=None):
"""Get a user from authentication file.
@@ -1149,6 +1149,8 @@
:param ask: Ask the user if there is no explicitly configured username
(optional)
+ :param default: The username returned if none is defined (optional).
+
:return: The found user.
"""
credentials = self.get_credentials(scheme, host, port, user=None,
@@ -1169,9 +1171,6 @@
prompt_host = host
user = ui.ui_factory.get_username(prompt, host=prompt_host)
else:
- if default is None:
- import getpass
- default = getpass.getuser()
user = default
return user
=== modified file 'bzrlib/plugins/launchpad/account.py'
--- a/bzrlib/plugins/launchpad/account.py 2009-04-10 18:35:52 +0000
+++ b/bzrlib/plugins/launchpad/account.py 2009-04-27 16:10:10 +0000
@@ -80,9 +80,7 @@
def _get_auth_user(auth=None):
if auth is None:
auth = AuthenticationConfig()
- username = auth.get_user('ssh', '.launchpad.net', default="")
- if username == "":
- username = None
+ username = auth.get_user('ssh', '.launchpad.net')
return username
def _set_auth_user(username, auth=None):
=== modified file 'bzrlib/smtp_connection.py'
--- a/bzrlib/smtp_connection.py 2009-04-07 14:03:52 +0000
+++ b/bzrlib/smtp_connection.py 2009-04-27 16:10:10 +0000
@@ -109,9 +109,8 @@
# FIXME: Since _authenticate gets called even when no authentication
# is necessary, it's not possible to use the default username
# here yet.
- self._smtp_username = auth.get_user('smtp', self._smtp_server,
- default="")
- if self._smtp_username == "":
+ self._smtp_username = auth.get_user('smtp', self._smtp_server)
+ if self._smtp_username is None:
return
if self._smtp_password is None:
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2009-04-14 06:50:58 +0000
+++ b/bzrlib/tests/test_config.py 2009-04-27 16:10:10 +0000
@@ -1506,9 +1506,9 @@
def test_username_default_no_prompt(self):
conf = config.AuthenticationConfig()
- self.assertEquals(getpass.getuser(),
+ self.assertEquals(None,
conf.get_user('ftp', 'example.com'))
- self.assertEquals("explicitdefault",
+ self.assertEquals("explicitdefault",
conf.get_user('ftp', 'example.com', default="explicitdefault"))
def test_password_default_prompts(self):
@@ -1524,9 +1524,9 @@
# FIXME: should we: forbid that, extend it to other schemes, leave
# things as they are that's fine thank you ?
self._check_default_password_prompt('SMTP %(user)s@%(host)s password: ',
- 'smtp')
+ 'smtp')
self._check_default_password_prompt('SMTP %(user)s@%(host)s password: ',
- 'smtp', host='bar.org:10025')
+ 'smtp', host='bar.org:10025')
self._check_default_password_prompt(
'SMTP %(user)s@%(host)s:%(port)d password: ',
'smtp', port=10025)
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2009-04-15 02:07:35 +0000
+++ b/bzrlib/tests/test_remote.py 2009-04-27 16:10:10 +0000
@@ -25,7 +25,6 @@
import bz2
from cStringIO import StringIO
-import getpass
from bzrlib import (
bzrdir,
@@ -1560,9 +1559,9 @@
class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
- def test_defaults_to_getuser(self):
+ def test_defaults_to_none(self):
t = RemoteSSHTransport('bzr+ssh://example.com')
- self.assertIs(getpass.getuser(), t._get_credentials()[0])
+ self.assertIs(None, t._get_credentials()[0])
def test_uses_authentication_config(self):
conf = config.AuthenticationConfig()
=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py 2009-04-09 20:22:04 +0000
+++ b/bzrlib/tests/test_sftp_transport.py 2009-04-27 16:10:10 +0000
@@ -15,7 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import getpass
import os
import socket
import sys
@@ -547,13 +546,13 @@
def test_sftp_is_none_if_no_config(self):
t = self.get_transport_for_connection(set_config=False)
- self.assertIs(getpass.getuser(), t._get_credentials()[0])
+ self.assertIs(None, t._get_credentials()[0])
def test_sftp_doesnt_prompt_username(self):
stdout = tests.StringIOWrapper()
ui.ui_factory = tests.TestUIFactory(stdin='joe\nfoo\n', stdout=stdout)
t = self.get_transport_for_connection(set_config=False)
- self.assertIs(getpass.getuser(), t._get_credentials()[0])
+ self.assertIs(None, t._get_credentials()[0])
# No prompts should've been printed, stdin shouldn't have been read
self.assertEquals("", stdout.getvalue())
self.assertEquals(0, ui.ui_factory.stdin.tell())
=== modified file 'bzrlib/transport/ftp/__init__.py'
--- a/bzrlib/transport/ftp/__init__.py 2009-04-02 15:26:49 +0000
+++ b/bzrlib/transport/ftp/__init__.py 2009-04-27 16:10:10 +0000
@@ -129,8 +129,8 @@
auth = config.AuthenticationConfig()
if user is None:
- user = auth.get_user('ftp', self._host, port=self._port)
-
+ user = auth.get_user('ftp', self._host, port=self._port,
+ default=getpass.getuser())
mutter("Constructing FTP instance against %r" %
((self._host, self._port, user, '********',
self.is_active),))
=== modified file 'bzrlib/transport/ftp/_gssapi.py'
--- a/bzrlib/transport/ftp/_gssapi.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/transport/ftp/_gssapi.py 2009-04-27 16:10:10 +0000
@@ -118,11 +118,8 @@
auth = config.AuthenticationConfig()
if user is None:
- user = auth.get_user('ftp', self._host, port=self._port)
- if user is None:
- # Default to local user
- user = getpass.getuser()
-
+ user = auth.get_user('ftp', self._host, port=self._port,
+ default=getpass.getuser())
mutter("Constructing FTP instance against %r" %
((self._host, self._port, user, '********',
self.is_active),))
=== modified file 'bzrlib/transport/ssh.py'
--- a/bzrlib/transport/ssh.py 2009-04-02 15:26:49 +0000
+++ b/bzrlib/transport/ssh.py 2009-04-27 16:10:10 +0000
@@ -18,6 +18,7 @@
"""Foundation SSH support for SFTP and smart server."""
import errno
+import getpass
import os
import socket
import subprocess
@@ -461,8 +462,8 @@
# paramiko requires a username, but it might be none if nothing was
# supplied. If so, use the local username.
if username is None:
- username = auth.get_user('ssh', host, port=port)
-
+ username = auth.get_user('ssh', host, port=port,
+ default=getpass.getuser())
if _use_ssh_agent:
agent = paramiko.Agent()
for key in agent.get_keys():
More information about the bazaar-commits
mailing list