~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.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:
63
63
"""
64
64
 
65
65
import os
 
66
import getpass
66
67
import sys
67
68
 
68
69
from bzrlib.lazy_import import lazy_import
1003
1004
 
1004
1005
        :param path: the absolute path on the server (optional)
1005
1006
 
1006
 
        :return: A dict with containing the matching credentials or None.
 
1007
        :return: A dict containing the matching credentials or None.
1007
1008
           This includes:
1008
1009
           - name: the section name of the credentials in the
1009
1010
             authentication.conf file,
1010
1011
           - user: can't de different from the provided user if any,
1011
 
           - password: the decoded password,
 
1012
           - password: the decoded password, could be None if the credential
 
1013
             defines only the user
1012
1014
           - verify_certificates: https specific, True if the server
1013
1015
             certificate should be verified, False otherwise.
1014
1016
        """
1042
1044
                and a_user != user):
1043
1045
                # Never contradict the caller about the user to be used
1044
1046
                continue
1045
 
            user = a_user
1046
 
            if user is None:
 
1047
            if a_user is None:
1047
1048
                # Can't find a user
1048
1049
                continue
1049
1050
            a_password, a_encoding = map(auth_def.get,
1050
1051
                                         ['password', 'password_encoding'])
1051
1052
            password = self.decode_password(a_password, a_encoding)
1052
1053
            credentials = {'name': auth_def_name,
1053
 
                           'user': user, 'password': password,
 
1054
                           'user': a_user, 'password': password,
1054
1055
                           'verify_certificates': a_verify_certificates,
1055
1056
                           }
1056
1057
            if 'auth' in debug.debug_flags:
1059
1060
 
1060
1061
        return credentials
1061
1062
 
 
1063
    def get_user(self, scheme, host, port=None,
 
1064
                 realm=None, path=None, prompt=None):
 
1065
        """Get a user from authentication file.
 
1066
 
 
1067
        :param scheme: protocol
 
1068
 
 
1069
        :param host: the server address
 
1070
 
 
1071
        :param port: the associated port (optional)
 
1072
 
 
1073
        :param realm: the realm sent by the server (optional)
 
1074
 
 
1075
        :param path: the absolute path on the server (optional)
 
1076
 
 
1077
        :return: The found user.
 
1078
        """
 
1079
        credentials = self.get_credentials(scheme, host, port, user, path)
 
1080
        if credentials is not None:
 
1081
            user = credentials['user']
 
1082
        else:
 
1083
            user = None
 
1084
        return user
 
1085
 
1062
1086
    def get_password(self, scheme, host, user, port=None,
1063
1087
                     realm=None, path=None, prompt=None):
1064
1088
        """Get a password from authentication file or prompt the user for one.
1080
1104
        credentials = self.get_credentials(scheme, host, port, user, path)
1081
1105
        if credentials is not None:
1082
1106
            password = credentials['password']
1083
 
        else:
 
1107
        if password is None:
1084
1108
            # Prompt user only if we could't find a password
1085
1109
            if prompt is None:
1086
1110
                prompt = ('%s' % scheme.upper()