Show More
@@ -1,52 +1,74 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | """ |
|
3 | """ | |
4 | Storing HTTP authentication passwords in keyring database. |
|
4 | Storing HTTP authentication passwords in keyring database. | |
5 |
|
5 | |||
6 | Installation method(s): |
|
6 | Installation method(s): | |
7 |
|
7 | |||
8 | 1) in ~/.hgrc (or /etc/hgext/...) |
|
8 | 1) in ~/.hgrc (or /etc/hgext/...) | |
9 |
|
9 | |||
10 | [extensions] |
|
10 | [extensions] | |
11 | ... |
|
11 | ... | |
12 | hgext.mercurial_keyring = /path/to/mercurial_keyring.py |
|
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 | from mercurial import hg, repo, util |
|
22 | from mercurial import hg, repo, util | |
17 | from mercurial.i18n import _ |
|
23 | from mercurial.i18n import _ | |
18 | try: |
|
24 | try: | |
19 | from mercurial.url import passwordmgr |
|
25 | from mercurial.url import passwordmgr | |
20 | except: |
|
26 | except: | |
21 | from mercurial.httprepo import passwordmgr |
|
27 | from mercurial.httprepo import passwordmgr | |
22 |
|
28 | |||
23 | import keyring |
|
29 | import keyring | |
24 | import getpass |
|
30 | import getpass | |
25 | from urlparse import urlparse |
|
31 | from urlparse import urlparse | |
26 |
|
32 | |||
27 |
KEYRING_ |
|
33 | KEYRING_SERVICE = "Mercurial" | |
28 |
|
34 | |||
29 | def monkeypatch_method(cls): |
|
35 | def monkeypatch_method(cls): | |
30 | def decorator(func): |
|
36 | def decorator(func): | |
31 | setattr(cls, func.__name__, func) |
|
37 | setattr(cls, func.__name__, func) | |
32 | return func |
|
38 | return func | |
33 | return decorator |
|
39 | return decorator | |
34 |
|
40 | |||
35 | @monkeypatch_method(passwordmgr) |
|
41 | @monkeypatch_method(passwordmgr) | |
36 | def find_user_password(self, realm, authuri): |
|
42 | def find_user_password(self, realm, authuri): | |
37 | """ |
|
43 | """ | |
38 | keyring-based implementation of username/password query |
|
44 | keyring-based implementation of username/password query | |
39 |
|
45 | |||
40 | Passwords are saved in gnome keyring, OSX/Chain or other platform |
|
46 | Passwords are saved in gnome keyring, OSX/Chain or other platform | |
41 | specific storage and keyed by the repository url |
|
47 | specific storage and keyed by the repository url | |
42 | """ |
|
48 | """ | |
43 | # Calculate the true url. authuri happens to contain things like |
|
49 | # Calculate the true url. authuri happens to contain things like | |
44 | # https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between |
|
50 | # https://repo.machine.com/repos/apps/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between | |
45 | parsed_url = urlparse(authuri) |
|
51 | parsed_url = urlparse(authuri) | |
46 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) |
|
52 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) | |
47 |
|
||||
48 | print "find_user_password", realm, base_url |
|
53 | print "find_user_password", realm, base_url | |
49 |
|
54 | |||
50 | # return user, password |
|
55 | ||
51 | return None, None |
|
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