diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-03-17 14:03:17 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-03-17 14:03:17 +0300 |
commit | 139d68f352b1c0b163ec3c40046fe540b22a4148 (patch) | |
tree | e96f81d611fbf527f83509dc1c138fee63e4f6a9 /cmd/gitaly-ssh/main.go | |
parent | 1ac28387afcfb33e682059d20cb6517182ed60a3 (diff) | |
parent | 75f23507af40aed4739571e1caa38ca46cd1e0ba (diff) |
Merge branch 'pks-ssh-upload-pack-filter' into 'master'
Support partial clones with SSH transports
See merge request gitlab-org/gitaly!1893
Diffstat (limited to 'cmd/gitaly-ssh/main.go')
-rw-r--r-- | cmd/gitaly-ssh/main.go | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/cmd/gitaly-ssh/main.go b/cmd/gitaly-ssh/main.go index 4049cc47b..5c70de194 100644 --- a/cmd/gitaly-ssh/main.go +++ b/cmd/gitaly-ssh/main.go @@ -5,10 +5,12 @@ import ( "fmt" "log" "os" + "strings" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" "gitlab.com/gitlab-org/gitaly/client" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" "gitlab.com/gitlab-org/labkit/tracing" grpctracing "gitlab.com/gitlab-org/labkit/tracing/grpc" @@ -17,10 +19,26 @@ import ( type packFn func(_ context.Context, _ *grpc.ClientConn, _ string) (int32, error) +type gitalySSHCommand struct { + // The git packer that shall be executed. One of receivePack, + // uploadPack or uploadArchive + packer packFn + // Working directory to execute the packer in + workingDir string + // Address of the server we want to post the request to + address string + // Marshalled gRPC payload to pass to the remote server + payload string + // Comma separated list of feature flags that shall be enabled on the + // remote server + featureFlags string +} + // GITALY_ADDRESS="tcp://1.2.3.4:9999" or "unix:/var/run/gitaly.sock" // GITALY_TOKEN="foobar1234" // GITALY_PAYLOAD="{repo...}" // GITALY_WD="/path/to/working-directory" +// GITALY_FEATUREFLAGS="upload_pack_filter,hooks_rpc" // gitaly-ssh upload-pack <git-garbage-x2> func main() { // < 4 since git throws on 2x garbage here @@ -42,11 +60,15 @@ func main() { log.Fatalf("invalid pack command: %q", command) } - gitalyWorkingDir := os.Getenv("GITALY_WD") - gitalyAddress := os.Getenv("GITALY_ADDRESS") - gitalyPayload := os.Getenv("GITALY_PAYLOAD") + cmd := gitalySSHCommand{ + packer: packer, + workingDir: os.Getenv("GITALY_WD"), + address: os.Getenv("GITALY_ADDRESS"), + payload: os.Getenv("GITALY_PAYLOAD"), + featureFlags: os.Getenv("GITALY_FEATUREFLAGS"), + } - code, err := run(packer, gitalyWorkingDir, gitalyAddress, gitalyPayload) + code, err := cmd.run() if err != nil { log.Printf("%s: %v", command, err) } @@ -54,7 +76,7 @@ func main() { os.Exit(code) } -func run(packer packFn, gitalyWorkingDir string, gitalyAddress string, gitalyPayload string) (int, error) { +func (cmd gitalySSHCommand) run() (int, error) { // Configure distributed tracing closer := tracing.Initialize(tracing.WithServiceName("gitaly-ssh")) defer closer.Close() @@ -62,19 +84,25 @@ func run(packer packFn, gitalyWorkingDir string, gitalyAddress string, gitalyPay ctx, finished := tracing.ExtractFromEnv(context.Background()) defer finished() - if gitalyWorkingDir != "" { - if err := os.Chdir(gitalyWorkingDir); err != nil { - return 1, fmt.Errorf("unable to chdir to %v", gitalyWorkingDir) + if cmd.featureFlags != "" { + for _, flag := range strings.Split(cmd.featureFlags, ",") { + ctx = featureflag.OutgoingCtxWithFeatureFlag(ctx, flag) + } + } + + if cmd.workingDir != "" { + if err := os.Chdir(cmd.workingDir); err != nil { + return 1, fmt.Errorf("unable to chdir to %v", cmd.workingDir) } } - conn, err := getConnection(gitalyAddress) + conn, err := getConnection(cmd.address) if err != nil { return 1, err } defer conn.Close() - code, err := packer(ctx, conn, gitalyPayload) + code, err := cmd.packer(ctx, conn, cmd.payload) if err != nil { return 1, err } |