diff easyhg.py @ 451:8156537329ff

Associate password with scheme+host+user rather than url+user
author Chris Cannam
date Wed, 29 Jun 2011 13:40:57 +0100
parents 568abb678073
children d0b7dbc3ba46
line wrap: on
line diff
--- a/easyhg.py	Wed Jun 29 13:36:07 2011 +0100
+++ b/easyhg.py	Wed Jun 29 13:40:57 2011 +0100
@@ -76,9 +76,13 @@
     (salt, d, text) = text.partition('.')
     return text[0:int(tlen)]
 
+def pathless_url(url):
+    parsed_url = urlparse.urlparse(url)
+    return "%s://%s" % (parsed_url.scheme, parsed_url.netloc)
+
 # from mercurial_keyring by Marcin Kasperski
-def canonical_url(authuri):
-    parsed_url = urlparse.urlparse(authuri)
+def canonical_url(url):
+    parsed_url = urlparse.urlparse(url)
     return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc,
                           parsed_url.path)
 
@@ -170,6 +174,7 @@
 #    self.ui.write("want username and/or password for %s\n" % authuri)
 
     short_uri = canonical_url(authuri)
+    pathless_uri = pathless_url(authuri)
 
     authkey = self.ui.config('easyhg', 'authkey')
     authfile = self.ui.config('easyhg', 'authfile')
@@ -220,7 +225,7 @@
 
         if not passwd:
             authdata = get_from_config(authconfig, 'auth',
-                                       remote_key(short_uri, user, authkey))
+                                       remote_key(pathless_uri, user, authkey))
             if authdata:
                 passwd = decrypt_salted(authdata, authkey)
                 passwd_field.setText(passwd)
@@ -270,9 +275,9 @@
         if passwd:
             if remember:
                 authdata = encrypt_salted(passwd, authkey)
-                set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), authdata)
+                set_to_config(authconfig, 'auth', remote_key(pathless_uri, user, authkey), authdata)
             else:
-                set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), '')
+                set_to_config(authconfig, 'auth', remote_key(pathless_uri, user, authkey), '')
         save_config(self.ui, authconfig, authfile)
 
     self.add_password(realm, authuri, user, passwd)