Mercurial > hg
comparison mercurial/url.py @ 13372:5bced0d28a39
url: return the matched authentication group name from readauthforuri()
Internally, the group name is only used in debug statements, but readauthforuri
can be also used externally to determine which group will be matched for a given
URL.
author | Steve Borho <steve@borho.org> |
---|---|
date | Sun, 13 Feb 2011 12:19:58 -0600 |
parents | c691cfdc6b4d |
children | 1cc73868c740 |
comparison
equal
deleted
inserted
replaced
13371:c691cfdc6b4d | 13372:5bced0d28a39 |
---|---|
86 | 86 |
87 # Find the best match | 87 # Find the best match |
88 scheme, hostpath = uri.split('://', 1) | 88 scheme, hostpath = uri.split('://', 1) |
89 bestlen = 0 | 89 bestlen = 0 |
90 bestauth = None | 90 bestauth = None |
91 for auth in config.itervalues(): | 91 for group, auth in config.iteritems(): |
92 prefix = auth.get('prefix') | 92 prefix = auth.get('prefix') |
93 if not prefix: | 93 if not prefix: |
94 continue | 94 continue |
95 p = prefix.split('://', 1) | 95 p = prefix.split('://', 1) |
96 if len(p) > 1: | 96 if len(p) > 1: |
98 else: | 98 else: |
99 schemes = (auth.get('schemes') or 'https').split() | 99 schemes = (auth.get('schemes') or 'https').split() |
100 if (prefix == '*' or hostpath.startswith(prefix)) and \ | 100 if (prefix == '*' or hostpath.startswith(prefix)) and \ |
101 len(prefix) > bestlen and scheme in schemes: | 101 len(prefix) > bestlen and scheme in schemes: |
102 bestlen = len(prefix) | 102 bestlen = len(prefix) |
103 bestauth = auth | 103 bestauth = group, auth |
104 return bestauth | 104 return bestauth |
105 | 105 |
106 _safe = ('abcdefghijklmnopqrstuvwxyz' | 106 _safe = ('abcdefghijklmnopqrstuvwxyz' |
107 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 107 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
108 '0123456789' '_.-/') | 108 '0123456789' '_.-/') |
153 if user and passwd: | 153 if user and passwd: |
154 self._writedebug(user, passwd) | 154 self._writedebug(user, passwd) |
155 return (user, passwd) | 155 return (user, passwd) |
156 | 156 |
157 if not user: | 157 if not user: |
158 auth = self.readauthtoken(authuri) | 158 res = readauthforuri(self.ui, authuri) |
159 if auth: | 159 if res: |
160 group, auth = res | |
160 user, passwd = auth.get('username'), auth.get('password') | 161 user, passwd = auth.get('username'), auth.get('password') |
162 self.ui.debug("using auth.%s.* for authentication\n" % group) | |
161 if not user or not passwd: | 163 if not user or not passwd: |
162 if not self.ui.interactive(): | 164 if not self.ui.interactive(): |
163 raise util.Abort(_('http authorization required')) | 165 raise util.Abort(_('http authorization required')) |
164 | 166 |
165 self.ui.write(_("http authorization required\n")) | 167 self.ui.write(_("http authorization required\n")) |
177 return (user, passwd) | 179 return (user, passwd) |
178 | 180 |
179 def _writedebug(self, user, passwd): | 181 def _writedebug(self, user, passwd): |
180 msg = _('http auth: user %s, password %s\n') | 182 msg = _('http auth: user %s, password %s\n') |
181 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set')) | 183 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set')) |
182 | |
183 def readauthtoken(self, uri): | |
184 return readauthforuri(self.ui, uri) | |
185 | 184 |
186 class proxyhandler(urllib2.ProxyHandler): | 185 class proxyhandler(urllib2.ProxyHandler): |
187 def __init__(self, ui): | 186 def __init__(self, ui): |
188 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') | 187 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') |
189 # XXX proxyauthinfo = None | 188 # XXX proxyauthinfo = None |
622 def _start_transaction(self, h, req): | 621 def _start_transaction(self, h, req): |
623 _generic_start_transaction(self, h, req) | 622 _generic_start_transaction(self, h, req) |
624 return keepalive.KeepAliveHandler._start_transaction(self, h, req) | 623 return keepalive.KeepAliveHandler._start_transaction(self, h, req) |
625 | 624 |
626 def https_open(self, req): | 625 def https_open(self, req): |
627 self.auth = self.pwmgr.readauthtoken(req.get_full_url()) | 626 res = readauthforuri(self.ui, req.get_full_url()) |
627 if res: | |
628 group, auth = res | |
629 self.auth = auth | |
630 self.ui.debug("using auth.%s.* for authentication\n" % group) | |
631 else: | |
632 self.auth = None | |
628 return self.do_open(self._makeconnection, req) | 633 return self.do_open(self._makeconnection, req) |
629 | 634 |
630 def _makeconnection(self, host, port=None, *args, **kwargs): | 635 def _makeconnection(self, host, port=None, *args, **kwargs): |
631 keyfile = None | 636 keyfile = None |
632 certfile = None | 637 certfile = None |