Show More
@@ -79,6 +79,16 b' password_store = PasswordStore()' | |||||
79 |
|
79 | |||
80 | ############################################################ |
|
80 | ############################################################ | |
81 |
|
81 | |||
|
82 | def _debug(ui, msg): | |||
|
83 | ui.debug("[HgKeyring] " + msg) | |||
|
84 | ||||
|
85 | def _debug_reply(ui, msg, url, user, pwd): | |||
|
86 | _debug(ui, "%s. Url: %s, user: %s, passwd: %s\n" % ( | |||
|
87 | msg, url, user, pwd and '*' * len(pwd) or 'not set')) | |||
|
88 | ||||
|
89 | ||||
|
90 | ############################################################ | |||
|
91 | ||||
82 | class HTTPPasswordHandler(object): |
|
92 | class HTTPPasswordHandler(object): | |
83 | """ |
|
93 | """ | |
84 | Actual implementation of password handling (user prompting, |
|
94 | Actual implementation of password handling (user prompting, | |
@@ -113,8 +123,8 b' class HTTPPasswordHandler(object):' | |||||
113 | user, pwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( |
|
123 | user, pwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( | |
114 | pwmgr, realm, authuri) |
|
124 | pwmgr, realm, authuri) | |
115 | if user and pwd: |
|
125 | if user and pwd: | |
116 |
|
|
126 | _debug_reply(ui, _("Auth data found in repository URL"), | |
117 |
|
|
127 | base_url, user, pwd) | |
118 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) |
|
128 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) | |
119 | return user, pwd |
|
129 | return user, pwd | |
120 |
|
130 | |||
@@ -125,7 +135,7 b' class HTTPPasswordHandler(object):' | |||||
125 | keyring_url = prefix_url |
|
135 | keyring_url = prefix_url | |
126 | else: |
|
136 | else: | |
127 | keyring_url = base_url |
|
137 | keyring_url = base_url | |
128 |
ui |
|
138 | _debug(ui, _("Keyring URL: %s\n") % keyring_url) | |
129 |
|
139 | |||
130 | # Checking the memory cache (there may be many http calls per command) |
|
140 | # Checking the memory cache (there may be many http calls per command) | |
131 | cache_key = (realm, keyring_url) |
|
141 | cache_key = (realm, keyring_url) | |
@@ -133,8 +143,8 b' class HTTPPasswordHandler(object):' | |||||
133 | cached_auth = self.pwd_cache.get(cache_key) |
|
143 | cached_auth = self.pwd_cache.get(cache_key) | |
134 | if cached_auth: |
|
144 | if cached_auth: | |
135 | user, pwd = cached_auth |
|
145 | user, pwd = cached_auth | |
136 |
|
|
146 | _debug_reply(ui, _("Cached auth data found"), | |
137 |
|
|
147 | base_url, user, pwd) | |
138 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) |
|
148 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) | |
139 | return user, pwd |
|
149 | return user, pwd | |
140 |
|
150 | |||
@@ -144,26 +154,27 b' class HTTPPasswordHandler(object):' | |||||
144 | user = auth_user |
|
154 | user = auth_user | |
145 | if pwd: |
|
155 | if pwd: | |
146 | self.pwd_cache[cache_key] = user, pwd |
|
156 | self.pwd_cache[cache_key] = user, pwd | |
147 |
|
|
157 | _debug_reply(ui, _("Auth data set in .hg/hgrc"), | |
148 |
|
|
158 | base_url, user, pwd) | |
149 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) |
|
159 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) | |
150 | return user, pwd |
|
160 | return user, pwd | |
151 | else: |
|
161 | else: | |
152 |
ui |
|
162 | _debug(ui, _("Username found in .hg/hgrc: %s\n") % user) | |
153 |
|
163 | |||
154 | # Loading password from keyring. |
|
164 | # Loading password from keyring. | |
155 | # Only if username is known (so we know the key) and we are |
|
165 | # Only if username is known (so we know the key) and we are | |
156 | # not after failure (so we don't reuse the bad password). |
|
166 | # not after failure (so we don't reuse the bad password). | |
157 | if user and not after_bad_auth: |
|
167 | if user and not after_bad_auth: | |
|
168 | _debug(ui, _("Looking for password for user %s and url %s") % (user, keyring_url)) | |||
158 | pwd = password_store.get_http_password(keyring_url, user) |
|
169 | pwd = password_store.get_http_password(keyring_url, user) | |
159 | if pwd: |
|
170 | if pwd: | |
160 | self.pwd_cache[cache_key] = user, pwd |
|
171 | self.pwd_cache[cache_key] = user, pwd | |
161 |
|
|
172 | _debug_reply(ui, _("Keyring password found"), | |
162 |
|
|
173 | base_url, user, pwd) | |
163 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) |
|
174 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) | |
164 | return user, pwd |
|
175 | return user, pwd | |
165 | else: |
|
176 | else: | |
166 |
ui |
|
177 | _debug(ui, _("Password not present in the keyring\n")) | |
167 |
|
178 | |||
168 | # Is the username permanently set? |
|
179 | # Is the username permanently set? | |
169 | fixed_user = (user and True or False) |
|
180 | fixed_user = (user and True or False) | |
@@ -188,14 +199,14 b' class HTTPPasswordHandler(object):' | |||||
188 | # It is done only if username is permanently set. |
|
199 | # It is done only if username is permanently set. | |
189 | # Otherwise we won't be able to find the password so it |
|
200 | # Otherwise we won't be able to find the password so it | |
190 | # does not make much sense to preserve it |
|
201 | # does not make much sense to preserve it | |
191 |
ui |
|
202 | _debug(ui, _("Saving password for %s to keyring\n") % user) | |
192 | password_store.set_http_password(keyring_url, user, pwd) |
|
203 | password_store.set_http_password(keyring_url, user, pwd) | |
193 |
|
204 | |||
194 | # Saving password to the memory cache |
|
205 | # Saving password to the memory cache | |
195 | self.pwd_cache[cache_key] = user, pwd |
|
206 | self.pwd_cache[cache_key] = user, pwd | |
196 |
|
207 | |||
197 |
|
|
208 | _debug_reply(ui, _("Manually entered password"), | |
198 |
|
|
209 | base_url, user, pwd) | |
199 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) |
|
210 | self.last_reply = dict(realm=realm,authuri=authuri,user=user) | |
200 | return user, pwd |
|
211 | return user, pwd | |
201 |
|
212 | |||
@@ -284,10 +295,6 b' class HTTPPasswordHandler(object):' | |||||
284 | return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, |
|
295 | return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, | |
285 | parsed_url.path) |
|
296 | parsed_url.path) | |
286 |
|
297 | |||
287 | def _debug_reply(self, ui, msg, url, user, pwd): |
|
|||
288 | ui.debug("[HgKeyring] " + "%s. Url: %s, user: %s, passwd: %s\n" % ( |
|
|||
289 | msg, url, user, pwd and '*' * len(pwd) or 'not set')) |
|
|||
290 |
|
||||
291 | ############################################################ |
|
298 | ############################################################ | |
292 |
|
299 | |||
293 | @monkeypatch_method(passwordmgr) |
|
300 | @monkeypatch_method(passwordmgr) |
General Comments 0
You need to be logged in to leave comments.
Login now