Exemplo n.º 1
0
def remote(ui):
    """remotestore factory. return a store in _storemap depending on config"""
    url = util.url(ui.config("lfs", "url"))
    scheme = url.scheme
    if scheme not in _storemap:
        raise error.Abort(_("lfs: unknown url scheme: %s") % scheme)
    return _storemap[scheme](ui, url)
Exemplo n.º 2
0
def activepath(ui, remote):
    local = None
    try:
        local = remote.local()
    except AttributeError:
        pass

    # determine the remote path from the repo, if possible; else just
    # use the string given to us
    rpath = remote
    if local:
        rpath = getattr(remote, "root", None)
        if rpath is None:
            # Maybe a localpeer? (hg@1ac628cd7113, 2.3)
            rpath = getattr(getattr(remote, "_repo", None), "root", None)
    elif not isinstance(remote, str):
        try:
            rpath = _normalizeremote(remote.url())
        except AttributeError:
            # Handled by "isinstance(rpath, basestring)" below
            pass
    else:
        rpath = _normalizeremote(rpath)

    candidates = []
    for path, uri in ui.configitems("paths"):
        if local:
            uri = os.path.realpath(uri)
        else:
            uri = _normalizeremote(uri)
            if uri.startswith("http"):
                try:
                    uri = util.url(uri).authinfo()[0]
                except AttributeError:
                    uri = url.getauthinfo(uri)[0]
        uri = uri.rstrip("/")
        rpath = rpath.rstrip("/")
        if uri == rpath:
            candidates.append(path)

    if not candidates:
        return ""

    # Prefer default paths
    for preferred in ["default", "default-push"]:
        if preferred in candidates:
            bestpath = preferred
            break
    else:
        # Otherwise, pick the shortest (using a stable ordering).
        # Use alphabetical to break ties in length.
        candidates.sort()  # alphabetical
        candidates.sort(
            key=len)  # sort is stable so first will be the correct one
        bestpath = candidates[0]

    renames = _getrenames(ui)
    realpath = renames.get(bestpath, bestpath)
    return realpath
Exemplo n.º 3
0
    def _setuphttpsconnection(self):
        # setting up HTTS connection

        # enable client side compression
        # data in the response is also requested compressed
        self.headers = {
            "Connection": "keep-alive",
            "Content-Type": "application/json",
            "Accept-Encoding": "none, gzip",
            "Content-Encoding": "gzip",
        }
        if self.token:
            self.headers["Authorization"] = "OAuth %s" % self.token

        u = util.url(self.url, parsequery=False, parsefragment=False)
        if u.scheme != "https" or not u.host or u.passwd is not None:
            raise ccerror.ConfigurationError(
                self.ui, _("'commitcloud.url' is invalid or unsupported"))

        remotehost = u.host
        remoteport = int(u.port) if u.port else 443

        sslcontext = ssl.create_default_context()

        # if the token is not set, use the same TLS auth to connect to the Commit Cloud service
        # as it is used to connect to the default path
        if not self.token:
            path = ccutil.getremotepath(self.ui)
            authdata = httpconnection.readauthforuri(self.ui, path, u.user)
            if authdata:
                (authname, auth) = authdata
                cert = auth.get("cert")
                key = auth.get("key")
                cacerts = auth.get("cacerts")
                sslcontext.load_cert_chain(cert, keyfile=key)
                if cacerts:
                    sslcontext.load_verify_locations(cacerts)
            else:
                raise ccerror.TLSConfigurationError(
                    self.ui,
                    _("no certificates have been found to connect to the Commit Cloud Service"
                      ),
                )

        self.connection = httpclient.HTTPConnection(
            remotehost,
            remoteport,
            timeout=DEFAULT_TIMEOUT,
            use_ssl=True,
            ssl_wrap_socket=sslcontext.wrap_socket,
        )

        self.ui.debug(
            "will be connecting to %s:%d\n" % (remotehost, remoteport),
            component="commitcloud",
        )
Exemplo n.º 4
0
def debugnetwork(ui, repo, remote="default", **opts):
    """debug the network connection to a remote"""

    alltests = not any(opts.get(opt) for opt in ["connection", "speed"])

    ui.status(_("Remote name: %s\n") % remote, component="debugnetwork")

    path, branches = hg.parseurl(repo.ui.expandpath(remote))
    ui.status(_("Remote url: %s\n") % path, component="debugnetwork")

    url = util.url(path)

    if url.scheme == "ssh":
        checkspeed = checkhgspeed
        checkserverhostname = checksshcommand
        servertype = "Mercurial"
    else:
        checkspeed = checkspeedhttp
        checkserverhostname = checkmononokehost
        servertype = "Mononoke"
        if url.port is None:
            url.port = "443"

    if alltests or opts.get("connection"):
        addrinfos = checkdnsresolution(ui, url)
        if not addrinfos:
            msg = _("Failed to look-up the server in DNS.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 2

        if not checkreachability(ui, url, addrinfos):
            msg = _("Failed to connect to the server on any address.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 3

        if not checkserverhostname(ui, url, opts):
            msg = _("Failed to connect to check %s server hostname.\n"
                    ) % servertype
            ui.status(msg, component=_("debugnetwork"))
            return 4

        if servertype == "Mercurial" and not checkhgserver(
                ui, repo, opts, path):
            msg = _("Failed to connect to Mercurial on the server.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 5

    if alltests or opts.get("speed"):
        if not checkspeed(ui, url, opts):
            msg = _(
                "Failed to check %s server connection speed.\n") % servertype
            ui.status(msg, component=_("debugnetwork"))
            return 6
Exemplo n.º 5
0
def _normalizeremote(remote):
    """
    Normalises a remote for grouping

    Remote URL can have QueryStrings or Fragments which we consider to be
    parameters, rather then being part of the repo path. So normalization strips
    away the QueryString and Fragments and returns the stripped remote.
    """
    u = util.url(remote)
    u.query = None
    u.fragment = None
    return str(u)
Exemplo n.º 6
0
def debugnetwork(ui, repo, remote="default", **opts):
    """debug the network connection to a remote"""

    alltests = not any(opts.get(opt) for opt in ["connection", "speed"])

    ui.status(_("Remote name: %s\n") % remote, component="debugnetwork")

    path, branches = hg.parseurl(repo.ui.expandpath(remote))
    ui.status(_("Remote url: %s\n") % path, component="debugnetwork")

    url = util.url(path)
    if url.scheme != "ssh":
        ui.status(_("Not checking network as remote is not an ssh peer"))
        return 1

    if alltests or opts.get("connection"):
        addrinfos = checkdnsresolution(ui, url)
        if not addrinfos:
            msg = _("Failed to look-up the server in DNS.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 2

        if not checkreachability(ui, url, addrinfos):
            msg = _("Failed to connect to the server on any address.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 3

        if not checksshcommand(ui, url, opts):
            msg = _("Failed to connect to SSH on the server.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 4

        if not checkhgserver(ui, repo, opts, path):
            msg = _("Failed to connect to Mercurial on the server.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 5

    if alltests or opts.get("speed"):
        if not checkhgspeed(ui, url, opts):
            msg = _("Failed to check Mercurial server connection speed.\n")
            ui.status(msg, component=_("debugnetwork"))
            return 6
Exemplo n.º 7
0
def islocal(path):
    if isgitsshuri(path):
        return True

    u = util.url(path)
    return not u.scheme or u.scheme == "file"