Rev 3783: Implement default ssh usernames via launchpad-login (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Oct 17 13:55:55 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3783
revision-id: pqm at pqm.ubuntu.com-20081017125551-l5zi213vopny82nt
parent: pqm at pqm.ubuntu.com-20081016213135-0115pw9c95l2dyxq
parent: aaron at aaronbentley.com-20081017122234-4lygct4bu1hsube6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-10-17 13:55:51 +0100
message:
  Implement default ssh usernames via launchpad-login (abentley)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
  bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
  bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
    ------------------------------------------------------------
    revno: 3777.1.18
    revision-id: aaron at aaronbentley.com-20081017122234-4lygct4bu1hsube6
    parent: aaron at aaronbentley.com-20081016184810-ago29htjdh2z0x0t
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Fri 2008-10-17 08:22:34 -0400
    message:
      Fix None handling wrt auth upgrades
    modified:
      bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
      bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
      bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
    ------------------------------------------------------------
    revno: 3777.1.17
    revision-id: aaron at aaronbentley.com-20081016184810-ago29htjdh2z0x0t
    parent: aaron at aaronbentley.com-20081016184139-ve0w21oeg0by6he6
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 14:48:10 -0400
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3777.1.16
    revision-id: aaron at aaronbentley.com-20081016184139-ve0w21oeg0by6he6
    parent: aaron at aaronbentley.com-20081016183519-llt3cr4n24ymrlrh
    parent: aaron at aaronbentley.com-20081016183758-1c4qosfpmdoee03b
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 14:41:39 -0400
    message:
      Merge with lower thread
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
        ------------------------------------------------------------
        revno: 3777.3.3
        revision-id: aaron at aaronbentley.com-20081016183758-1c4qosfpmdoee03b
        parent: aaron at aaronbentley.com-20081016183032-cybgqp6y0ip27mem
        committer: Aaron Bentley <aaron at aaronbentley.com>
        branch nick: set_credentials
        timestamp: Thu 2008-10-16 14:37:58 -0400
        message:
          Update NEWS
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3777.1.15
    revision-id: aaron at aaronbentley.com-20081016183519-llt3cr4n24ymrlrh
    parent: aaron at aaronbentley.com-20081016183220-7e692v9fac5613zb
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 14:35:19 -0400
    message:
      Update docs
    modified:
      bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
    ------------------------------------------------------------
    revno: 3777.1.14
    revision-id: aaron at aaronbentley.com-20081016183220-7e692v9fac5613zb
    parent: aaron at aaronbentley.com-20081016183043-v3d3226g1x7c05ns
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 14:32:20 -0400
    message:
      Adjust for new set_credentials signature
    modified:
      bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
      bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
    ------------------------------------------------------------
    revno: 3777.1.13
    revision-id: aaron at aaronbentley.com-20081016183043-v3d3226g1x7c05ns
    parent: aaron at aaronbentley.com-20081016160555-6ux64504nzwyxog9
    parent: aaron at aaronbentley.com-20081016183032-cybgqp6y0ip27mem
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 14:30:43 -0400
    message:
      Merge set_credentials into launchpad-login
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
        ------------------------------------------------------------
        revno: 3777.3.2
        revision-id: aaron at aaronbentley.com-20081016183032-cybgqp6y0ip27mem
        parent: aaron at aaronbentley.com-20081016182657-1xi0vmda0iffc2g8
        committer: Aaron Bentley <aaron at aaronbentley.com>
        branch nick: set_credentials
        timestamp: Thu 2008-10-16 14:30:32 -0400
        message:
          Reverse order of scheme and password
        modified:
          bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
          bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
        ------------------------------------------------------------
        revno: 3777.3.1
        revision-id: aaron at aaronbentley.com-20081016182657-1xi0vmda0iffc2g8
        parent: aaron at aaronbentley.com-20081016160425-z6e33epyqltcn6wj
        committer: Aaron Bentley <aaron at aaronbentley.com>
        branch nick: set_credentials
        timestamp: Thu 2008-10-16 14:26:57 -0400
        message:
          Update docs
        modified:
          bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
    ------------------------------------------------------------
    revno: 3777.1.12
    revision-id: aaron at aaronbentley.com-20081016160555-6ux64504nzwyxog9
    parent: aaron at aaronbentley.com-20081016160425-z6e33epyqltcn6wj
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 12:05:55 -0400
    message:
      Enable configuring ssh auth from launchpad-login, with auto-upgrade.
    modified:
      bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
      bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
    ------------------------------------------------------------
    revno: 3777.1.11
    revision-id: aaron at aaronbentley.com-20081016160425-z6e33epyqltcn6wj
    parent: aaron at aaronbentley.com-20081016132940-24l3emoih65h1nsq
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 12:04:25 -0400
    message:
      Ensure changed-name updates clear old values
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
    ------------------------------------------------------------
    revno: 3777.1.10
    revision-id: aaron at aaronbentley.com-20081016132940-24l3emoih65h1nsq
    parent: aaron at aaronbentley.com-20081016130333-0cti66q6xo5napqd
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 09:29:40 -0400
    message:
      Ensure credentials are stored
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
    ------------------------------------------------------------
    revno: 3777.1.9
    revision-id: aaron at aaronbentley.com-20081016130333-0cti66q6xo5napqd
    parent: aaron at aaronbentley.com-20081015211105-49xq5y8jnla6clni
    parent: aaron at aaronbentley.com-20081016130324-547q140zwnh6g8aq
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Thu 2008-10-16 09:03:33 -0400
    message:
      Merge authconfig into launchpad-login
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
        ------------------------------------------------------------
        revno: 3777.2.1
        revision-id: aaron at aaronbentley.com-20081016130324-547q140zwnh6g8aq
        parent: aaron at aaronbentley.com-20081015191156-mrykcuir96zszuh7
        parent: pqm at pqm.ubuntu.com-20081016043554-38i4ho6svnlyba65
        committer: Aaron Bentley <aaron at aaronbentley.com>
        branch nick: authconfig
        timestamp: Thu 2008-10-16 09:03:24 -0400
        message:
          Merge with bzr.dev
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
          bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
          bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
          setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
    ------------------------------------------------------------
    revno: 3777.1.8
    revision-id: aaron at aaronbentley.com-20081015211105-49xq5y8jnla6clni
    parent: aaron at aaronbentley.com-20081015191156-mrykcuir96zszuh7
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: launchpad-login
    timestamp: Wed 2008-10-15 17:11:05 -0400
    message:
      Commit work-in-progress
    modified:
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
=== modified file 'NEWS'
--- a/NEWS	2008-10-16 03:58:42 +0000
+++ b/NEWS	2008-10-16 18:48:10 +0000
@@ -19,6 +19,9 @@
     * default username for bzr+ssh and sftp can be configured in
       authentication.conf. (Aaron Bentley)
 
+    * launchpad-login now provides a default username for bzr+ssh and sftp
+      URLs, allowing username-free URLs to work for everyone. (Aaron Bentley)
+
   BUG FIXES:
 
     * A failure to load a plugin due to an IncompatibleAPI exception is
@@ -39,6 +42,9 @@
 
   INTERNALS:
 
+     * New AuthenticationConfig.set_credentials method allows easy programmatic
+       configuration of authetication credentials.
+
   PORTABILITY:
 
 

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2008-09-08 12:59:00 +0000
+++ b/bzrlib/config.py	2008-10-16 18:30:32 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2007 Canonical Ltd
+# Copyright (C) 2005, 2007, 2008 Canonical Ltd
 #   Authors: Robert Collins <robert.collins at canonical.com>
 #            and others
 #
@@ -1064,6 +1064,47 @@
 
         return credentials
 
+    def set_credentials(self, name, host, user, scheme=None, password=None,
+                        port=None, path=None, verify_certificates=None):
+        """Set authentication credentials for a host.
+
+        Any existing credentials with matching scheme, host, port and path
+        will be deleted, regardless of name.
+
+        :param name: An arbitrary name to describe this set of credentials.
+        :param host: Name of the host that accepts these credentials.
+        :param user: The username portion of these credentials.
+        :param scheme: The URL scheme (e.g. ssh, http) the credentials apply
+            to.
+        :param password: Password portion of these credentials.
+        :param port: The IP port on the host that these credentials apply to.
+        :param path: A filesystem path on the host that these credentials
+            apply to.
+        :param verify_certificates: On https, verify server certificates if
+            True.
+        """
+        values = {'host': host, 'user': user}
+        if password is not None:
+            values['password'] = password
+        if scheme is not None:
+            values['scheme'] = scheme
+        if port is not None:
+            values['port'] = '%d' % port
+        if path is not None:
+            values['path'] = path
+        if verify_certificates is not None:
+            values['verify_certificates'] = str(verify_certificates)
+        config = self._get_config()
+        for_deletion = []
+        for section, existing_values in config.items():
+            for key in ('scheme', 'host', 'port', 'path'):
+                if existing_values.get(key) != values.get(key):
+                    break
+            else:
+                del config[section]
+        config.update({name: values})
+        self._save()
+
     def get_user(self, scheme, host, port=None,
                  realm=None, path=None, prompt=None):
         """Get a user from authentication file.

=== modified file 'bzrlib/plugins/launchpad/account.py'
--- a/bzrlib/plugins/launchpad/account.py	2007-11-12 21:23:07 +0000
+++ b/bzrlib/plugins/launchpad/account.py	2008-10-17 12:22:34 +0000
@@ -20,8 +20,8 @@
 than once for each place that needs to take it into account.
 """
 
-from bzrlib import errors
-from bzrlib.config import GlobalConfig
+from bzrlib import errors, trace
+from bzrlib.config import AuthenticationConfig, GlobalConfig
 from bzrlib.transport import get_transport
 
 
@@ -36,20 +36,56 @@
     _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
 
 
+class MismatchedUsernames(errors.BzrError):
+
+    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
+            ' account name.  Please re-run launchpad-login.')
+
+
 def get_lp_login(_config=None):
-    """Return the user's Launchpad username"""
-    if _config is None:
-        _config = GlobalConfig()
-
-    return _config.get_user_option('launchpad_username')
+    """Return the user's Launchpad username.
+
+    :raises: MismatchedUsername if authentication.conf and bazaar.conf
+        disagree about username.
+    """
+    if _config is None:
+        _config = GlobalConfig()
+
+    username = _config.get_user_option('launchpad_username')
+    if username is not None:
+        auth = AuthenticationConfig()
+        auth_username = _get_auth_user(auth)
+        # Auto-upgrading
+        if auth_username is None:
+            trace.note('Setting ssh/sftp username for bazaar.launchpad.net.')
+            _set_auth_user(username, auth)
+        elif auth_username != username:
+            raise MismatchedUsernames()
+    return username
+
+
+def _set_global_option(username, _config=None):
+    if _config is None:
+        _config = GlobalConfig()
+    _config.set_user_option('launchpad_username', username)
 
 
 def set_lp_login(username, _config=None):
     """Set the user's Launchpad username"""
-    if _config is None:
-        _config = GlobalConfig()
-
-    _config.set_user_option('launchpad_username', username)
+    _set_global_option(username, _config)
+    _set_auth_user(username)
+
+
+def _get_auth_user(auth=None):
+    if auth is None:
+        auth = AuthenticationConfig()
+    return auth.get_user('ssh', 'bazaar.launchpad.net')
+
+def _set_auth_user(username, auth=None):
+    if auth is None:
+        auth = AuthenticationConfig()
+    auth.set_credentials(
+        'Launchpad', 'bazaar.launchpad.net', username, 'ssh')
 
 
 def check_lp_login(username, _transport=None):

=== modified file 'bzrlib/plugins/launchpad/test_account.py'
--- a/bzrlib/plugins/launchpad/test_account.py	2007-10-18 08:58:19 +0000
+++ b/bzrlib/plugins/launchpad/test_account.py	2008-10-17 12:22:34 +0000
@@ -63,6 +63,38 @@
         self.assertEqualDiff('The user test-user has not registered any '
                              'SSH keys with Launchpad.', str(error))
 
+    def test_set_lp_login_updates_authentication_conf(self):
+        self.assertIs(None, account._get_auth_user())
+        account.set_lp_login('foo')
+        self.assertEqual('foo', account._get_auth_user())
+
+    def test_get_lp_login_does_not_update_for_none_user(self):
+        account.get_lp_login()
+        self.assertIs(None, account._get_auth_user())
+
+    def test_get_lp_login_updates_authentication_conf(self):
+        account._set_global_option('foo')
+        self.assertIs(None, account._get_auth_user())
+        account.get_lp_login()
+        self.assertEqual('foo', account._get_auth_user())
+
+    def test_get_lp_login_leaves_existing_credentials(self):
+        auth = config.AuthenticationConfig()
+        auth.set_credentials('Foo', 'bazaar.launchpad.net', 'foo', 'ssh')
+        account._set_global_option('foo')
+        account.get_lp_login()
+        auth = config.AuthenticationConfig()
+        credentials = auth.get_credentials('ssh', 'bazaar.launchpad.net')
+        self.assertEqual('Foo', credentials['name'])
+
+    def test_get_lp_login_errors_on_mismatch(self):
+        account._set_auth_user('foo')
+        account._set_global_option('bar')
+        e = self.assertRaises(account.MismatchedUsernames,
+                              account.get_lp_login)
+        self.assertEqual('bazaar.conf and authentication.conf disagree about'
+            ' launchpad account name.  Please re-run launchpad-login.', str(e))
+
 
 class CheckAccountTests(TestCaseWithMemoryTransport):
 

=== modified file 'bzrlib/plugins/launchpad/test_lp_directory.py'
--- a/bzrlib/plugins/launchpad/test_lp_directory.py	2008-03-06 21:16:38 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_directory.py	2008-10-17 12:22:34 +0000
@@ -23,7 +23,11 @@
     )
 from bzrlib.branch import Branch
 from bzrlib.directory_service import directories
-from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
+from bzrlib.tests import (
+    TestCase,
+    TestCaseInTempDir,
+    TestCaseWithMemoryTransport
+)
 from bzrlib.transport import get_transport
 from bzrlib.plugins.launchpad import _register_directory
 from bzrlib.plugins.launchpad.lp_directory import (
@@ -46,7 +50,7 @@
         return self._result
 
 
-class DirectoryUrlTests(TestCase):
+class DirectoryUrlTests(TestCaseInTempDir):
     """Tests for branch urls through Launchpad.net directory"""
 
     def test_short_form(self):

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2008-08-10 11:26:50 +0000
+++ b/bzrlib/tests/test_config.py	2008-10-16 18:30:32 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 #   Authors: Robert Collins <robert.collins at canonical.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -1412,6 +1412,32 @@
         self.assertEquals(True, credentials.get('verify_certificates'))
 
 
+class TestAuthenticationStorage(tests.TestCaseInTempDir):
+
+    def test_set_credentials(self):
+        conf = config.AuthenticationConfig()
+        conf.set_credentials('name', 'host', 'user', 'scheme', 'password',
+        99, path='/foo', verify_certificates=False)
+        credentials = conf.get_credentials(host='host', scheme='scheme',
+                                           port=99, path='/foo')
+        CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
+                       'verify_certificates': False,}
+        self.assertEqual(CREDENTIALS, credentials)
+        credentials_from_disk = config.AuthenticationConfig().get_credentials(
+            host='host', scheme='scheme', port=99, path='/foo')
+        self.assertEqual(CREDENTIALS, credentials_from_disk)
+
+    def test_reset_credentials_different_name(self):
+        conf = config.AuthenticationConfig()
+        conf.set_credentials('name', 'host', 'user', 'scheme', 'password'),
+        conf.set_credentials('name2', 'host', 'user2', 'scheme', 'password'),
+        self.assertIs(None, conf._get_config().get('name'))
+        credentials = conf.get_credentials(host='host', scheme='scheme')
+        CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
+                       'password', 'verify_certificates': True}
+        self.assertEqual(CREDENTIALS, credentials)
+
+
 class TestAuthenticationConfig(tests.TestCase):
     """Test AuthenticationConfig behaviour"""
 




More information about the bazaar-commits mailing list