changeset 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 5fa4e29ba3e3
files contrib/phabricator.py
diffstat 1 files changed, 12 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/phabricator.py	Sat May 12 00:34:01 2018 -0400
+++ b/contrib/phabricator.py	Mon May 14 23:00:30 2018 -0400
@@ -32,7 +32,9 @@
     curlcmd = curl --connect-timeout 2 --retry 3 --silent
 
     [auth]
-    example.url = https://phab.example.com/
+    example.schemes = https
+    example.prefix = phab.example.com
+
     # API token. Get it from https://$HOST/conduit/login/
     example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
 """
@@ -51,6 +53,7 @@
     context,
     encoding,
     error,
+    httpconnection as httpconnectionmod,
     mdiff,
     obsutil,
     parser,
@@ -135,7 +138,7 @@
 def readurltoken(repo):
     """return conduit url, token and make sure they exist
 
-    Currently read from [phabricator] config section. In the future, it might
+    Currently read from [auth] config section. In the future, it might
     make sense to read from .arcconfig and .arcrc as well.
     """
     url = repo.ui.config('phabricator', 'url')
@@ -143,22 +146,15 @@
         raise error.Abort(_('config %s.%s is required')
                           % ('phabricator', 'url'))
 
-    groups = {}
-    for key, val in repo.ui.configitems('auth'):
-        if '.' not in key:
-            repo.ui.warn(_("ignoring invalid [auth] key '%s'\n")
-                         % key)
-            continue
-        group, setting = key.rsplit('.', 1)
-        groups.setdefault(group, {})[setting] = val
+    res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user)
+    token = None
 
-    token = None
-    for group, auth in groups.iteritems():
-        if url != auth.get('url'):
-            continue
+    if res:
+        group, auth = res
+
+        repo.ui.debug("using auth.%s.* for authentication\n" % group)
+
         token = auth.get('phabtoken')
-        if token:
-            break
 
     if not token:
         token = readlegacytoken(repo, url)