~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-22 15:18:24 UTC
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071022151824-eol757lk393ofc38
AuthenticationConfig can be queried for logins too (first step).

* bzrlib/transport/ssh.py:
(_paramiko_auth): Try to get a user from AuthenticationConfig.

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Try to get a user from
AuthenticationConfig.

* bzrlib/transport/ftp.py:
(FtpTransport._create_connection): Try to get a user from
AuthenticationConfig. Credentials are now (user, password) instead
of just password.

* bzrlib/tests/test_ftp_transport.py:
(TestFTPServerUI._add_authorized_user): Cleanup by refactoring.

* bzrlib/config.py:
(AuthenticationConfig.get_user): New method to get logins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
        in base url at transport creation time.
121
121
        """
122
122
        if credentials is None:
123
 
            password = self._password
 
123
            user, password = self._user, self._password
124
124
        else:
125
 
            password = credentials
 
125
            user, password = credentials
 
126
 
 
127
        auth = config.AuthenticationConfig()
 
128
        if user is None:
 
129
            user = auth.get_user('ftp', self._host, port=self._port)
 
130
            if user is None:
 
131
                # Default to local user
 
132
                user = getpass.getuser()
126
133
 
127
134
        mutter("Constructing FTP instance against %r" %
128
 
               ((self._host, self._port, self._user, '********',
 
135
               ((self._host, self._port, user, '********',
129
136
                self.is_active),))
130
137
        try:
131
138
            connection = ftplib.FTP()
132
139
            connection.connect(host=self._host, port=self._port)
133
 
            if self._user and self._user != 'anonymous' and \
 
140
            if user and user != 'anonymous' and \
134
141
                    password is None: # '' is a valid password
135
 
                auth = config.AuthenticationConfig()
136
 
                password = auth.get_password('ftp', self._host, self._user,
 
142
                password = auth.get_password('ftp', self._host, user,
137
143
                                             port=self._port)
138
 
            connection.login(user=self._user, passwd=password)
 
144
            connection.login(user=user, passwd=password)
139
145
            connection.set_pasv(not self.is_active)
140
146
        except ftplib.error_perm, e:
141
147
            raise errors.TransportError(msg="Error setting up connection:"
142
148
                                        " %s" % str(e), orig_error=e)
143
 
        return connection, password
 
149
        return connection, (user, password)
144
150
 
145
151
    def _reconnect(self):
146
152
        """Create a new connection with the previously used credentials"""