Show More
@@ -224,7 +224,7 b' class PasswordStore(object):' | |||||
224 | err) |
|
224 | err) | |
225 | return '' |
|
225 | return '' | |
226 | # Reverse recoding from next routine |
|
226 | # Reverse recoding from next routine | |
227 | if isinstance(password, unicode): |
|
227 | if isinstance(password, meu.pycompat.unicode): | |
228 | return encoding.tolocal(password.encode('utf-8')) |
|
228 | return encoding.tolocal(password.encode('utf-8')) | |
229 | return password |
|
229 | return password | |
230 |
|
230 | |||
@@ -251,11 +251,6 b' password_store = PasswordStore()' | |||||
251 | # Various utils |
|
251 | # Various utils | |
252 | ############################################################ |
|
252 | ############################################################ | |
253 |
|
253 | |||
254 | def _debug(ui, msg): |
|
|||
255 | """Generic debug message""" |
|
|||
256 | ui.debug("keyring: " + msg + "\n") |
|
|||
257 |
|
||||
258 |
|
||||
259 | class PwdCache(object): |
|
254 | class PwdCache(object): | |
260 | """Short term cache, used to preserve passwords |
|
255 | """Short term cache, used to preserve passwords | |
261 | if they are used twice during a command""" |
|
256 | if they are used twice during a command""" | |
@@ -328,9 +323,9 b' class HTTPPasswordHandler(object):' | |||||
328 | ui = pwmgr.ui |
|
323 | ui = pwmgr.ui | |
329 |
|
324 | |||
330 | parsed_url, url_user, url_passwd = self.unpack_url(authuri) |
|
325 | parsed_url, url_user, url_passwd = self.unpack_url(authuri) | |
331 |
base_url = |
|
326 | base_url = bytes(parsed_url) | |
332 |
ui.debug( |
|
327 | ui.debug(b'keyring: base url: %s, url user: %s, url pwd: %s\n' % | |
333 | (base_url, url_user or '', url_passwd and '******' or '')) |
|
328 | (base_url, url_user or b'', url_passwd and b'******' or b'')) | |
334 |
|
329 | |||
335 | # Extract username (or password) stored directly in url |
|
330 | # Extract username (or password) stored directly in url | |
336 | if url_user and url_passwd: |
|
331 | if url_user and url_passwd: | |
@@ -371,7 +366,7 b' class HTTPPasswordHandler(object):' | |||||
371 |
|
366 | |||
372 | # Load from keyring. |
|
367 | # Load from keyring. | |
373 | if actual_user: |
|
368 | if actual_user: | |
374 |
ui.debug( |
|
369 | ui.debug(b"keyring: looking for password (user %s, url %s)\n" % | |
375 | (actual_user, keyring_url)) |
|
370 | (actual_user, keyring_url)) | |
376 | keyring_pwd = password_store.get_http_password(keyring_url, actual_user) |
|
371 | keyring_pwd = password_store.get_http_password(keyring_url, actual_user) | |
377 | if keyring_pwd: |
|
372 | if keyring_pwd: | |
@@ -389,10 +384,10 b' class HTTPPasswordHandler(object):' | |||||
389 | ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) |
|
384 | ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n")) | |
390 |
|
385 | |||
391 | ui.write(_("http authorization required\n")) |
|
386 | ui.write(_("http authorization required\n")) | |
392 | ui.status(_("realm: %s\n") % realm) |
|
387 | ui.status(_("realm: %s\n") % meu.pycompat.bytestr(realm)) | |
393 | ui.status(_("url: %s\n") % url) |
|
388 | ui.status(_("url: %s\n") % url) | |
394 | if user: |
|
389 | if user: | |
395 |
ui.write(_("user: %s (fixed in hgrc or url)\n" |
|
390 | ui.write(_("user: %s (fixed in hgrc or url)\n") % user) | |
396 | else: |
|
391 | else: | |
397 | user = ui.prompt(_("user:"), default=None) |
|
392 | user = ui.prompt(_("user:"), default=None) | |
398 | pwd = ui.getpass(_("password: ")) |
|
393 | pwd = ui.getpass(_("password: ")) | |
@@ -415,7 +410,7 b' class HTTPPasswordHandler(object):' | |||||
415 | if src != self.SRC_MEMCACHE: |
|
410 | if src != self.SRC_MEMCACHE: | |
416 | self.pwd_cache.store(realm, final_url, user, pwd) |
|
411 | self.pwd_cache.store(realm, final_url, user, pwd) | |
417 | self._note_last_reply(realm, authuri, user, req) |
|
412 | self._note_last_reply(realm, authuri, user, req) | |
418 |
|
|
413 | ui.debug("keyring: Password found in %s\n" % src) | |
419 | return user, pwd |
|
414 | return user, pwd | |
420 |
|
415 | |||
421 | # Last resort: interactive prompt |
|
416 | # Last resort: interactive prompt | |
@@ -426,7 +421,7 b' class HTTPPasswordHandler(object):' | |||||
426 | # It is done only if username is permanently set. |
|
421 | # It is done only if username is permanently set. | |
427 | # Otherwise we won't be able to find the password so it |
|
422 | # Otherwise we won't be able to find the password so it | |
428 | # does not make much sense to preserve it |
|
423 | # does not make much sense to preserve it | |
429 |
|
|
424 | ui.debug("keyring: Saving password for %s to keyring\n" % user) | |
430 | try: |
|
425 | try: | |
431 | password_store.set_http_password(final_url, user, pwd) |
|
426 | password_store.set_http_password(final_url, user, pwd) | |
432 | except Exception as e: |
|
427 | except Exception as e: | |
@@ -440,7 +435,7 b' class HTTPPasswordHandler(object):' | |||||
440 | # Saving password to the memory cache |
|
435 | # Saving password to the memory cache | |
441 | self.pwd_cache.store(realm, final_url, user, pwd) |
|
436 | self.pwd_cache.store(realm, final_url, user, pwd) | |
442 | self._note_last_reply(realm, authuri, user, req) |
|
437 | self._note_last_reply(realm, authuri, user, req) | |
443 |
|
|
438 | ui.debug("keyring: Manually entered password\n") | |
444 | return user, pwd |
|
439 | return user, pwd | |
445 |
|
440 | |||
446 | def get_url_config(self, ui, parsed_url, user): |
|
441 | def get_url_config(self, ui, parsed_url, user): | |
@@ -452,10 +447,10 b' class HTTPPasswordHandler(object):' | |||||
452 | found. username and password can be None (if unset), if prefix |
|
447 | found. username and password can be None (if unset), if prefix | |
453 | is not found, url itself is returned. |
|
448 | is not found, url itself is returned. | |
454 | """ |
|
449 | """ | |
455 |
base_url = |
|
450 | base_url = bytes(parsed_url) | |
456 |
|
451 | |||
457 | from mercurial.httpconnection import readauthforuri |
|
452 | from mercurial.httpconnection import readauthforuri | |
458 |
|
|
453 | ui.debug(b"keyring: checking for hgrc info about url %s, user %s\n" % (base_url, user)) | |
459 | res = readauthforuri(ui, base_url, user) |
|
454 | res = readauthforuri(ui, base_url, user) | |
460 | # If it user-less version not work, let's try with added username to handle |
|
455 | # If it user-less version not work, let's try with added username to handle | |
461 | # both config conventions |
|
456 | # both config conventions | |
@@ -479,8 +474,8 b' class HTTPPasswordHandler(object):' | |||||
479 |
|
474 | |||
480 | password_url = self.password_url(base_url, prefix) |
|
475 | password_url = self.password_url(base_url, prefix) | |
481 |
|
476 | |||
482 |
|
|
477 | ui.debug(b"keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n" % ( | |
483 | password_url, username, '********' if password else '', prefix)) |
|
478 | password_url, username or b'', b'********' if password else b'', prefix or b'')) | |
484 |
|
479 | |||
485 | return username, password, password_url |
|
480 | return username, password, password_url | |
486 |
|
481 | |||
@@ -505,7 +500,8 b' class HTTPPasswordHandler(object):' | |||||
505 | if (self.last_reply['realm'] == realm) \ |
|
500 | if (self.last_reply['realm'] == realm) \ | |
506 | and (self.last_reply['authuri'] == authuri) \ |
|
501 | and (self.last_reply['authuri'] == authuri) \ | |
507 | and (self.last_reply['req'] == req): |
|
502 | and (self.last_reply['req'] == req): | |
508 |
|
|
503 | ui.debug("keyring: Working after bad authentication, cached passwords not used %s\n" % | |
|
504 | str(self.last_reply)) | |||
509 | return True |
|
505 | return True | |
510 | return False |
|
506 | return False | |
511 |
|
507 | |||
@@ -542,11 +538,12 b' class HTTPPasswordHandler(object):' | |||||
542 | where url is mercurial.util.url object already stripped of all those |
|
538 | where url is mercurial.util.url object already stripped of all those | |
543 | params. |
|
539 | params. | |
544 | """ |
|
540 | """ | |
545 | import pdb; pdb.set_trace() |
|
541 | # In case of py3, util.url expects bytes | |
|
542 | authuri = meu.pycompat.bytestr(authuri) | |||
546 |
|
543 | |||
547 | # mercurial.util.url, rather handy url parser |
|
544 | # mercurial.util.url, rather handy url parser | |
548 | parsed_url = util.url(authuri) |
|
545 | parsed_url = util.url(authuri) | |
549 | parsed_url.query = '' |
|
546 | parsed_url.query = b'' | |
550 | parsed_url.fragment = None |
|
547 | parsed_url.fragment = None | |
551 | # Strip arguments to get actual remote repository url. |
|
548 | # Strip arguments to get actual remote repository url. | |
552 | # base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, |
|
549 | # base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, |
General Comments 0
You need to be logged in to leave comments.
Login now