func()

in internal/command/lfstransfer/lfstransfer.go [32:96]


func (c *Command) Execute(ctx context.Context) (context.Context, error) {
	args := c.Args.SSHArgs
	if len(args) != 3 {
		return ctx, disallowedcommand.Error
	}

	// e.g. git-lfs-transfer user/repo.git download
	repo := args[1]
	operation := args[2]

	action, err := actionFromOperation(operation)
	if err != nil {
		return ctx, err
	}

	accessResponse, err := c.verifyAccess(ctx, action, repo)
	if err != nil {
		return ctx, err
	}

	ctxWithLogData := context.WithValue(ctx, "logData", command.NewLogData(
		accessResponse.Gitaly.Repo.GlProjectPath,
		accessResponse.Username,
		accessResponse.ProjectID,
		accessResponse.RootNamespaceID,
	))

	log.WithContextFields(ctxWithLogData, log.Fields{"action": action}).Info("processing action")

	auth, err := c.authenticate(ctx, operation, repo, accessResponse.UserID)
	if err != nil {
		return ctxWithLogData, err
	}

	logger := NewWrappedLoggerForGitLFSTransfer(ctxWithLogData)

	backend, err := NewGitlabBackend(ctxWithLogData, c.Config, c.Args, auth)
	if err != nil {
		return ctxWithLogData, err
	}

	handler := transfer.NewPktline(c.ReadWriter.In, c.ReadWriter.Out, logger)

	for _, cap := range capabilities {
		if err := handler.WritePacketText(cap); err != nil {
			log.WithContextFields(ctxWithLogData, log.Fields{"capability": cap}).WithError(err).Error("error sending capability")
		}
	}

	if err := handler.WriteFlush(); err != nil {
		log.WithContextFields(ctxWithLogData, log.Fields{}).WithError(err).Error("error flushing capabilities")
	}

	p := transfer.NewProcessor(handler, backend, logger)
	defer log.WithContextFields(ctxWithLogData, log.Fields{"action": action}).Info("done processing commands")

	switch operation {
	case transfer.DownloadOperation:
		return ctxWithLogData, p.ProcessCommands(transfer.DownloadOperation)
	case transfer.UploadOperation:
		return ctxWithLogData, p.ProcessCommands(transfer.UploadOperation)
	default:
		return ctxWithLogData, fmt.Errorf("unknown operation %q", operation)
	}
}