Show More
@@ -1,52 +1,74 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | """ |
|
4 | 4 | Storing HTTP authentication passwords in keyring database. |
|
5 | 5 | |
|
6 | 6 | Installation method(s): |
|
7 | 7 | |
|
8 | 8 | 1) in ~/.hgrc (or /etc/hgext/...) |
|
9 | 9 | |
|
10 | 10 | [extensions] |
|
11 | 11 | ... |
|
12 | 12 | hgext.mercurial_keyring = /path/to/mercurial_keyring.py |
|
13 | 13 | |
|
14 | ||
|
15 | 2) Drop this file to hgext directory and in ~/.hgrc | |
|
16 | ||
|
17 | [extensions] | |
|
18 | hgext.mercurial_keyring = | |
|
19 | ||
|
14 | 20 | """ |
|
15 | 21 | |
|
16 | 22 | from mercurial import hg, repo, util |
|
17 | 23 | from mercurial.i18n import _ |
|
18 | 24 | try: |
|
19 | 25 | from mercurial.url import passwordmgr |
|
20 | 26 | except: |
|
21 | 27 | from mercurial.httprepo import passwordmgr |
|
22 | 28 | |
|
23 | 29 | import keyring |
|
24 | 30 | import getpass |
|
25 | 31 | from urlparse import urlparse |
|
26 | 32 | |
|
27 |
KEYRING_ |
|
|
33 | KEYRING_SERVICE = "Mercurial" | |
|
28 | 34 | |
|
29 | 35 | def monkeypatch_method(cls): |
|
30 | 36 | def decorator(func): |
|
31 | 37 | setattr(cls, func.__name__, func) |
|
32 | 38 | return func |
|
33 | 39 | return decorator |
|
34 | 40 | |
|
35 | 41 | @monkeypatch_method(passwordmgr) |
|
36 | 42 | def find_user_password(self, realm, authuri): |
|
37 | 43 | """ |
|
38 | 44 | keyring-based implementation of username/password query |
|
39 | 45 | |
|
40 | 46 | Passwords are saved in gnome keyring, OSX/Chain or other platform |
|
41 | 47 | specific storage and keyed by the repository url |
|
42 | 48 | """ |
|
43 | 49 | # Calculate the true url. authuri happens to contain things like |
|
44 | 50 | # https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between |
|
45 | 51 | parsed_url = urlparse(authuri) |
|
46 | 52 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) |
|
47 | ||
|
48 | 53 | print "find_user_password", realm, base_url |
|
49 | 54 | |
|
50 | # return user, password | |
|
51 | return None, None | |
|
55 | ||
|
56 | # TODO: odczyt danych z cache w procesie | |
|
57 | ||
|
58 | # TODO: odczyt danych już obecnych w keyring-u | |
|
59 | ||
|
60 | if not self.ui.interactive(): | |
|
61 | raise util.Abort(_('mercurial_keyring: http authorization required')) | |
|
62 | self.ui.write(_("http authorization required\n")) | |
|
63 | self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url))) | |
|
64 | username = self.ui.prompt(_("user:"), default = None) | |
|
65 | password = self.ui.getpass(_("password for user %s:" % username)) | |
|
52 | 66 | |
|
67 | # TODO: zapis w keyringu | |
|
68 | ||
|
69 | # TODO: zapis w cache w procesie | |
|
70 | ||
|
71 | ||
|
72 | return username, password | |
|
73 | #return None, None | |
|
74 |
General Comments 0
You need to be logged in to leave comments.
Login now