787
787
return osutils.pathjoin(config_dir(), 'locations.conf')
790
def authentication_config_filename():
791
"""Return per-user authentication ini file filename."""
792
return osutils.pathjoin(config_dir(), 'authentication.conf')
790
795
def user_ignore_config_filename():
791
796
"""Return the user default ignore filename"""
792
797
return osutils.pathjoin(config_dir(), 'ignore')
928
934
self.branch.control_files.put('branch.conf', out_file)
930
936
self.branch.unlock()
939
class AuthenticationConfig(object):
940
"""The authentication configuration file based on a ini file.
942
Implements the authentication.conf file described in
943
doc/developers/authentication-ring.txt.
946
def __init__(self, _file=None):
947
super(AuthenticationConfig, self).__init__()
951
self._input = authentication_config_filename()
955
def _get_config(self):
956
if self._config is not None:
959
self._config = ConfigObj(self._input, encoding='utf-8')
960
except configobj.ConfigObjError, e:
961
raise errors.ParseConfigError(e.errors, e.config.filename)
964
def get_credentials(self, scheme, host, port=None, user=None, path=None):
966
for auth_def_name, auth_def in self._get_config().items():
967
a_scheme, a_user, a_host, a_port, a_path = map(
968
auth_def.get, ['scheme', 'user', 'host', 'port',
970
if a_scheme is not None and scheme != a_scheme:
972
if a_host is not None:
973
if not (host == a_host
974
or (a_host.startswith('.') and host.endswith(a_host))):
976
if a_port is not None and port != int(a_port):
978
if (a_path is not None and path is not None
979
and not path.startswith(a_path)):
981
if (a_user is not None and user is not None
988
a_password, a_encoding = map(auth_def.get,
989
['password', 'password_encoding'])
990
password = self.decode_password(a_password, a_encoding)
992
verify_certificates = auth_def.as_bool('verify_certificates')
994
verify_certificates = True
995
credentials = {'name': auth_def_name,
996
'user': user, 'password': password,
997
'verify_certificates': verify_certificates,
1003
def decode_password(self, password, encoding):