29 # communicate. If set, use the specified curl command. This could be useful |
29 # communicate. If set, use the specified curl command. This could be useful |
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 [phabricator.auth] |
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 |
41 |
41 |
42 import itertools |
42 import itertools |
98 else: |
98 else: |
99 process(k, v) |
99 process(k, v) |
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 |
104 |
105 |
105 def readlegacytoken(repo, url): |
106 Currently read from [phabricator] config section. In the future, it might |
106 """Transitional support for old phabricator tokens. |
107 make sense to read from .arcconfig and .arcrc as well. |
107 |
108 """ |
108 Remove before the 4.7 release. |
109 url = repo.ui.config('phabricator', 'url') |
109 """ |
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: |
117 repo.ui.warn(_("ignoring invalid [phabricator.auth] key '%s'\n") |
113 repo.ui.warn(_("ignoring invalid [phabricator.auth] key '%s'\n") |
118 % key) |
114 % key) |
126 continue |
122 continue |
127 token = auth.get('token') |
123 token = auth.get('token') |
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 |
137 def callconduit(repo, name, params): |
171 def callconduit(repo, name, params): |
138 """call Conduit API, params is a dict. return json.loads result, or None""" |
172 """call Conduit API, params is a dict. return json.loads result, or None""" |