summaryrefslogtreecommitdiff
path: root/internal/handler/exec.go
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2022-01-21 11:05:19 +0000
committerJacob Vosmaer <jacob@gitlab.com>2022-01-21 11:05:19 +0000
commitd005af25ab3224efa0d23be53858710f77e672c6 (patch)
tree0e5363ea426f2d66a646f63f3099ff8361c63e38 /internal/handler/exec.go
parentbc25e92dd824591688cbe88cbbeb891b6459b9a9 (diff)
downloadgitlab-shell-jv-ssh-sidechannel.tar.gz
Optionally use SSHUploadPackWithSidechanneljv-ssh-sidechannel
If the GitLab API returns an allowed response with use_sidechannel set to true, gitlab-shell will establish a sidechannel connection and use SSHUploadPackWithSidechannel instead of SSHUploadPack. This is an efficiency improvement.
Diffstat (limited to 'internal/handler/exec.go')
-rw-r--r--internal/handler/exec.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/internal/handler/exec.go b/internal/handler/exec.go
index 8f4a7df..9bd8018 100644
--- a/internal/handler/exec.go
+++ b/internal/handler/exec.go
@@ -29,21 +29,23 @@ import (
// GitalyHandlerFunc implementations are responsible for making
// an appropriate Gitaly call using the provided client and context
// and returning an error from the Gitaly call.
-type GitalyHandlerFunc func(ctx context.Context, client *grpc.ClientConn) (int32, error)
+type GitalyHandlerFunc func(ctx context.Context, client *grpc.ClientConn, registry *client.SidechannelRegistry) (int32, error)
type GitalyCommand struct {
- Config *config.Config
- ServiceName string
- Address string
- Token string
- Features map[string]string
+ Config *config.Config
+ ServiceName string
+ Address string
+ Token string
+ Features map[string]string
+ DialSidechannel bool
}
// RunGitalyCommand provides a bootstrap for Gitaly commands executed
// through GitLab-Shell. It ensures that logging, tracing and other
// common concerns are configured before executing the `handler`.
func (gc *GitalyCommand) RunGitalyCommand(ctx context.Context, handler GitalyHandlerFunc) error {
- conn, err := getConn(ctx, gc)
+ registry := client.NewSidechannelRegistry(log.ContextLogger(ctx))
+ conn, err := getConn(ctx, gc, registry)
if err != nil {
log.ContextLogger(ctx).WithError(fmt.Errorf("RunGitalyCommand: %v", err)).Error("Failed to get connection to execute Git command")
@@ -53,7 +55,7 @@ func (gc *GitalyCommand) RunGitalyCommand(ctx context.Context, handler GitalyHan
childCtx := withOutgoingMetadata(ctx, gc.Features)
ctxlog := log.ContextLogger(childCtx)
- exitStatus, err := handler(childCtx, conn)
+ exitStatus, err := handler(childCtx, conn, registry)
if err != nil {
if grpcstatus.Convert(err).Code() == grpccodes.Unavailable {
@@ -116,7 +118,7 @@ func withOutgoingMetadata(ctx context.Context, features map[string]string) conte
return metadata.NewOutgoingContext(ctx, md)
}
-func getConn(ctx context.Context, gc *GitalyCommand) (*grpc.ClientConn, error) {
+func getConn(ctx context.Context, gc *GitalyCommand, registry *client.SidechannelRegistry) (*grpc.ClientConn, error) {
if gc.Address == "" {
return nil, fmt.Errorf("no gitaly_address given")
}
@@ -160,5 +162,9 @@ func getConn(ctx context.Context, gc *GitalyCommand) (*grpc.ClientConn, error) {
)
}
+ if gc.DialSidechannel {
+ return client.DialSidechannel(ctx, gc.Address, registry, connOpts)
+ }
+
return client.DialContext(ctx, gc.Address, connOpts)
}