[PATCH] phabricator: migrate [phabricator.auth] to [auth]

Matt Harbison mharbison72 at gmail.com
Sat May 12 00:36:58 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1526099641 14400
#      Sat May 12 00:34:01 2018 -0400
# Node ID 6c6d0679de6cca2d740874812d87a649f8d8dde8
# Parent  b9e6b71dc27246d1f4d6437edfdc9788188aa306
phabricator: migrate [phabricator.auth] to [auth]

This resurrects the warning mechanism removed in 20a4543e9a2b.  I'm not worried
about the copy/paste of the code for a brief transitional period.

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -31,10 +31,10 @@ Config::
     # the internal library.
     curlcmd = curl --connect-timeout 2 --retry 3 --silent
 
-    [phabricator.auth]
+    [auth]
     example.url = https://phab.example.com/
     # API token. Get it from https://$HOST/conduit/login/
-    example.token = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
+    example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
 """
 
 from __future__ import absolute_import
@@ -100,16 +100,15 @@ def urlencodenested(params):
     process('', params)
     return util.urlreq.urlencode(flatparams)
 
-def readurltoken(repo):
-    """return conduit url, token and make sure they exist
+printed_token_warning = False
+
+def readlegacytoken(repo, url):
+    """Transitional support for old phabricator tokens.
 
-    Currently read from [phabricator] config section. In the future, it might
-    make sense to read from .arcconfig and .arcrc as well.
+    Remove before the 4.7 release.
     """
-    url = repo.ui.config('phabricator', 'url')
-    if not url:
-        raise error.Abort(_('config %s.%s is required')
-                          % ('phabricator', 'url'))
+    global printed_token_warning
+    token = repo.ui.config('phabricator.auth', 'token')
 
     groups = {}
     for key, val in repo.ui.configitems('phabricator.auth'):
@@ -128,9 +127,45 @@ def readurltoken(repo):
         if token:
             break
 
+    if token and not printed_token_warning:
+        printed_token_warning = True
+        repo.ui.warn(_('phabricator.auth.token is deprecated - please '
+                       'migrate to auth.phabtoken.\n'))
+    return token
+
+def readurltoken(repo):
+    """return conduit url, token and make sure they exist
+
+    Currently read from [phabricator] config section. In the future, it might
+    make sense to read from .arcconfig and .arcrc as well.
+    """
+    url = repo.ui.config('phabricator', 'url')
+    if not url:
+        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
+
+    token = None
+    for group, auth in groups.iteritems():
+        if url != auth.get('url'):
+            continue
+        token = auth.get('phabtoken')
+        if token:
+            break
+
     if not token:
-        raise error.Abort(_('Can\'t find conduit token associated to %s')
-                          % (url,))
+        token = readlegacytoken(repo, url)
+        if not token:
+            raise error.Abort(_('Can\'t find conduit token associated to %s')
+                              % (url,))
 
     return url, token
 


More information about the Mercurial-devel mailing list