Show More
@@ -31,10 +31,10 b' Config::' | |||||
31 | # the internal library. |
|
31 | # the internal library. | |
32 | curlcmd = curl --connect-timeout 2 --retry 3 --silent |
|
32 | curlcmd = curl --connect-timeout 2 --retry 3 --silent | |
33 |
|
33 | |||
34 |
[ |
|
34 | [auth] | |
35 | example.url = https://phab.example.com/ |
|
35 | example.url = https://phab.example.com/ | |
36 | # API token. Get it from https://$HOST/conduit/login/ |
|
36 | # API token. Get it from https://$HOST/conduit/login/ | |
37 | example.token = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
37 | example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
38 | """ |
|
38 | """ | |
39 |
|
39 | |||
40 | from __future__ import absolute_import |
|
40 | from __future__ import absolute_import | |
@@ -100,17 +100,13 b' def urlencodenested(params):' | |||||
100 | process('', params) |
|
100 | process('', params) | |
101 | return util.urlreq.urlencode(flatparams) |
|
101 | return util.urlreq.urlencode(flatparams) | |
102 |
|
102 | |||
103 | def readurltoken(repo): |
|
103 | printed_token_warning = False | |
104 | """return conduit url, token and make sure they exist |
|
|||
105 |
|
104 | |||
106 | Currently read from [phabricator] config section. In the future, it might |
|
105 | def readlegacytoken(repo, url): | |
107 | make sense to read from .arcconfig and .arcrc as well. |
|
106 | """Transitional support for old phabricator tokens. | |
|
107 | ||||
|
108 | Remove before the 4.7 release. | |||
108 | """ |
|
109 | """ | |
109 | url = repo.ui.config('phabricator', 'url') |
|
|||
110 | if not url: |
|
|||
111 | raise error.Abort(_('config %s.%s is required') |
|
|||
112 | % ('phabricator', 'url')) |
|
|||
113 |
|
||||
114 | groups = {} |
|
110 | groups = {} | |
115 | for key, val in repo.ui.configitems('phabricator.auth'): |
|
111 | for key, val in repo.ui.configitems('phabricator.auth'): | |
116 | if '.' not in key: |
|
112 | if '.' not in key: | |
@@ -128,9 +124,47 b' def readurltoken(repo):' | |||||
128 | if token: |
|
124 | if token: | |
129 | break |
|
125 | break | |
130 |
|
126 | |||
|
127 | global printed_token_warning | |||
|
128 | ||||
|
129 | if token and not printed_token_warning: | |||
|
130 | printed_token_warning = True | |||
|
131 | repo.ui.warn(_('phabricator.auth.token is deprecated - please ' | |||
|
132 | 'migrate to auth.phabtoken.\n')) | |||
|
133 | return token | |||
|
134 | ||||
|
135 | def readurltoken(repo): | |||
|
136 | """return conduit url, token and make sure they exist | |||
|
137 | ||||
|
138 | Currently read from [phabricator] config section. In the future, it might | |||
|
139 | make sense to read from .arcconfig and .arcrc as well. | |||
|
140 | """ | |||
|
141 | url = repo.ui.config('phabricator', 'url') | |||
|
142 | if not url: | |||
|
143 | raise error.Abort(_('config %s.%s is required') | |||
|
144 | % ('phabricator', 'url')) | |||
|
145 | ||||
|
146 | groups = {} | |||
|
147 | for key, val in repo.ui.configitems('auth'): | |||
|
148 | if '.' not in key: | |||
|
149 | repo.ui.warn(_("ignoring invalid [auth] key '%s'\n") | |||
|
150 | % key) | |||
|
151 | continue | |||
|
152 | group, setting = key.rsplit('.', 1) | |||
|
153 | groups.setdefault(group, {})[setting] = val | |||
|
154 | ||||
|
155 | token = None | |||
|
156 | for group, auth in groups.iteritems(): | |||
|
157 | if url != auth.get('url'): | |||
|
158 | continue | |||
|
159 | token = auth.get('phabtoken') | |||
|
160 | if token: | |||
|
161 | break | |||
|
162 | ||||
131 | if not token: |
|
163 | if not token: | |
132 | raise error.Abort(_('Can\'t find conduit token associated to %s') |
|
164 | token = readlegacytoken(repo, url) | |
133 | % (url,)) |
|
165 | if not token: | |
|
166 | raise error.Abort(_('Can\'t find conduit token associated to %s') | |||
|
167 | % (url,)) | |||
134 |
|
168 | |||
135 | return url, token |
|
169 | return url, token | |
136 |
|
170 |
General Comments 0
You need to be logged in to leave comments.
Login now