30 # if you need to specify advanced options that is not easily supported by |
30 # if you need to specify advanced options that is not easily supported by |
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 [auth] |
34 [auth] |
35 example.url = https://phab.example.com/ |
35 example.schemes = https |
|
36 example.prefix = phab.example.com |
|
37 |
36 # API token. Get it from https://$HOST/conduit/login/ |
38 # API token. Get it from https://$HOST/conduit/login/ |
37 example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
39 example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
38 """ |
40 """ |
39 |
41 |
40 from __future__ import absolute_import |
42 from __future__ import absolute_import |
133 return token |
136 return token |
134 |
137 |
135 def readurltoken(repo): |
138 def readurltoken(repo): |
136 """return conduit url, token and make sure they exist |
139 """return conduit url, token and make sure they exist |
137 |
140 |
138 Currently read from [phabricator] config section. In the future, it might |
141 Currently read from [auth] config section. In the future, it might |
139 make sense to read from .arcconfig and .arcrc as well. |
142 make sense to read from .arcconfig and .arcrc as well. |
140 """ |
143 """ |
141 url = repo.ui.config('phabricator', 'url') |
144 url = repo.ui.config('phabricator', 'url') |
142 if not url: |
145 if not url: |
143 raise error.Abort(_('config %s.%s is required') |
146 raise error.Abort(_('config %s.%s is required') |
144 % ('phabricator', 'url')) |
147 % ('phabricator', 'url')) |
145 |
148 |
146 groups = {} |
149 res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user) |
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 |
150 token = None |
156 for group, auth in groups.iteritems(): |
151 |
157 if url != auth.get('url'): |
152 if res: |
158 continue |
153 group, auth = res |
|
154 |
|
155 repo.ui.debug("using auth.%s.* for authentication\n" % group) |
|
156 |
159 token = auth.get('phabtoken') |
157 token = auth.get('phabtoken') |
160 if token: |
|
161 break |
|
162 |
158 |
163 if not token: |
159 if not token: |
164 token = readlegacytoken(repo, url) |
160 token = readlegacytoken(repo, url) |
165 if not token: |
161 if not token: |
166 raise error.Abort(_('Can\'t find conduit token associated to %s') |
162 raise error.Abort(_('Can\'t find conduit token associated to %s') |