phabricator: make conduit auth more flexible

Summary:
We've modified arcanist a while ago so that if it doesn't find user/cert information for the specific URL that it's using, it just picks the user/cert information from any other URL in ~/.arcrc.  This is because it's essentially always the same user, and always the same cert, so there's really no point in being too picky.
This updates hg extension to be almost as careless.  It will attempt to find the matching user/cert, but if it doesn't work, it'll just pick any cert if available.

Test Plan:
Without this change, "hg ssl" in a recent version of www reports an warning because www/.arcconfig has phabricator.intern.facebook.com, where default ~/.arcrc's have phabricator.fb.com.
With this change, "hg ssl" succeeds to display revision information because it is once again able to authenticate with conduit

Reviewers: #phabricator, rmcelroy

Reviewed By: rmcelroy

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4964111

Tasks: 17683952

Signature: t1:4964111:1493323636:668b50ce2d20d720ba3de573de05be5251ce3310
This commit is contained in:
Mark Edson 2017-04-27 13:45:50 -07:00
parent 7e191da991
commit 36d60f5259

View File

@ -15,7 +15,7 @@ import arcconfig
urlreq = util.urlreq
DEFAULT_HOST = 'https://phabricator.fb.com/api/'
DEFAULT_HOST = 'https://phabricator.intern.facebook.com/api/'
DEFAULT_TIMEOUT = 60
mocked_responses = None
@ -39,8 +39,15 @@ class Client(object):
self._user = hostconfig['user']
self._cert = hostconfig['cert']
except KeyError:
raise arcconfig.ArcConfigError('arcrc is missing user credentials '
'for host %s' % self._host)
try:
hostconfig = config['hosts'][config['hosts'].keys()[0]]
self._user = hostconfig['user']
self._cert = hostconfig['cert']
except KeyError:
raise arcconfig.ArcConfigError(
'arcrc is missing user '
'credentials for host %s. use '
'"arc install-certificate" to fix.' % self._host)
self._actas = self._user
self._connection = None