func()

in internal/command/lfsauthenticate/lfsauthenticate.go [48:90]


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-authenticate 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
	}

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

	payload, err := c.authenticate(ctx, operation, repo, accessResponse.UserID)
	if err != nil {
		// return nothing just like Ruby's GitlabShell#lfs_authenticate does
		log.WithContextFields(
			ctx,
			log.Fields{"operation": operation, "repo": repo, "user_id": accessResponse.UserID},
		).WithError(err).Debug("lfsauthenticate: execute: LFS authentication failed")

		return ctxWithLogData, nil
	}

	fmt.Fprintf(c.ReadWriter.Out, "%s\n", payload)

	return ctxWithLogData, nil
}