comparison contrib/phabricator.py @ 37997:71cf20d47f25

phabricator: split auth.url into the standard auth.schemes and auth.prefix It seems better to reuse the existing function to find the proper [auth] block, even if not all of the possible settings may be of interest. The other callers of readauthforuri() make a trip through the password database to fetch the user from the URI. But in the little experimenting I did here, the username always came back as None. Since readauthforuri() wants it to make sure that user@prefix matches user@url, it seems that parsing the URL and pulling out the user component should be equivalent.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 14 May 2018 23:00:30 -0400
parents 0fa050bc68cb
children 5a7cf42ba6ef
comparison
equal deleted inserted replaced
37996:0fa050bc68cb 37997:71cf20d47f25
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
49 from mercurial import ( 51 from mercurial import (
50 cmdutil, 52 cmdutil,
51 context, 53 context,
52 encoding, 54 encoding,
53 error, 55 error,
56 httpconnection as httpconnectionmod,
54 mdiff, 57 mdiff,
55 obsutil, 58 obsutil,
56 parser, 59 parser,
57 patch, 60 patch,
58 registrar, 61 registrar,
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')