##// END OF EJS Templates
Partial bugfix for ignoring usernames specified in url (not yet finished)....
Marcin Kasperski -
r196:bfd781fe default
parent child Browse files
Show More
@@ -58,7 +58,6 b' from mercurial import mail'
58 58 from mercurial.mail import SMTPS, STARTTLS
59 59 from mercurial import encoding
60 60
61 from urlparse import urlparse
62 61 import urllib2
63 62 import smtplib
64 63 import socket
@@ -298,6 +297,7 b' class HTTPPasswordHandler(object):'
298 297 SRC_URL = "repository URL"
299 298 SRC_CFGAUTH = "hgrc"
300 299 SRC_MEMCACHE = "temporary cache"
300 SRC_URLCACHE = "urllib temporary cache"
301 301 SRC_KEYRING = "keyring"
302 302
303 303 def get_credentials(self, pwmgr, realm, authuri, skip_caches=False):
@@ -317,22 +317,27 b' class HTTPPasswordHandler(object):'
317 317 """
318 318 ui = pwmgr.ui
319 319
320 # Strip arguments to get actual remote repository url.
321 base_url = self.canonical_url(authuri)
320 base_url, url_user, url_passwd = self.unpack_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
324 url_user, url_pwd \
328 # Extract data from urllib (in case it was already stored)
329 urllib_user, urllib_pwd \
325 330 = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
326 331 pwmgr, realm, authuri)
327 if url_user and url_pwd:
328 return url_user, url_pwd, self.SRC_URL, base_url
332 if urllib_user and urllib_pwd:
333 return urllib_user, urllib_pwd, self.SRC_URLCACHE, base_url
329 334
330 335 # Consult configuration to normalize url to prefix, and find username
331 336 # (and maybe password)
332 337 auth_user, auth_pwd, keyring_url = self.get_url_config(
333 338 ui, base_url, url_user)
334 339 if auth_user and url_user and (url_user != auth_user):
335 raise util.Abort(_('mercurial_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)))
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 341 if auth_user and auth_pwd:
337 342 return auth_user, auth_pwd, self.SRC_CFGAUTH, keyring_url
338 343
@@ -354,12 +359,11 b' class HTTPPasswordHandler(object):'
354 359
355 360 return auth_user, None, None, keyring_url
356 361
357
358 362 @staticmethod
359 363 def prompt_interactively(ui, user, realm, url):
360 364 """Actual interactive prompt"""
361 365 if not ui.interactive():
362 raise util.Abort(_('mercurial_keyring: http authorization required but program used in non-interactive mode'))
366 raise util.Abort(_('keyring: http authorization required but program used in non-interactive mode'))
363 367
364 368 if not user:
365 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 486 return password_url
483 487
484 488 @staticmethod
485 def canonical_url(authuri):
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 494 https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between
489 495 to
490 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)
493 return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc,
494 parsed_url.path)
502 # mercurial.util.url, rather handy url parser
503 parsed_url = util.url(authuri)
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 514 # Mercurial monkey-patching
General Comments 0
You need to be logged in to leave comments. Login now