git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fwd: "reverse proxy" remote-helper

From
GFGuga Figueiredo <gugabfigueiredo@gmail.com>
Date
Apr 1, 2024, 17:37 UTC
Message-ID
<CAEK6H9r7NbPpcTiOk7E8ZTr1W_rfarLmU_yT1etDiCs6BaERVw@mail.gmail.com>
In-Reply-To
<CAEK6H9o2QQGLQQZ0=C=1CjRGg6UiD_0fv7MwQujv1Sa_v41TAw@mail.gmail.com>
Hello,

I am playing around with git remote helpers trying to write a "reverse proxy" sort of custom helper to work with a personal server and custom protocol. I am doing this because git, natively, already does 99% of the work that I need, and I would like to avoid reinventing the wheel. I just want to create a barely customized interface for a custom server. I know I can achieve this with hooks, but I would rather keep this configuration out of the repos.

conceptually, the command call flow should be something like this:
```
git <cmd> custom::<repo-url>
└──>git-remote-custom <repo-url> <cmd>
    └──>git <native-remote-helper> <repo-url> <cmd>
```

I have been able to implement a git remote helper in go that works on locally stored remotes following this article by rovaugn and the git documentation on helpers.

And have stripped it down to bare essentials to try to invoke the native/builtin remote-helpers directly: ```go package main

import (
    "errors"
    "fmt"
    "log"
    "net/url"
    "os"
    "os/exec"
    "regexp"
)
func Main() (er error) {
    if len(os.Args) < 3 {
       return fmt.Errorf("Usage: git-remote-custom remote-name remote-url")
    }
    remoteName := os.Args[1]
    remoteUrl := os.Args[2]
    scheme, err := parseRemoteURL(remoteUrl)
    if err != nil {
       return fmt.Errorf("Invalid remote URL %s: %v", remoteUrl, err)
    }
    // do custom stuff here ...
    // proxy through to native git remote helper
    cmd := exec.Command("git", fmt.Sprintf("remote-%s", scheme),
remoteName, remoteUrl)
    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    if err := cmd.Run(); err != nil {
       return err
    }
    return nil
}
func main() {
    if err := Main(); err != nil {
       log.Fatal(err)
    }
}
func parseRemoteURL(remoteUrl string) (string, error) {
    if u, err := url.Parse(remoteUrl); err == nil && u.Scheme != "" {
       return u.Scheme, nil
    }
    // Check for SCP-like SSH URLs first because they don't have a "scheme://"
    scpRe := regexp.MustCompile(`^[a-zA-Z0-9._@/+~-]+@[a-zA-Z0-9._@/+~-]+:[a-zA-Z0-9._@/+~-]+(\.git)?$`)
    if scpRe.MatchString(remoteUrl) {
       return "ssh", nil
    }
    return "", errors.New("invalid Git URL scheme")
}
```

and this worked for http(s): ``` $ GIT_TRACE=1 git clone custom::https://github.com/rovaughn/git-remote-grave.git 11:17:52.117674 git.c:455 trace: built-in: git clone custom::https://github.com/rovaughn/git-remote-grave.git Cloning into 'git-remote-grave'... 11:17:52.120021 run-command.c:668 trace: run_command: git remote-custom origin https://github.com/rovaughn/git-remote-grave.git 11:17:52.121757 git.c:742 trace: exec: git-remote-custom origin https://github.com/rovaughn/git-remote-grave.git 11:17:52.121792 run-command.c:668 trace: run_command: git-remote-custom origin https://github.com/rovaughn/git-remote-grave.git 11:17:52.666930 run-command.c:668 trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 21547 on pop-os' --check-self-contained-and-connected remote: Enumerating objects: 71, done. 11:17:52.669349 git.c:455 trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 21547 on pop-os' --check-self-contained-and-connected remote: Total 71 (delta 0), reused 0 (delta 0), pack-reused 71 Receiving objects: 100% (71/71), 48.92 KiB | 1.11 MiB/s, done. Resolving deltas: 100% (28/28), done. 11:17:52.716950 run-command.c:668 trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity' 11:17:52.718721 git.c:455 trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity' ```

but `ssh` doesn't have a corresponding remote-ssh helper.

Is there a plug and play way to wrap/proxy the `ssh` protocols in a similar way with a remote-helper? Or are there better approaches to achieve this?

Any feedback is appreciated, Kind regards

Guga
Message 1 of 1 in “Fwd: "reverse proxy" remote-helper”
  1. Guga FigueiredoApr 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.