Show More
@@ -58,7 +58,6 b' from mercurial import mail' | |||||
58 | from mercurial.mail import SMTPS, STARTTLS |
|
58 | from mercurial.mail import SMTPS, STARTTLS | |
59 | from mercurial import encoding |
|
59 | from mercurial import encoding | |
60 |
|
60 | |||
61 | from urlparse import urlparse |
|
|||
62 | import urllib2 |
|
61 | import urllib2 | |
63 | import smtplib |
|
62 | import smtplib | |
64 | import socket |
|
63 | import socket | |
@@ -298,6 +297,7 b' class HTTPPasswordHandler(object):' | |||||
298 | SRC_URL = "repository URL" |
|
297 | SRC_URL = "repository URL" | |
299 | SRC_CFGAUTH = "hgrc" |
|
298 | SRC_CFGAUTH = "hgrc" | |
300 | SRC_MEMCACHE = "temporary cache" |
|
299 | SRC_MEMCACHE = "temporary cache" | |
|
300 | SRC_URLCACHE = "urllib temporary cache" | |||
301 | SRC_KEYRING = "keyring" |
|
301 | SRC_KEYRING = "keyring" | |
302 |
|
302 | |||
303 | def get_credentials(self, pwmgr, realm, authuri, skip_caches=False): |
|
303 | def get_credentials(self, pwmgr, realm, authuri, skip_caches=False): | |
@@ -317,22 +317,27 b' class HTTPPasswordHandler(object):' | |||||
317 | """ |
|
317 | """ | |
318 | ui = pwmgr.ui |
|
318 | ui = pwmgr.ui | |
319 |
|
319 | |||
320 | # Strip arguments to get actual remote repository url. |
|
320 | base_url, url_user, url_passwd = self.unpack_url(authuri) | |
321 | base_url = self.canonical_url(authuri) |
|
321 | ui.debug(_('keyring: base url: %s, url user: %s, url pwd: %s\n') % | |
|
322 | (base_url, url_user or '', url_passwd and '******' or '')) | |||
|
323 | ||||
|
324 | # Extract username (or password) stored directly in url | |||
|
325 | if url_user and url_passwd: | |||
|
326 | return url_user, url_passwd, self.SRC_URL, base_url | |||
322 |
|
327 | |||
323 | # Extract username (or password) stored directly in url |
|
328 | # Extract data from urllib (in case it was already stored) | |
324 | url_user, url_pwd \ |
|
329 | urllib_user, urllib_pwd \ | |
325 | = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( |
|
330 | = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( | |
326 | pwmgr, realm, authuri) |
|
331 | pwmgr, realm, authuri) | |
327 | if url_user and url_pwd: |
|
332 | if urllib_user and urllib_pwd: | |
328 | return url_user, url_pwd, self.SRC_URL, base_url |
|
333 | return urllib_user, urllib_pwd, self.SRC_URLCACHE, base_url | |
329 |
|
334 | |||
330 | # Consult configuration to normalize url to prefix, and find username |
|
335 | # Consult configuration to normalize url to prefix, and find username | |
331 | # (and maybe password) |
|
336 | # (and maybe password) | |
332 | auth_user, auth_pwd, keyring_url = self.get_url_config( |
|
337 | auth_user, auth_pwd, keyring_url = self.get_url_config( | |
333 | ui, base_url, url_user) |
|
338 | ui, base_url, url_user) | |
334 | if auth_user and url_user and (url_user != auth_user): |
|
339 | if auth_user and url_user and (url_user != auth_user): | |
335 |
raise util.Abort(_(' |
|
340 | raise util.Abort(_('keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, url_user, auth_user))) | |
336 | if auth_user and auth_pwd: |
|
341 | if auth_user and auth_pwd: | |
337 | return auth_user, auth_pwd, self.SRC_CFGAUTH, keyring_url |
|
342 | return auth_user, auth_pwd, self.SRC_CFGAUTH, keyring_url | |
338 |
|
343 | |||
@@ -354,12 +359,11 b' class HTTPPasswordHandler(object):' | |||||
354 |
|
359 | |||
355 | return auth_user, None, None, keyring_url |
|
360 | return auth_user, None, None, keyring_url | |
356 |
|
361 | |||
357 |
|
||||
358 | @staticmethod |
|
362 | @staticmethod | |
359 | def prompt_interactively(ui, user, realm, url): |
|
363 | def prompt_interactively(ui, user, realm, url): | |
360 | """Actual interactive prompt""" |
|
364 | """Actual interactive prompt""" | |
361 | if not ui.interactive(): |
|
365 | if not ui.interactive(): | |
362 |
raise util.Abort(_(' |
|
366 | raise util.Abort(_('keyring: http authorization required but program used in non-interactive mode')) | |
363 |
|
367 | |||
364 | if not user: |
|
368 | if not user: | |
365 | ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) |
|
369 | ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) | |
@@ -482,16 +486,29 b' class HTTPPasswordHandler(object):' | |||||
482 | return password_url |
|
486 | return password_url | |
483 |
|
487 | |||
484 | @staticmethod |
|
488 | @staticmethod | |
485 |
def |
|
489 | def unpack_url(authuri): | |
486 | """ |
|
490 | """ | |
487 | Strips query params from url. Used to convert urls like |
|
491 | Does two things: | |
|
492 | ||||
|
493 | 1. Strips query params from url. Used to convert urls like | |||
488 | https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between |
|
494 | https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between | |
489 | to |
|
495 | to | |
490 | https://repo.machine.com/repos/apps/module |
|
496 | https://repo.machine.com/repos/apps/module | |
|
497 | ||||
|
498 | 2. Extracts username and password, if present. | |||
|
499 | ||||
|
500 | Returns url, user, password | |||
491 | """ |
|
501 | """ | |
492 | parsed_url = urlparse(authuri) |
|
502 | # mercurial.util.url, rather handy url parser | |
493 | return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, |
|
503 | parsed_url = util.url(authuri) | |
494 | parsed_url.path) |
|
504 | parsed_url.query = '' | |
|
505 | parsed_url.fragment = '' | |||
|
506 | # Strip arguments to get actual remote repository url. | |||
|
507 | # base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, | |||
|
508 | # parsed_url.path) | |||
|
509 | ||||
|
510 | return str(parsed_url), parsed_url.user, parsed_url.passwd | |||
|
511 | ||||
495 |
|
512 | |||
496 | ############################################################ |
|
513 | ############################################################ | |
497 | # Mercurial monkey-patching |
|
514 | # Mercurial monkey-patching |
General Comments 0
You need to be logged in to leave comments.
Login now