/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/config.py

merge bzr.dev r4154

Show diffs side-by-side

added added

removed removed

Lines of Context:
993
993
        section[option_name] = value
994
994
        self._save()
995
995
 
996
 
    def get_credentials(self, scheme, host, port=None, user=None, path=None):
 
996
    def get_credentials(self, scheme, host, port=None, user=None, path=None, 
 
997
                        realm=None):
997
998
        """Returns the matching credentials from authentication.conf file.
998
999
 
999
1000
        :param scheme: protocol
1005
1006
        :param user: login (optional)
1006
1007
 
1007
1008
        :param path: the absolute path on the server (optional)
 
1009
        
 
1010
        :param realm: the http authentication realm (optional)
1008
1011
 
1009
1012
        :return: A dict containing the matching credentials or None.
1010
1013
           This includes:
1011
1014
           - name: the section name of the credentials in the
1012
1015
             authentication.conf file,
1013
 
           - user: can't de different from the provided user if any,
 
1016
           - user: can't be different from the provided user if any,
 
1017
           - scheme: the server protocol,
 
1018
           - host: the server address,
 
1019
           - port: the server port (can be None),
 
1020
           - path: the absolute server path (can be None),
 
1021
           - realm: the http specific authentication realm (can be None),
1014
1022
           - password: the decoded password, could be None if the credential
1015
1023
             defines only the user
1016
1024
           - verify_certificates: https specific, True if the server
1057
1065
            if a_user is None:
1058
1066
                # Can't find a user
1059
1067
                continue
 
1068
            # Prepare a credentials dictionary with additional keys
 
1069
            # for the credential providers
1060
1070
            credentials = dict(name=auth_def_name,
1061
1071
                               user=a_user,
 
1072
                               scheme=a_scheme,
 
1073
                               host=host,
 
1074
                               port=port,
 
1075
                               path=path,
 
1076
                               realm=realm,
1062
1077
                               password=auth_def.get('password', None),
1063
1078
                               verify_certificates=a_verify_certificates)
 
1079
            # Decode the password in the credentials (or get one)
1064
1080
            self.decode_password(credentials,
1065
1081
                                 auth_def.get('password_encoding', None))
1066
1082
            if 'auth' in debug.debug_flags:
1070
1086
        return credentials
1071
1087
 
1072
1088
    def set_credentials(self, name, host, user, scheme=None, password=None,
1073
 
                        port=None, path=None, verify_certificates=None):
 
1089
                        port=None, path=None, verify_certificates=None,
 
1090
                        realm=None):
1074
1091
        """Set authentication credentials for a host.
1075
1092
 
1076
1093
        Any existing credentials with matching scheme, host, port and path
1087
1104
            apply to.
1088
1105
        :param verify_certificates: On https, verify server certificates if
1089
1106
            True.
 
1107
        :param realm: The http authentication realm (optional).
1090
1108
        """
1091
1109
        values = {'host': host, 'user': user}
1092
1110
        if password is not None:
1099
1117
            values['path'] = path
1100
1118
        if verify_certificates is not None:
1101
1119
            values['verify_certificates'] = str(verify_certificates)
 
1120
        if realm is not None:
 
1121
            values['realm'] = realm
1102
1122
        config = self._get_config()
1103
1123
        for_deletion = []
1104
1124
        for section, existing_values in config.items():
1105
 
            for key in ('scheme', 'host', 'port', 'path'):
 
1125
            for key in ('scheme', 'host', 'port', 'path', 'realm'):
1106
1126
                if existing_values.get(key) != values.get(key):
1107
1127
                    break
1108
1128
            else:
1127
1147
        :return: The found user.
1128
1148
        """
1129
1149
        credentials = self.get_credentials(scheme, host, port, user=None,
1130
 
                                           path=path)
 
1150
                                           path=path, realm=realm)
1131
1151
        if credentials is not None:
1132
1152
            user = credentials['user']
1133
1153
        else:
1152
1172
 
1153
1173
        :return: The found password or the one entered by the user.
1154
1174
        """
1155
 
        credentials = self.get_credentials(scheme, host, port, user, path)
 
1175
        credentials = self.get_credentials(scheme, host, port, user, path,
 
1176
                                           realm)
1156
1177
        if credentials is not None:
1157
1178
            password = credentials['password']
1158
1179
            if password is not None and scheme is 'ssh':