mirror of
https://github.com/facebook/sapling.git
synced 2024-10-15 19:29:13 +03:00
55171a856b
Summary: The Eden API client in Mercurial should be a singleton. This diff assigns the client to `repo.edenapi` so that it is accessible throughout the code. Reviewed By: quark-zju Differential Revision: D14233314 fbshipit-source-id: 8e0ed22c32611e8f6e7d4461c3e31870d47a0e95
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# Copyright 2018 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from edenscm.mercurial import error, httpconnection
|
|
from edenscm.mercurial.i18n import _
|
|
from edenscm.mercurial.rust.bindings import edenapi
|
|
|
|
from . import shallowutil
|
|
|
|
|
|
def getbaseurl(ui):
|
|
"""Get the base URL of the API server."""
|
|
url = ui.config("edenapi", "url")
|
|
if url is None:
|
|
raise error.Abort(_("No Eden API base URL configured"))
|
|
return url
|
|
|
|
|
|
def getcreds(ui, url):
|
|
"""Get the TLS mutual authentication credentials for the given URL."""
|
|
res = httpconnection.readauthforuri(ui, url, None)
|
|
if res is None:
|
|
return None
|
|
group, auth = res
|
|
if "cert" not in auth or "key" not in auth:
|
|
return None
|
|
return (auth["cert"], auth["key"])
|
|
|
|
|
|
def initclient(ui, repo):
|
|
"""Initialize a new Eden API client using the user's config."""
|
|
url = getbaseurl(ui)
|
|
creds = getcreds(ui, url)
|
|
cachepath = shallowutil.getcachepath(ui)
|
|
return edenapi.client(url, cachepath, repo.name, creds)
|