Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2022-10-31 18:23:21 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-11-08 12:33:53 +0300
commit461712595d49ffc23504cb5ef9de2b238bde95b5 (patch)
treed1f5c9762abf4fcb58cbd3622f39d7fda512ba9a
parent52f1d86984251bb14537c39362302325d398df79 (diff)
gitaly/service: Use 'service.ValidateRepository()' to validate input
Replace simple non-nil check with call of the ValidateRepository() functions that also validates RelativePath and StorageName fields. Part of https://gitlab.com/gitlab-org/gitaly/-/issues/3717
-rw-r--r--internal/gitaly/service/blob/blobs.go13
-rw-r--r--internal/gitaly/service/blob/get_blob.go6
-rw-r--r--internal/gitaly/service/blob/get_blobs.go6
-rw-r--r--internal/gitaly/service/blob/lfs_pointers.go20
-rw-r--r--internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go8
-rw-r--r--internal/gitaly/service/commit/check_objects_exist.go9
-rw-r--r--internal/gitaly/service/commit/commit_messages.go8
-rw-r--r--internal/gitaly/service/commit/commit_signatures.go6
-rw-r--r--internal/gitaly/service/commit/commits_by_message.go6
-rw-r--r--internal/gitaly/service/commit/count_commits.go6
-rw-r--r--internal/gitaly/service/commit/count_diverging_commits.go9
-rw-r--r--internal/gitaly/service/commit/filter_shas_with_signatures.go7
-rw-r--r--internal/gitaly/service/commit/find_all_commits.go6
-rw-r--r--internal/gitaly/service/commit/find_commit.go6
-rw-r--r--internal/gitaly/service/commit/find_commits.go6
-rw-r--r--internal/gitaly/service/commit/isancestor.go6
-rw-r--r--internal/gitaly/service/commit/languages.go6
-rw-r--r--internal/gitaly/service/commit/last_commit_for_path.go6
-rw-r--r--internal/gitaly/service/commit/list_all_commits.go7
-rw-r--r--internal/gitaly/service/commit/list_commits.go6
-rw-r--r--internal/gitaly/service/commit/list_commits_by_oid.go9
-rw-r--r--internal/gitaly/service/commit/list_commits_by_ref_name.go9
-rw-r--r--internal/gitaly/service/commit/list_files.go6
-rw-r--r--internal/gitaly/service/commit/list_files_test.go2
-rw-r--r--internal/gitaly/service/commit/list_last_commits_for_tree.go6
-rw-r--r--internal/gitaly/service/commit/raw_blame.go6
-rw-r--r--internal/gitaly/service/commit/stats.go6
-rw-r--r--internal/gitaly/service/commit/tree_entries.go6
-rw-r--r--internal/gitaly/service/commit/tree_entry.go6
-rw-r--r--internal/gitaly/service/conflicts/list_conflict_files.go6
-rw-r--r--internal/gitaly/service/conflicts/resolve_conflicts.go6
-rw-r--r--internal/gitaly/service/diff/commit.go6
-rw-r--r--internal/gitaly/service/diff/find_changed_paths.go12
-rw-r--r--internal/gitaly/service/diff/numstat.go10
-rw-r--r--internal/gitaly/service/hook/pack_objects.go6
-rw-r--r--internal/gitaly/service/hook/post_receive.go8
-rw-r--r--internal/gitaly/service/hook/pre_receive.go8
-rw-r--r--internal/gitaly/service/hook/reference_transaction.go8
-rw-r--r--internal/gitaly/service/hook/update.go8
-rw-r--r--internal/gitaly/service/objectpool/alternates.go9
-rw-r--r--internal/gitaly/service/objectpool/get.go13
-rw-r--r--internal/gitaly/service/objectpool/link.go8
-rw-r--r--internal/gitaly/service/objectpool/reduplicate.go11
-rw-r--r--internal/gitaly/service/operations/apply_patch.go6
-rw-r--r--internal/gitaly/service/operations/branches.go14
-rw-r--r--internal/gitaly/service/operations/commit_files.go6
-rw-r--r--internal/gitaly/service/operations/merge.go14
-rw-r--r--internal/gitaly/service/operations/rebase.go6
-rw-r--r--internal/gitaly/service/operations/rebase_test.go2
-rw-r--r--internal/gitaly/service/operations/squash.go6
-rw-r--r--internal/gitaly/service/operations/submodules.go6
-rw-r--r--internal/gitaly/service/operations/tags.go10
-rw-r--r--internal/gitaly/service/operations/utils.go6
-rw-r--r--internal/gitaly/service/ref/branches.go9
-rw-r--r--internal/gitaly/service/ref/delete_refs.go6
-rw-r--r--internal/gitaly/service/ref/find_all_tags.go9
-rw-r--r--internal/gitaly/service/ref/find_refs_by_oid.go6
-rw-r--r--internal/gitaly/service/ref/find_tag.go9
-rw-r--r--internal/gitaly/service/ref/list_refs.go6
-rw-r--r--internal/gitaly/service/ref/pack_refs.go7
-rw-r--r--internal/gitaly/service/ref/pack_refs_test.go2
-rw-r--r--internal/gitaly/service/ref/refexists.go6
-rw-r--r--internal/gitaly/service/ref/refnames.go10
-rw-r--r--internal/gitaly/service/ref/refnames_containing.go10
-rw-r--r--internal/gitaly/service/ref/refs.go17
-rw-r--r--internal/gitaly/service/ref/remote_branches.go6
-rw-r--r--internal/gitaly/service/ref/tag_messages.go8
-rw-r--r--internal/gitaly/service/ref/tag_signatures.go6
-rw-r--r--internal/gitaly/service/remote/find_remote_root_ref.go6
-rw-r--r--internal/gitaly/service/remote/update_remote_mirror.go6
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes.go9
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes_test.go4
-rw-r--r--internal/gitaly/service/repository/archive.go9
-rw-r--r--internal/gitaly/service/repository/archive_test.go2
-rw-r--r--internal/gitaly/service/repository/backup_custom_hooks.go6
-rw-r--r--internal/gitaly/service/repository/calculate_checksum.go9
-rw-r--r--internal/gitaly/service/repository/cleanup.go7
-rw-r--r--internal/gitaly/service/repository/cleanup_test.go2
-rw-r--r--internal/gitaly/service/repository/commit_graph.go9
-rw-r--r--internal/gitaly/service/repository/commit_graph_test.go2
-rw-r--r--internal/gitaly/service/repository/config.go9
-rw-r--r--internal/gitaly/service/repository/create_bundle.go12
-rw-r--r--internal/gitaly/service/repository/create_bundle_from_ref_list.go11
-rw-r--r--internal/gitaly/service/repository/create_fork.go6
-rw-r--r--internal/gitaly/service/repository/create_repository.go9
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle.go9
-rw-r--r--internal/gitaly/service/repository/create_repository_from_snapshot.go9
-rw-r--r--internal/gitaly/service/repository/create_repository_from_url.go6
-rw-r--r--internal/gitaly/service/repository/fetch.go6
-rw-r--r--internal/gitaly/service/repository/fetch_bundle.go6
-rw-r--r--internal/gitaly/service/repository/fetch_remote.go6
-rw-r--r--internal/gitaly/service/repository/fsck.go13
-rw-r--r--internal/gitaly/service/repository/fullpath.go16
-rw-r--r--internal/gitaly/service/repository/gc.go9
-rw-r--r--internal/gitaly/service/repository/gc_test.go2
-rw-r--r--internal/gitaly/service/repository/info_attributes.go9
-rw-r--r--internal/gitaly/service/repository/license.go11
-rw-r--r--internal/gitaly/service/repository/merge_base.go9
-rw-r--r--internal/gitaly/service/repository/midx.go12
-rw-r--r--internal/gitaly/service/repository/midx_test.go2
-rw-r--r--internal/gitaly/service/repository/optimize.go9
-rw-r--r--internal/gitaly/service/repository/prune_unreachable_objects.go9
-rw-r--r--internal/gitaly/service/repository/raw_changes.go9
-rw-r--r--internal/gitaly/service/repository/remove.go16
-rw-r--r--internal/gitaly/service/repository/rename.go6
-rw-r--r--internal/gitaly/service/repository/repack.go16
-rw-r--r--internal/gitaly/service/repository/repack_test.go8
-rw-r--r--internal/gitaly/service/repository/replicate.go6
-rw-r--r--internal/gitaly/service/repository/repository.go13
-rw-r--r--internal/gitaly/service/repository/restore_custom_hooks.go18
-rw-r--r--internal/gitaly/service/repository/search_files.go6
-rw-r--r--internal/gitaly/service/repository/search_files_test.go18
-rw-r--r--internal/gitaly/service/repository/size.go16
-rw-r--r--internal/gitaly/service/repository/snapshot.go6
-rw-r--r--internal/gitaly/service/repository/write_ref.go6
-rw-r--r--internal/gitaly/service/smarthttp/inforefs.go16
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack.go6
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack.go11
-rw-r--r--internal/gitaly/service/ssh/receive_pack.go8
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go2
-rw-r--r--internal/gitaly/service/ssh/upload_archive.go6
-rw-r--r--internal/gitaly/service/ssh/upload_archive_test.go2
-rw-r--r--internal/gitaly/service/ssh/upload_pack.go6
-rw-r--r--internal/gitaly/service/ssh/upload_pack_test.go2
124 files changed, 496 insertions, 489 deletions
diff --git a/internal/gitaly/service/blob/blobs.go b/internal/gitaly/service/blob/blobs.go
index 64c5f8e62..beb9202ba 100644
--- a/internal/gitaly/service/blob/blobs.go
+++ b/internal/gitaly/service/blob/blobs.go
@@ -7,10 +7,10 @@ import (
"io"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -19,8 +19,8 @@ import (
)
func verifyListBlobsRequest(req *gitalypb.ListBlobsRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.GetRevisions()) == 0 {
return errors.New("missing revisions")
@@ -237,11 +237,12 @@ func (t *blobSender) Send() error {
func (s *server) ListAllBlobs(req *gitalypb.ListAllBlobsRequest, stream gitalypb.BlobService_ListAllBlobsServer) error {
ctx := stream.Context()
- if req.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
- repo := s.localrepo(req.GetRepository())
+ repo := s.localrepo(repository)
chunker := chunk.New(&allBlobsSender{
send: func(blobs []*gitalypb.ListAllBlobsResponse_Blob) error {
diff --git a/internal/gitaly/service/blob/get_blob.go b/internal/gitaly/service/blob/get_blob.go
index 77ad6dfae..8d087ac34 100644
--- a/internal/gitaly/service/blob/get_blob.go
+++ b/internal/gitaly/service/blob/get_blob.go
@@ -4,9 +4,9 @@ import (
"errors"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -71,8 +71,8 @@ func (s *server) GetBlob(in *gitalypb.GetBlobRequest, stream gitalypb.BlobServic
}
func validateRequest(in *gitalypb.GetBlobRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.GetOid()) == 0 {
diff --git a/internal/gitaly/service/blob/get_blobs.go b/internal/gitaly/service/blob/get_blobs.go
index 114fbbfc0..51a173a8f 100644
--- a/internal/gitaly/service/blob/get_blobs.go
+++ b/internal/gitaly/service/blob/get_blobs.go
@@ -6,9 +6,9 @@ import (
"fmt"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -177,8 +177,8 @@ func (s *server) GetBlobs(req *gitalypb.GetBlobsRequest, stream gitalypb.BlobSer
}
func validateGetBlobsRequest(req *gitalypb.GetBlobsRequest) error {
- if req.Repository == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.RevisionPaths) == 0 {
diff --git a/internal/gitaly/service/blob/lfs_pointers.go b/internal/gitaly/service/blob/lfs_pointers.go
index 88b7870ec..ce51cd01a 100644
--- a/internal/gitaly/service/blob/lfs_pointers.go
+++ b/internal/gitaly/service/blob/lfs_pointers.go
@@ -6,10 +6,10 @@ import (
"io"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -28,8 +28,9 @@ const (
func (s *server) ListLFSPointers(in *gitalypb.ListLFSPointersRequest, stream gitalypb.BlobService_ListLFSPointersServer) error {
ctx := stream.Context()
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
if len(in.Revisions) == 0 {
return helper.ErrInvalidArgumentf("missing revisions")
@@ -48,7 +49,7 @@ func (s *server) ListLFSPointers(in *gitalypb.ListLFSPointersRequest, stream git
},
})
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
objectReader, cancel, err := s.catfileCache.ObjectReader(ctx, repo)
if err != nil {
@@ -79,11 +80,12 @@ func (s *server) ListLFSPointers(in *gitalypb.ListLFSPointersRequest, stream git
func (s *server) ListAllLFSPointers(in *gitalypb.ListAllLFSPointersRequest, stream gitalypb.BlobService_ListAllLFSPointersServer) error {
ctx := stream.Context()
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
chunker := chunk.New(&lfsPointerSender{
send: func(pointers []*gitalypb.LFSPointer) error {
@@ -177,8 +179,8 @@ func (s *server) GetLFSPointers(req *gitalypb.GetLFSPointersRequest, stream gita
}
func validateGetLFSPointersRequest(req *gitalypb.GetLFSPointersRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.GetBlobIds()) == 0 {
diff --git a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go
index 9b65eae67..7a2dcbe86 100644
--- a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go
+++ b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go
@@ -3,7 +3,7 @@ package cleanup
import (
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/cleanup/internalrefs"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/cleanup/notifier"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
@@ -65,11 +65,7 @@ func (s *server) ApplyBfgObjectMapStream(server gitalypb.CleanupService_ApplyBfg
}
func validateFirstRequest(req *gitalypb.ApplyBfgObjectMapStreamRequest) error {
- if repo := req.GetRepository(); repo == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(req.GetRepository())
}
func (r *bfgStreamReader) readOne() ([]byte, error) {
diff --git a/internal/gitaly/service/commit/check_objects_exist.go b/internal/gitaly/service/commit/check_objects_exist.go
index 2a43ed0fc..8a557df8b 100644
--- a/internal/gitaly/service/commit/check_objects_exist.go
+++ b/internal/gitaly/service/commit/check_objects_exist.go
@@ -4,9 +4,9 @@ import (
"context"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -29,13 +29,14 @@ func (s *server) CheckObjectsExist(
return helper.ErrInternalf("receiving initial request: %w", err)
}
- if request.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
objectInfoReader, cancel, err := s.catfileCache.ObjectInfoReader(
ctx,
- s.localrepo(request.GetRepository()),
+ s.localrepo(repository),
)
if err != nil {
return helper.ErrInternalf("creating object info reader: %w", err)
diff --git a/internal/gitaly/service/commit/commit_messages.go b/internal/gitaly/service/commit/commit_messages.go
index 3417f509a..8cc7ecfea 100644
--- a/internal/gitaly/service/commit/commit_messages.go
+++ b/internal/gitaly/service/commit/commit_messages.go
@@ -5,9 +5,9 @@ import (
"fmt"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -56,9 +56,5 @@ func (s *server) getAndStreamCommitMessages(request *gitalypb.GetCommitMessagesR
}
func validateGetCommitMessagesRequest(request *gitalypb.GetCommitMessagesRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(request.GetRepository())
}
diff --git a/internal/gitaly/service/commit/commit_signatures.go b/internal/gitaly/service/commit/commit_signatures.go
index ffcb0adc8..a84a704af 100644
--- a/internal/gitaly/service/commit/commit_signatures.go
+++ b/internal/gitaly/service/commit/commit_signatures.go
@@ -7,9 +7,9 @@ import (
"fmt"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -127,8 +127,8 @@ func sendResponse(commitID string, signatureKey []byte, commitText []byte, strea
}
func validateGetCommitSignaturesRequest(request *gitalypb.GetCommitSignaturesRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(request.GetRepository()); err != nil {
+ return err
}
if len(request.GetCommitIds()) == 0 {
diff --git a/internal/gitaly/service/commit/commits_by_message.go b/internal/gitaly/service/commit/commits_by_message.go
index 1eaeb52c7..9eb5c8004 100644
--- a/internal/gitaly/service/commit/commits_by_message.go
+++ b/internal/gitaly/service/commit/commits_by_message.go
@@ -3,8 +3,8 @@ package commit
import (
"fmt"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/protobuf/proto"
@@ -70,8 +70,8 @@ func (s *server) commitsByMessage(in *gitalypb.CommitsByMessageRequest, stream g
}
func validateCommitsByMessageRequest(in *gitalypb.CommitsByMessageRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(in.Revision); err != nil {
diff --git a/internal/gitaly/service/commit/count_commits.go b/internal/gitaly/service/commit/count_commits.go
index 1d2807193..d547639f3 100644
--- a/internal/gitaly/service/commit/count_commits.go
+++ b/internal/gitaly/service/commit/count_commits.go
@@ -9,8 +9,8 @@ import (
"time"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -77,8 +77,8 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ
}
func validateCountCommitsRequest(in *gitalypb.CountCommitsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(in.Revision); err != nil {
diff --git a/internal/gitaly/service/commit/count_diverging_commits.go b/internal/gitaly/service/commit/count_diverging_commits.go
index d47671ee9..330943e29 100644
--- a/internal/gitaly/service/commit/count_diverging_commits.go
+++ b/internal/gitaly/service/commit/count_diverging_commits.go
@@ -8,8 +8,8 @@ import (
"strconv"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -36,11 +36,12 @@ func (s *server) validateCountDivergingCommitsRequest(req *gitalypb.CountDivergi
return errors.New("from and to are both required")
}
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
- if _, err := s.locator.GetRepoPath(req.GetRepository()); err != nil {
+ if _, err := s.locator.GetRepoPath(repository); err != nil {
return fmt.Errorf("repository not valid: %v", err)
}
diff --git a/internal/gitaly/service/commit/filter_shas_with_signatures.go b/internal/gitaly/service/commit/filter_shas_with_signatures.go
index b71f7fd54..2b63711f6 100644
--- a/internal/gitaly/service/commit/filter_shas_with_signatures.go
+++ b/internal/gitaly/service/commit/filter_shas_with_signatures.go
@@ -4,9 +4,9 @@ import (
"context"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -28,10 +28,7 @@ func (s *server) FilterShasWithSignatures(bidi gitalypb.CommitService_FilterShas
}
func validateFirstFilterShasWithSignaturesRequest(in *gitalypb.FilterShasWithSignaturesRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
func (s *server) filterShasWithSignatures(bidi gitalypb.CommitService_FilterShasWithSignaturesServer, firstRequest *gitalypb.FilterShasWithSignaturesRequest) error {
diff --git a/internal/gitaly/service/commit/find_all_commits.go b/internal/gitaly/service/commit/find_all_commits.go
index 573894744..d52e2b714 100644
--- a/internal/gitaly/service/commit/find_all_commits.go
+++ b/internal/gitaly/service/commit/find_all_commits.go
@@ -3,8 +3,8 @@ package commit
import (
"fmt"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -40,8 +40,8 @@ func (s *server) FindAllCommits(in *gitalypb.FindAllCommitsRequest, stream gital
}
func validateFindAllCommitsRequest(in *gitalypb.FindAllCommitsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(in.Revision); err != nil {
diff --git a/internal/gitaly/service/commit/find_commit.go b/internal/gitaly/service/commit/find_commit.go
index 4b736452c..7c823c8d1 100644
--- a/internal/gitaly/service/commit/find_commit.go
+++ b/internal/gitaly/service/commit/find_commit.go
@@ -4,16 +4,16 @@ import (
"context"
"errors"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func validateFindCommitRequest(in *gitalypb.FindCommitRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.GetRevision()); err != nil {
return err
diff --git a/internal/gitaly/service/commit/find_commits.go b/internal/gitaly/service/commit/find_commits.go
index 1b2aa7117..c22298866 100644
--- a/internal/gitaly/service/commit/find_commits.go
+++ b/internal/gitaly/service/commit/find_commits.go
@@ -12,10 +12,10 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/trailerparser"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -24,8 +24,8 @@ import (
var statsPattern = regexp.MustCompile(`\s(\d+)\sfiles? changed(,\s(\d+)\sinsertions?\(\+\))?(,\s(\d+)\sdeletions?\(-\))?`)
func validateFindCommitsRequest(in *gitalypb.FindCommitsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(in.GetRevision()); err != nil {
return err
diff --git a/internal/gitaly/service/commit/isancestor.go b/internal/gitaly/service/commit/isancestor.go
index a4b993da5..b4ec810bb 100644
--- a/internal/gitaly/service/commit/isancestor.go
+++ b/internal/gitaly/service/commit/isancestor.go
@@ -6,8 +6,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -15,8 +15,8 @@ import (
)
func validateCommitIsAncestorRequest(in *gitalypb.CommitIsAncestorRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if in.GetAncestorId() == "" {
return errors.New("Bad Request (empty ancestor sha)") //nolint:stylecheck
diff --git a/internal/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go
index 10eb971e8..e6475e347 100644
--- a/internal/gitaly/service/commit/languages.go
+++ b/internal/gitaly/service/commit/languages.go
@@ -9,9 +9,9 @@ import (
"sort"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/linguist"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -20,8 +20,8 @@ import (
var errAmbigRef = errors.New("ambiguous reference")
func (s *server) validateCommitLanguagesRequest(req *gitalypb.CommitLanguagesRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(req.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/last_commit_for_path.go b/internal/gitaly/service/commit/last_commit_for_path.go
index 0ed2eb3e3..3bee23686 100644
--- a/internal/gitaly/service/commit/last_commit_for_path.go
+++ b/internal/gitaly/service/commit/last_commit_for_path.go
@@ -3,9 +3,9 @@ package commit
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -58,8 +58,8 @@ func (s *server) lastCommitForPath(ctx context.Context, in *gitalypb.LastCommitF
}
func validateLastCommitForPathRequest(in *gitalypb.LastCommitForPathRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/list_all_commits.go b/internal/gitaly/service/commit/list_all_commits.go
index 9cba824b8..05a001ab2 100644
--- a/internal/gitaly/service/commit/list_all_commits.go
+++ b/internal/gitaly/service/commit/list_all_commits.go
@@ -3,20 +3,17 @@ package commit
import (
"fmt"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func verifyListAllCommitsRequest(request *gitalypb.ListAllCommitsRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
- return nil
+ return service.ValidateRepository(request.GetRepository())
}
func (s *server) ListAllCommits(
diff --git a/internal/gitaly/service/commit/list_commits.go b/internal/gitaly/service/commit/list_commits.go
index cff5cd83a..376ef9175 100644
--- a/internal/gitaly/service/commit/list_commits.go
+++ b/internal/gitaly/service/commit/list_commits.go
@@ -5,18 +5,18 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func verifyListCommitsRequest(request *gitalypb.ListCommitsRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(request.GetRepository()); err != nil {
+ return err
}
if len(request.GetRevisions()) == 0 {
return errors.New("missing revisions")
diff --git a/internal/gitaly/service/commit/list_commits_by_oid.go b/internal/gitaly/service/commit/list_commits_by_oid.go
index fa830121b..d9a35fb1a 100644
--- a/internal/gitaly/service/commit/list_commits_by_oid.go
+++ b/internal/gitaly/service/commit/list_commits_by_oid.go
@@ -3,9 +3,9 @@ package commit
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -25,10 +25,11 @@ var listCommitsbyOidHistogram = promauto.NewHistogram(
func (s *server) ListCommitsByOid(in *gitalypb.ListCommitsByOidRequest, stream gitalypb.CommitService_ListCommitsByOidServer) error {
ctx := stream.Context()
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
objectReader, cancel, err := s.catfileCache.ObjectReader(ctx, repo)
if err != nil {
diff --git a/internal/gitaly/service/commit/list_commits_by_ref_name.go b/internal/gitaly/service/commit/list_commits_by_ref_name.go
index 12b866730..9f28a43e1 100644
--- a/internal/gitaly/service/commit/list_commits_by_ref_name.go
+++ b/internal/gitaly/service/commit/list_commits_by_ref_name.go
@@ -1,9 +1,9 @@
package commit
import (
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -12,10 +12,11 @@ import (
func (s *server) ListCommitsByRefName(in *gitalypb.ListCommitsByRefNameRequest, stream gitalypb.CommitService_ListCommitsByRefNameServer) error {
ctx := stream.Context()
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
objectReader, cancel, err := s.catfileCache.ObjectReader(ctx, repo)
if err != nil {
diff --git a/internal/gitaly/service/commit/list_files.go b/internal/gitaly/service/commit/list_files.go
index 5ba492fe4..fcf86d841 100644
--- a/internal/gitaly/service/commit/list_files.go
+++ b/internal/gitaly/service/commit/list_files.go
@@ -5,9 +5,9 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -59,8 +59,8 @@ func (s *server) ListFiles(in *gitalypb.ListFilesRequest, stream gitalypb.Commit
}
func validateListFilesRequest(in *gitalypb.ListFilesRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevisionAllowEmpty(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/list_files_test.go b/internal/gitaly/service/commit/list_files_test.go
index f4e1c5a9b..445f9dfaa 100644
--- a/internal/gitaly/service/commit/list_files_test.go
+++ b/internal/gitaly/service/commit/list_files_test.go
@@ -221,7 +221,7 @@ func TestListFiles_failure(t *testing.T) {
desc: "empty repo object",
repo: &gitalypb.Repository{},
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- `GetStorageByName: no such storage: ""`,
+ "empty StorageName",
"repo scoped: invalid Repository",
)),
},
diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree.go b/internal/gitaly/service/commit/list_last_commits_for_tree.go
index ba3f6535e..7f5396998 100644
--- a/internal/gitaly/service/commit/list_last_commits_for_tree.go
+++ b/internal/gitaly/service/commit/list_last_commits_for_tree.go
@@ -6,10 +6,10 @@ import (
"sort"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/log"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -140,8 +140,8 @@ func sendCommitsForTree(batch []*gitalypb.ListLastCommitsForTreeResponse_CommitF
}
func validateListLastCommitsForTreeRequest(in *gitalypb.ListLastCommitsForTreeRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision([]byte(in.Revision)); err != nil {
return err
diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go
index ebaf02c70..7e45fe0f1 100644
--- a/internal/gitaly/service/commit/raw_blame.go
+++ b/internal/gitaly/service/commit/raw_blame.go
@@ -6,8 +6,8 @@ import (
"regexp"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
"google.golang.org/grpc/codes"
@@ -61,8 +61,8 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe
}
func validateRawBlameRequest(in *gitalypb.RawBlameRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/stats.go b/internal/gitaly/service/commit/stats.go
index 1a9873f4a..cc93eed20 100644
--- a/internal/gitaly/service/commit/stats.go
+++ b/internal/gitaly/service/commit/stats.go
@@ -7,15 +7,15 @@ import (
"strconv"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func validateCommitStatsRequest(in *gitalypb.CommitStatsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/tree_entries.go b/internal/gitaly/service/commit/tree_entries.go
index 1834980e0..0d1f88c74 100644
--- a/internal/gitaly/service/commit/tree_entries.go
+++ b/internal/gitaly/service/commit/tree_entries.go
@@ -10,11 +10,11 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -28,8 +28,8 @@ const (
)
func validateGetTreeEntriesRequest(in *gitalypb.GetTreeEntriesRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/commit/tree_entry.go b/internal/gitaly/service/commit/tree_entry.go
index c3216c15f..3878c2965 100644
--- a/internal/gitaly/service/commit/tree_entry.go
+++ b/internal/gitaly/service/commit/tree_entry.go
@@ -5,9 +5,9 @@ import (
"io"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -149,8 +149,8 @@ func (s *server) TreeEntry(in *gitalypb.TreeEntryRequest, stream gitalypb.Commit
}
func validateRequest(in *gitalypb.TreeEntryRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.Revision); err != nil {
return err
diff --git a/internal/gitaly/service/conflicts/list_conflict_files.go b/internal/gitaly/service/conflicts/list_conflict_files.go
index 427603524..2418f2170 100644
--- a/internal/gitaly/service/conflicts/list_conflict_files.go
+++ b/internal/gitaly/service/conflicts/list_conflict_files.go
@@ -7,9 +7,9 @@ import (
"io"
"unicode/utf8"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -127,8 +127,8 @@ func (s *server) ListConflictFiles(request *gitalypb.ListConflictFilesRequest, s
}
func validateListConflictFilesRequest(in *gitalypb.ListConflictFilesRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if in.GetOurCommitOid() == "" {
return fmt.Errorf("empty OurCommitOid")
diff --git a/internal/gitaly/service/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go
index 72ed7f94e..3a6ebf8a4 100644
--- a/internal/gitaly/service/conflicts/resolve_conflicts.go
+++ b/internal/gitaly/service/conflicts/resolve_conflicts.go
@@ -12,7 +12,6 @@ import (
"time"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/conflict"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
@@ -20,6 +19,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/remoterepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -80,8 +80,8 @@ func validateResolveConflictsHeader(header *gitalypb.ResolveConflictsRequestHead
if header.GetOurCommitOid() == "" {
return fmt.Errorf("empty OurCommitOid")
}
- if header.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(header.GetRepository()); err != nil {
+ return err
}
if header.GetTargetRepository() == nil {
return fmt.Errorf("empty TargetRepository")
diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go
index 8c718dcc4..02728b4fd 100644
--- a/internal/gitaly/service/diff/commit.go
+++ b/internal/gitaly/service/diff/commit.go
@@ -6,9 +6,9 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/diff"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -199,8 +199,8 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di
}
func validateRequest(in requestWithLeftRightCommitIds) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if in.GetLeftCommitId() == "" {
return fmt.Errorf("empty LeftCommitId")
diff --git a/internal/gitaly/service/diff/find_changed_paths.go b/internal/gitaly/service/diff/find_changed_paths.go
index 7420f9ab2..42710cdcc 100644
--- a/internal/gitaly/service/diff/find_changed_paths.go
+++ b/internal/gitaly/service/diff/find_changed_paths.go
@@ -10,9 +10,9 @@ import (
"strconv"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -195,15 +195,15 @@ func resolveObjectWithType(ctx context.Context, repo *localrepo.Repo, revision s
}
func (s *server) validateFindChangedPathsRequestParams(ctx context.Context, in *gitalypb.FindChangedPathsRequest) error {
- repo := in.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- if _, err := s.locator.GetRepoPath(repo); err != nil {
+ if _, err := s.locator.GetRepoPath(repository); err != nil {
return err
}
- gitRepo := s.localrepo(in.GetRepository())
+ gitRepo := s.localrepo(repository)
if len(in.GetCommits()) > 0 { //nolint:staticcheck
if len(in.GetRequests()) > 0 {
diff --git a/internal/gitaly/service/diff/numstat.go b/internal/gitaly/service/diff/numstat.go
index ed9290ea2..c4aaddd92 100644
--- a/internal/gitaly/service/diff/numstat.go
+++ b/internal/gitaly/service/diff/numstat.go
@@ -3,9 +3,9 @@ package diff
import (
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/diff"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -82,11 +82,11 @@ func sendStats(batch []*gitalypb.DiffStats, stream gitalypb.DiffService_DiffStat
}
func (s *server) validateDiffStatsRequestParams(in *gitalypb.DiffStatsRequest) error {
- repo := in.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- if _, err := s.locator.GetRepoPath(repo); err != nil {
+ if _, err := s.locator.GetRepoPath(repository); err != nil {
return err
}
diff --git a/internal/gitaly/service/hook/pack_objects.go b/internal/gitaly/service/hook/pack_objects.go
index 259b16923..1cdbcead7 100644
--- a/internal/gitaly/service/hook/pack_objects.go
+++ b/internal/gitaly/service/hook/pack_objects.go
@@ -18,10 +18,10 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
gitalyhook "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v15/internal/stream"
@@ -370,8 +370,8 @@ func bufferStdin(r io.Reader, h hash.Hash) (_ io.ReadCloser, err error) {
}
func (s *server) PackObjectsHookWithSidechannel(ctx context.Context, req *gitalypb.PackObjectsHookWithSidechannelRequest) (*gitalypb.PackObjectsHookWithSidechannelResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
args, err := parsePackObjectsArgs(req.Args)
diff --git a/internal/gitaly/service/hook/post_receive.go b/internal/gitaly/service/hook/post_receive.go
index 713c65849..9259a07c3 100644
--- a/internal/gitaly/service/hook/post_receive.go
+++ b/internal/gitaly/service/hook/post_receive.go
@@ -6,7 +6,7 @@ import (
"os/exec"
"sync"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -67,9 +67,5 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ
}
func validatePostReceiveHookRequest(in *gitalypb.PostReceiveHookRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
diff --git a/internal/gitaly/service/hook/pre_receive.go b/internal/gitaly/service/hook/pre_receive.go
index e30741737..596fd6396 100644
--- a/internal/gitaly/service/hook/pre_receive.go
+++ b/internal/gitaly/service/hook/pre_receive.go
@@ -6,7 +6,7 @@ import (
"os/exec"
"sync"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -57,11 +57,7 @@ func (s *server) PreReceiveHook(stream gitalypb.HookService_PreReceiveHookServer
}
func validatePreReceiveHookRequest(in *gitalypb.PreReceiveHookRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
func preReceiveHookResponse(stream gitalypb.HookService_PreReceiveHookServer, code int32, stderr string) error {
diff --git a/internal/gitaly/service/hook/reference_transaction.go b/internal/gitaly/service/hook/reference_transaction.go
index 8078b5541..51fbff981 100644
--- a/internal/gitaly/service/hook/reference_transaction.go
+++ b/internal/gitaly/service/hook/reference_transaction.go
@@ -3,8 +3,8 @@ package hook
import (
"errors"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -14,11 +14,7 @@ import (
)
func validateReferenceTransactionHookRequest(in *gitalypb.ReferenceTransactionHookRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
func (s *server) ReferenceTransactionHook(stream gitalypb.HookService_ReferenceTransactionHookServer) error {
diff --git a/internal/gitaly/service/hook/update.go b/internal/gitaly/service/hook/update.go
index dcbd032b7..b79029e0d 100644
--- a/internal/gitaly/service/hook/update.go
+++ b/internal/gitaly/service/hook/update.go
@@ -5,18 +5,14 @@ import (
"os/exec"
"sync"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
)
func validateUpdateHookRequest(in *gitalypb.UpdateHookRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
func (s *server) UpdateHook(in *gitalypb.UpdateHookRequest, stream gitalypb.HookService_UpdateHookServer) error {
diff --git a/internal/gitaly/service/objectpool/alternates.go b/internal/gitaly/service/objectpool/alternates.go
index 20ffbc2ae..33e5f5a31 100644
--- a/internal/gitaly/service/objectpool/alternates.go
+++ b/internal/gitaly/service/objectpool/alternates.go
@@ -11,9 +11,9 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
@@ -28,11 +28,12 @@ import (
// in a broken state until an administrator intervenes and restores the
// backed-up copy of objects/info/alternates.
func (s *server) DisconnectGitAlternates(ctx context.Context, req *gitalypb.DisconnectGitAlternatesRequest) (*gitalypb.DisconnectGitAlternatesResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(req.GetRepository())
+ repo := s.localrepo(repository)
if err := s.disconnectAlternates(ctx, repo); err != nil {
return nil, helper.ErrInternal(err)
diff --git a/internal/gitaly/service/objectpool/get.go b/internal/gitaly/service/objectpool/get.go
index 2986a1eb0..34fe42c2b 100644
--- a/internal/gitaly/service/objectpool/get.go
+++ b/internal/gitaly/service/objectpool/get.go
@@ -4,25 +4,26 @@ import (
"context"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/objectpool"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func (s *server) GetObjectPool(ctx context.Context, in *gitalypb.GetObjectPoolRequest) (*gitalypb.GetObjectPoolResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
objectPool, err := objectpool.FromRepo(s.locator, s.gitCmdFactory, s.catfileCache, s.txManager, s.housekeepingManager, repo)
if err != nil {
ctxlogrus.Extract(ctx).
WithError(err).
- WithField("storage", in.GetRepository().GetStorageName()).
- WithField("storage", in.GetRepository().GetRelativePath()).
+ WithField("storage", repository.GetStorageName()).
+ WithField("relative_path", repository.GetRelativePath()).
Warn("alternates file does not point to valid git repository")
}
diff --git a/internal/gitaly/service/objectpool/link.go b/internal/gitaly/service/objectpool/link.go
index 4a89f99a9..a0fdd510f 100644
--- a/internal/gitaly/service/objectpool/link.go
+++ b/internal/gitaly/service/objectpool/link.go
@@ -3,6 +3,7 @@ package objectpool
import (
"context"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -10,8 +11,9 @@ import (
)
func (s *server) LinkRepositoryToObjectPool(ctx context.Context, req *gitalypb.LinkRepositoryToObjectPoolRequest) (*gitalypb.LinkRepositoryToObjectPoolResponse, error) {
- if req.GetRepository() == nil {
- return nil, status.Error(codes.InvalidArgument, "no repository")
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, status.Error(codes.InvalidArgument, err.Error())
}
pool, err := s.poolForRequest(req)
@@ -19,7 +21,7 @@ func (s *server) LinkRepositoryToObjectPool(ctx context.Context, req *gitalypb.L
return nil, err
}
- repo := s.localrepo(req.GetRepository())
+ repo := s.localrepo(repository)
if err := pool.Link(ctx, repo); err != nil {
return nil, helper.ErrInternal(err)
diff --git a/internal/gitaly/service/objectpool/reduplicate.go b/internal/gitaly/service/objectpool/reduplicate.go
index b067f899f..16e1de255 100644
--- a/internal/gitaly/service/objectpool/reduplicate.go
+++ b/internal/gitaly/service/objectpool/reduplicate.go
@@ -4,17 +4,18 @@ import (
"context"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
- "google.golang.org/grpc/codes"
- "google.golang.org/grpc/status"
)
func (s *server) ReduplicateRepository(ctx context.Context, req *gitalypb.ReduplicateRepositoryRequest) (*gitalypb.ReduplicateRepositoryResponse, error) {
- if req.GetRepository() == nil {
- return nil, status.Errorf(codes.InvalidArgument, "ReduplicateRepository: no repository")
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInternalf("ReduplicateRepository: %w", err)
}
- cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.SubCmd{
+ cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubCmd{
Name: "repack",
Flags: []git.Option{
git.Flag{Name: "--quiet"},
diff --git a/internal/gitaly/service/operations/apply_patch.go b/internal/gitaly/service/operations/apply_patch.go
index 9cd025442..0c053280f 100644
--- a/internal/gitaly/service/operations/apply_patch.go
+++ b/internal/gitaly/service/operations/apply_patch.go
@@ -10,9 +10,9 @@ import (
"time"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -197,8 +197,8 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP
}
func validateUserApplyPatchHeader(header *gitalypb.UserApplyPatchRequest_Header) error {
- if header.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(header.GetRepository()); err != nil {
+ return err
}
if header.GetUser() == nil {
diff --git a/internal/gitaly/service/operations/branches.go b/internal/gitaly/service/operations/branches.go
index e8a34576e..8f8ba599c 100644
--- a/internal/gitaly/service/operations/branches.go
+++ b/internal/gitaly/service/operations/branches.go
@@ -4,10 +4,10 @@ import (
"context"
"errors"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -15,8 +15,8 @@ import (
)
func validateUserCreateBranchRequest(in *gitalypb.UserCreateBranchRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.BranchName) == 0 {
return errors.New("Bad Request (empty branch name)") //nolint:stylecheck
@@ -100,8 +100,8 @@ func (s *Server) UserCreateBranch(ctx context.Context, req *gitalypb.UserCreateB
}
func validateUserUpdateBranchGo(req *gitalypb.UserUpdateBranchRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.User == nil {
@@ -168,8 +168,8 @@ func (s *Server) UserUpdateBranch(ctx context.Context, req *gitalypb.UserUpdateB
}
func validateUserDeleteBranchRequest(in *gitalypb.UserDeleteBranchRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.GetBranchName()) == 0 {
return errors.New("bad request: empty branch name")
diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go
index 368100bbf..963c363fb 100644
--- a/internal/gitaly/service/operations/commit_files.go
+++ b/internal/gitaly/service/operations/commit_files.go
@@ -11,12 +11,12 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/remoterepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -420,8 +420,8 @@ func (s *Server) fetchMissingCommit(
}
func validateUserCommitFilesHeader(header *gitalypb.UserCommitFilesRequestHeader) error {
- if header.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(header.GetRepository()); err != nil {
+ return err
}
if header.GetUser() == nil {
return fmt.Errorf("empty User")
diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go
index 315bc96ea..6db99a311 100644
--- a/internal/gitaly/service/operations/merge.go
+++ b/internal/gitaly/service/operations/merge.go
@@ -8,18 +8,18 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func validateMergeBranchRequest(request *gitalypb.UserMergeBranchRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(request.GetRepository()); err != nil {
+ return err
}
if request.User == nil {
@@ -229,8 +229,8 @@ func (s *Server) UserMergeBranch(stream gitalypb.OperationService_UserMergeBranc
}
func validateFFRequest(in *gitalypb.UserFFBranchRequest) error {
- if in.Repository == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.Branch) == 0 {
@@ -309,8 +309,8 @@ func (s *Server) UserFFBranch(ctx context.Context, in *gitalypb.UserFFBranchRequ
}
func validateUserMergeToRefRequest(in *gitalypb.UserMergeToRefRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.FirstParentRef) == 0 && len(in.Branch) == 0 {
diff --git a/internal/gitaly/service/operations/rebase.go b/internal/gitaly/service/operations/rebase.go
index c585df4a1..d2ab62791 100644
--- a/internal/gitaly/service/operations/rebase.go
+++ b/internal/gitaly/service/operations/rebase.go
@@ -5,10 +5,10 @@ import (
"fmt"
"time"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -161,8 +161,8 @@ func (s *Server) UserRebaseConfirmable(stream gitalypb.OperationService_UserReba
var ErrInvalidBranch = errors.New("invalid branch name")
func validateUserRebaseConfirmableHeader(header *gitalypb.UserRebaseConfirmableRequest_Header) error {
- if header.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(header.GetRepository()); err != nil {
+ return err
}
if header.GetUser() == nil {
diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go
index a1939f05e..30822b430 100644
--- a/internal/gitaly/service/operations/rebase_test.go
+++ b/internal/gitaly/service/operations/rebase_test.go
@@ -812,7 +812,7 @@ func TestUserRebaseConfirmable_failedWithCode(t *testing.T) {
return buildHeaderRequest(repo, gittest.TestUser, "1", rebaseBranchName, branchCommitID, repo, "master")
},
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- "creating repo quarantine: creating object quarantine: getting repo path: GetPath: relative path missing",
+ "UserRebaseConfirmable: empty RelativePath",
"repo scoped: invalid Repository",
)),
},
diff --git a/internal/gitaly/service/operations/squash.go b/internal/gitaly/service/operations/squash.go
index 5085bd540..35cfb0951 100644
--- a/internal/gitaly/service/operations/squash.go
+++ b/internal/gitaly/service/operations/squash.go
@@ -5,9 +5,9 @@ import (
"errors"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting"
@@ -34,8 +34,8 @@ func (s *Server) UserSquash(ctx context.Context, req *gitalypb.UserSquashRequest
}
func validateUserSquashRequest(req *gitalypb.UserSquashRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.GetUser() == nil {
diff --git a/internal/gitaly/service/operations/submodules.go b/internal/gitaly/service/operations/submodules.go
index f49a895aa..1b3add4e0 100644
--- a/internal/gitaly/service/operations/submodules.go
+++ b/internal/gitaly/service/operations/submodules.go
@@ -8,10 +8,10 @@ import (
"strings"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -30,8 +30,8 @@ func (s *Server) UserUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpda
}
func validateUserUpdateSubmoduleRequest(req *gitalypb.UserUpdateSubmoduleRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.GetUser() == nil {
diff --git a/internal/gitaly/service/operations/tags.go b/internal/gitaly/service/operations/tags.go
index 893a2d330..0c8762bc1 100644
--- a/internal/gitaly/service/operations/tags.go
+++ b/internal/gitaly/service/operations/tags.go
@@ -8,12 +8,12 @@ import (
"regexp"
"time"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -21,8 +21,8 @@ import (
)
func validateUserDeleteTagRequest(in *gitalypb.UserDeleteTagRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.GetTagName()) == 0 {
return errors.New("empty tag name")
@@ -84,8 +84,8 @@ func validateUserCreateTag(req *gitalypb.UserCreateTagRequest) error {
return fmt.Errorf("tag message contains NUL byte")
}
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
return nil
diff --git a/internal/gitaly/service/operations/utils.go b/internal/gitaly/service/operations/utils.go
index 6d58e6f2d..8e872555e 100644
--- a/internal/gitaly/service/operations/utils.go
+++ b/internal/gitaly/service/operations/utils.go
@@ -4,7 +4,7 @@ import (
"fmt"
"time"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -18,8 +18,8 @@ type cherryPickOrRevertRequest interface {
}
func validateCherryPickOrRevertRequest(req cherryPickOrRevertRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.GetUser() == nil {
diff --git a/internal/gitaly/service/ref/branches.go b/internal/gitaly/service/ref/branches.go
index e99c62f44..686e29f3f 100644
--- a/internal/gitaly/service/ref/branches.go
+++ b/internal/gitaly/service/ref/branches.go
@@ -4,8 +4,8 @@ import (
"context"
"errors"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -13,14 +13,15 @@ import (
)
func (s *server) FindBranch(ctx context.Context, req *gitalypb.FindBranchRequest) (*gitalypb.FindBranchResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
if len(req.GetName()) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "Branch name cannot be empty")
}
- repo := s.localrepo(req.GetRepository())
+ repo := s.localrepo(repository)
branchName := git.NewReferenceNameFromBranchName(string(req.GetName()))
branchRef, err := repo.GetReference(ctx, branchName)
diff --git a/internal/gitaly/service/ref/delete_refs.go b/internal/gitaly/service/ref/delete_refs.go
index 9ac06d48e..198621184 100644
--- a/internal/gitaly/service/ref/delete_refs.go
+++ b/internal/gitaly/service/ref/delete_refs.go
@@ -6,10 +6,10 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
@@ -182,8 +182,8 @@ func hasAnyPrefix(s string, prefixes []string) bool {
}
func validateDeleteRefRequest(req *gitalypb.DeleteRefsRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.ExceptWithPrefix) > 0 && len(req.Refs) > 0 {
diff --git a/internal/gitaly/service/ref/find_all_tags.go b/internal/gitaly/service/ref/find_all_tags.go
index a07d225e0..5df28db8c 100644
--- a/internal/gitaly/service/ref/find_all_tags.go
+++ b/internal/gitaly/service/ref/find_all_tags.go
@@ -7,10 +7,10 @@ import (
"fmt"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -166,11 +166,12 @@ func (s *server) findAllTags(ctx context.Context, repo *localrepo.Repo, sortFiel
}
func (s *server) validateFindAllTagsRequest(request *gitalypb.FindAllTagsRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
- if _, err := s.locator.GetRepoPath(request.GetRepository()); err != nil {
+ if _, err := s.locator.GetRepoPath(repository); err != nil {
return fmt.Errorf("invalid git directory: %v", err)
}
diff --git a/internal/gitaly/service/ref/find_refs_by_oid.go b/internal/gitaly/service/ref/find_refs_by_oid.go
index bdadd7513..b6284723b 100644
--- a/internal/gitaly/service/ref/find_refs_by_oid.go
+++ b/internal/gitaly/service/ref/find_refs_by_oid.go
@@ -5,8 +5,8 @@ import (
"errors"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -52,8 +52,8 @@ func (s *server) FindRefsByOID(ctx context.Context, in *gitalypb.FindRefsByOIDRe
}
func validateFindRefsReq(in *gitalypb.FindRefsByOIDRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if in.GetOid() == "" {
diff --git a/internal/gitaly/service/ref/find_tag.go b/internal/gitaly/service/ref/find_tag.go
index 6c378d2df..ab340caea 100644
--- a/internal/gitaly/service/ref/find_tag.go
+++ b/internal/gitaly/service/ref/find_tag.go
@@ -7,9 +7,9 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -120,11 +120,12 @@ func (s *server) findTag(ctx context.Context, repo git.RepositoryExecutor, tagNa
}
func (s *server) validateFindTagRequest(in *gitalypb.FindTagRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return err
}
- if _, err := s.locator.GetRepoPath(in.GetRepository()); err != nil {
+ if _, err := s.locator.GetRepoPath(repository); err != nil {
return fmt.Errorf("invalid git directory: %v", err)
}
diff --git a/internal/gitaly/service/ref/list_refs.go b/internal/gitaly/service/ref/list_refs.go
index 512f17d28..24037f287 100644
--- a/internal/gitaly/service/ref/list_refs.go
+++ b/internal/gitaly/service/ref/list_refs.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/lines"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -48,8 +48,8 @@ func (s *server) ListRefs(in *gitalypb.ListRefsRequest, stream gitalypb.RefServi
}
func validateListRefsRequest(in *gitalypb.ListRefsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if len(in.GetPatterns()) < 1 {
return errors.New("patterns must have at least one entry")
diff --git a/internal/gitaly/service/ref/pack_refs.go b/internal/gitaly/service/ref/pack_refs.go
index 6fee884e3..81839f9f5 100644
--- a/internal/gitaly/service/ref/pack_refs.go
+++ b/internal/gitaly/service/ref/pack_refs.go
@@ -3,9 +3,9 @@ package ref
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/repository"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -23,10 +23,7 @@ func (s *server) PackRefs(ctx context.Context, in *gitalypb.PackRefsRequest) (*g
}
func validatePackRefsRequest(in *gitalypb.PackRefsRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
- return nil
+ return service.ValidateRepository(in.GetRepository())
}
func (s *server) packRefs(ctx context.Context, repository repository.GitRepo) error {
diff --git a/internal/gitaly/service/ref/pack_refs_test.go b/internal/gitaly/service/ref/pack_refs_test.go
index 267984ad3..d1c879718 100644
--- a/internal/gitaly/service/ref/pack_refs_test.go
+++ b/internal/gitaly/service/ref/pack_refs_test.go
@@ -89,7 +89,7 @@ func TestPackRefs_invalidRequest(t *testing.T) {
},
{
desc: "invalid storage name",
- repo: &gitalypb.Repository{StorageName: "foo"},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "foo"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
`GetStorageByName: no such storage: "foo"`,
"repo scoped: invalid Repository",
diff --git a/internal/gitaly/service/ref/refexists.go b/internal/gitaly/service/ref/refexists.go
index aab56ca0e..60a006b84 100644
--- a/internal/gitaly/service/ref/refexists.go
+++ b/internal/gitaly/service/ref/refexists.go
@@ -6,16 +6,16 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
// RefExists returns true if the given reference exists. The ref must start with the string `ref/`
func (s *server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) (*gitalypb.RefExistsResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
ref := string(in.Ref)
diff --git a/internal/gitaly/service/ref/refnames.go b/internal/gitaly/service/ref/refnames.go
index 958019d2c..1b9e95880 100644
--- a/internal/gitaly/service/ref/refnames.go
+++ b/internal/gitaly/service/ref/refnames.go
@@ -4,8 +4,8 @@ import (
"bufio"
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -15,8 +15,8 @@ import (
// FindAllBranchNames creates a stream of ref names for all branches in the given repository
func (s *server) FindAllBranchNames(in *gitalypb.FindAllBranchNamesRequest, stream gitalypb.RefService_FindAllBranchNamesServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
chunker := chunk.New(&findAllBranchNamesSender{stream: stream})
@@ -40,8 +40,8 @@ func (ts *findAllBranchNamesSender) Send() error {
// FindAllTagNames creates a stream of ref names for all tags in the given repository
func (s *server) FindAllTagNames(in *gitalypb.FindAllTagNamesRequest, stream gitalypb.RefService_FindAllTagNamesServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
chunker := chunk.New(&findAllTagNamesSender{stream: stream})
diff --git a/internal/gitaly/service/ref/refnames_containing.go b/internal/gitaly/service/ref/refnames_containing.go
index dc3db16f8..92e692095 100644
--- a/internal/gitaly/service/ref/refnames_containing.go
+++ b/internal/gitaly/service/ref/refnames_containing.go
@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -16,8 +16,8 @@ import (
// ListBranchNamesContainingCommit returns a maximum of in.GetLimit() Branch names
// which contain the SHA1 passed as argument
func (s *server) ListBranchNamesContainingCommit(in *gitalypb.ListBranchNamesContainingCommitRequest, stream gitalypb.RefService_ListBranchNamesContainingCommitServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if err := git.ObjectHashSHA1.ValidateHex(in.GetCommitId()); err != nil {
return helper.ErrInvalidArgument(err)
@@ -62,8 +62,8 @@ func (bs *branchNamesContainingCommitSender) Send() error {
// ListTagNamesContainingCommit returns a maximum of in.GetLimit() Tag names
// which contain the SHA1 passed as argument
func (s *server) ListTagNamesContainingCommit(in *gitalypb.ListTagNamesContainingCommitRequest, stream gitalypb.RefService_ListTagNamesContainingCommitServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if err := git.ObjectHashSHA1.ValidateHex(in.GetCommitId()); err != nil {
return helper.ErrInvalidArgument(err)
diff --git a/internal/gitaly/service/ref/refs.go b/internal/gitaly/service/ref/refs.go
index d1b9a23f9..2827764ac 100644
--- a/internal/gitaly/service/ref/refs.go
+++ b/internal/gitaly/service/ref/refs.go
@@ -7,8 +7,8 @@ import (
"math"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/lines"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -70,10 +70,11 @@ func (s *server) findRefs(ctx context.Context, writer lines.Sender, repo git.Rep
// FindDefaultBranchName returns the default branch name for the given repository
func (s *server) FindDefaultBranchName(ctx context.Context, in *gitalypb.FindDefaultBranchNameRequest) (*gitalypb.FindDefaultBranchNameResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
defaultBranch, err := repo.GetDefaultBranch(ctx)
if err != nil {
@@ -98,8 +99,8 @@ func parseSortKey(sortKey gitalypb.FindLocalBranchesRequest_SortBy) string {
// FindLocalBranches creates a stream of branches for all local branches in the given repository
func (s *server) FindLocalBranches(in *gitalypb.FindLocalBranchesRequest, stream gitalypb.RefService_FindLocalBranchesServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if err := s.findLocalBranches(in, stream); err != nil {
return helper.ErrInternal(err)
@@ -130,8 +131,8 @@ func (s *server) findLocalBranches(in *gitalypb.FindLocalBranchesRequest, stream
}
func (s *server) FindAllBranches(in *gitalypb.FindAllBranchesRequest, stream gitalypb.RefService_FindAllBranchesServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if err := s.findAllBranches(in, stream); err != nil {
return helper.ErrInternal(err)
diff --git a/internal/gitaly/service/ref/remote_branches.go b/internal/gitaly/service/ref/remote_branches.go
index 42543dc6a..972661d65 100644
--- a/internal/gitaly/service/ref/remote_branches.go
+++ b/internal/gitaly/service/ref/remote_branches.go
@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -46,8 +46,8 @@ func (s *server) findAllRemoteBranches(req *gitalypb.FindAllRemoteBranchesReques
}
func validateFindAllRemoteBranchesRequest(req *gitalypb.FindAllRemoteBranchesRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.GetRemoteName()) == 0 {
diff --git a/internal/gitaly/service/ref/tag_messages.go b/internal/gitaly/service/ref/tag_messages.go
index 87273b988..ec223bd7e 100644
--- a/internal/gitaly/service/ref/tag_messages.go
+++ b/internal/gitaly/service/ref/tag_messages.go
@@ -5,9 +5,9 @@ import (
"fmt"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -27,11 +27,7 @@ func (s *server) GetTagMessages(request *gitalypb.GetTagMessagesRequest, stream
}
func validateGetTagMessagesRequest(request *gitalypb.GetTagMessagesRequest) error {
- if request.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(request.GetRepository())
}
func (s *server) getAndStreamTagMessages(request *gitalypb.GetTagMessagesRequest, stream gitalypb.RefService_GetTagMessagesServer) error {
diff --git a/internal/gitaly/service/ref/tag_signatures.go b/internal/gitaly/service/ref/tag_signatures.go
index 6c1608ab3..1d2ca43a4 100644
--- a/internal/gitaly/service/ref/tag_signatures.go
+++ b/internal/gitaly/service/ref/tag_signatures.go
@@ -6,9 +6,9 @@ import (
"io"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -16,8 +16,8 @@ import (
)
func verifyGetTagSignaturesRequest(req *gitalypb.GetTagSignaturesRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.GetTagRevisions()) == 0 {
diff --git a/internal/gitaly/service/remote/find_remote_root_ref.go b/internal/gitaly/service/remote/find_remote_root_ref.go
index 275463e43..756d9dc15 100644
--- a/internal/gitaly/service/remote/find_remote_root_ref.go
+++ b/internal/gitaly/service/remote/find_remote_root_ref.go
@@ -7,8 +7,8 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -91,8 +91,8 @@ func (s *server) FindRemoteRootRef(ctx context.Context, in *gitalypb.FindRemoteR
if in.GetRemoteUrl() == "" {
return nil, helper.ErrInvalidArgumentf("missing remote URL")
}
- if in.Repository == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
ref, err := s.findRemoteRootRef(ctx, in)
diff --git a/internal/gitaly/service/remote/update_remote_mirror.go b/internal/gitaly/service/remote/update_remote_mirror.go
index 077a069dc..a6558d8e4 100644
--- a/internal/gitaly/service/remote/update_remote_mirror.go
+++ b/internal/gitaly/service/remote/update_remote_mirror.go
@@ -8,9 +8,9 @@ import (
"regexp"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -278,8 +278,8 @@ func newReferenceMatcher(branchMatchers [][]byte) (*regexp.Regexp, error) {
}
func validateUpdateRemoteMirrorRequest(ctx context.Context, req *gitalypb.UpdateRemoteMirrorRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.GetRemote() == nil {
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go
index 1a860284e..4c1e436bf 100644
--- a/internal/gitaly/service/repository/apply_gitattributes.go
+++ b/internal/gitaly/service/repository/apply_gitattributes.go
@@ -9,10 +9,10 @@ import (
"path/filepath"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/safe"
@@ -129,10 +129,11 @@ func (s *server) vote(ctx context.Context, oid git.ObjectID, phase voting.Phase)
}
func (s *server) ApplyGitattributes(ctx context.Context, in *gitalypb.ApplyGitattributesRequest) (*gitalypb.ApplyGitattributesResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
repoPath, err := s.locator.GetRepoPath(repo)
if err != nil {
return nil, err
diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go
index cd810aec6..ed2b49010 100644
--- a/internal/gitaly/service/repository/apply_gitattributes_test.go
+++ b/internal/gitaly/service/repository/apply_gitattributes_test.go
@@ -224,7 +224,7 @@ func TestApplyGitattributesFailure(t *testing.T) {
},
{
desc: "unknown storage provided",
- repo: &gitalypb.Repository{StorageName: "foo"},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "foo"},
revision: []byte("master"),
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
`GetStorageByName: no such storage: "foo"`,
@@ -236,7 +236,7 @@ func TestApplyGitattributesFailure(t *testing.T) {
repo: &gitalypb.Repository{RelativePath: repo.GetRelativePath()},
revision: []byte("master"),
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- `GetStorageByName: no such storage: ""`,
+ "empty StorageName",
"repo scoped: invalid Repository",
)),
},
diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go
index be6ffdd36..3192ab7ba 100644
--- a/internal/gitaly/service/repository/archive.go
+++ b/internal/gitaly/service/repository/archive.go
@@ -11,10 +11,10 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/smudge"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/log"
@@ -35,11 +35,12 @@ type archiveParams struct {
func (s *server) GetArchive(in *gitalypb.GetArchiveRequest, stream gitalypb.RepositoryService_GetArchiveServer) error {
ctx := stream.Context()
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
compressArgs, format := parseArchiveFormat(in.GetFormat())
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
repoRoot, err := repo.Path()
if err != nil {
diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go
index 660554b8f..5f6d403c0 100644
--- a/internal/gitaly/service/repository/archive_test.go
+++ b/internal/gitaly/service/repository/archive_test.go
@@ -380,7 +380,7 @@ func TestGetArchive_inputValidation(t *testing.T) {
format: gitalypb.GetArchiveRequest_TAR,
path: []byte("Here is a string...."),
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- "GetPath: relative path missing",
+ "empty RelativePath",
"repo scoped: invalid Repository",
)),
},
diff --git a/internal/gitaly/service/repository/backup_custom_hooks.go b/internal/gitaly/service/repository/backup_custom_hooks.go
index a9b49b8f0..f47fcb81d 100644
--- a/internal/gitaly/service/repository/backup_custom_hooks.go
+++ b/internal/gitaly/service/repository/backup_custom_hooks.go
@@ -5,7 +5,7 @@ import (
"path/filepath"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -16,8 +16,8 @@ import (
const customHooksDir = "custom_hooks"
func (s *server) BackupCustomHooks(in *gitalypb.BackupCustomHooksRequest, stream gitalypb.RepositoryService_BackupCustomHooksServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
repoPath, err := s.locator.GetPath(in.Repository)
if err != nil {
diff --git a/internal/gitaly/service/repository/calculate_checksum.go b/internal/gitaly/service/repository/calculate_checksum.go
index 84eb6f627..6bff6e61d 100644
--- a/internal/gitaly/service/repository/calculate_checksum.go
+++ b/internal/gitaly/service/repository/calculate_checksum.go
@@ -7,8 +7,8 @@ import (
"encoding/hex"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -16,10 +16,11 @@ import (
)
func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateChecksumRequest) (*gitalypb.CalculateChecksumResponse, error) {
- repo := in.GetRepository()
- if repo == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
+ repo := repository
repoPath, err := s.locator.GetRepoPath(repo)
if err != nil {
return nil, err
diff --git a/internal/gitaly/service/repository/cleanup.go b/internal/gitaly/service/repository/cleanup.go
index 6c3668126..2589dba8e 100644
--- a/internal/gitaly/service/repository/cleanup.go
+++ b/internal/gitaly/service/repository/cleanup.go
@@ -3,15 +3,16 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func (s *server) Cleanup(ctx context.Context, in *gitalypb.CleanupRequest) (*gitalypb.CleanupResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
repo := s.localrepo(in.GetRepository())
diff --git a/internal/gitaly/service/repository/cleanup_test.go b/internal/gitaly/service/repository/cleanup_test.go
index 931b7379f..726cc9b6d 100644
--- a/internal/gitaly/service/repository/cleanup_test.go
+++ b/internal/gitaly/service/repository/cleanup_test.go
@@ -173,7 +173,7 @@ func TestCleanup_invalidRequest(t *testing.T) {
},
{
desc: "storage doesn't exist",
- in: &gitalypb.Repository{StorageName: "stub"},
+ in: &gitalypb.Repository{RelativePath: "stub", StorageName: "stub"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
`GetStorageByName: no such storage: "stub"`,
"repo scoped: invalid Repository",
diff --git a/internal/gitaly/service/repository/commit_graph.go b/internal/gitaly/service/repository/commit_graph.go
index 1e340b834..b3f60dced 100644
--- a/internal/gitaly/service/repository/commit_graph.go
+++ b/internal/gitaly/service/repository/commit_graph.go
@@ -3,8 +3,8 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -14,11 +14,12 @@ func (s *server) WriteCommitGraph(
ctx context.Context,
in *gitalypb.WriteCommitGraphRequest,
) (*gitalypb.WriteCommitGraphResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
if in.GetSplitStrategy() != gitalypb.WriteCommitGraphRequest_SizeMultiple {
return nil, helper.ErrInvalidArgumentf("unsupported split strategy: %v", in.GetSplitStrategy())
diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go
index 7815b8399..59d577dd4 100644
--- a/internal/gitaly/service/repository/commit_graph_test.go
+++ b/internal/gitaly/service/repository/commit_graph_test.go
@@ -143,7 +143,7 @@ func TestWriteCommitGraph_validationChecks(t *testing.T) {
},
{
desc: "invalid storage",
- req: &gitalypb.WriteCommitGraphRequest{Repository: &gitalypb.Repository{StorageName: "invalid"}},
+ req: &gitalypb.WriteCommitGraphRequest{Repository: &gitalypb.Repository{RelativePath: "stub", StorageName: "invalid"}},
expectedErr: status.Error(codes.InvalidArgument, `getting commit-graph config: GetStorageByName: no such storage: "invalid"`),
},
{
diff --git a/internal/gitaly/service/repository/config.go b/internal/gitaly/service/repository/config.go
index d99cc36dc..a186e501c 100644
--- a/internal/gitaly/service/repository/config.go
+++ b/internal/gitaly/service/repository/config.go
@@ -5,7 +5,7 @@ import (
"os"
"path/filepath"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -18,10 +18,11 @@ func (s *server) GetConfig(
request *gitalypb.GetConfigRequest,
stream gitalypb.RepositoryService_GetConfigServer,
) error {
- if request.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repoPath, err := s.locator.GetPath(request.GetRepository())
+ repoPath, err := s.locator.GetPath(repository)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/repository/create_bundle.go b/internal/gitaly/service/repository/create_bundle.go
index 3acbcca16..0ede5ec18 100644
--- a/internal/gitaly/service/repository/create_bundle.go
+++ b/internal/gitaly/service/repository/create_bundle.go
@@ -3,8 +3,8 @@ package repository
import (
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -13,18 +13,18 @@ import (
)
func (s *server) CreateBundle(req *gitalypb.CreateBundleRequest, stream gitalypb.RepositoryService_CreateBundleServer) error {
- repo := req.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgumentf("CreateBundle: %w", gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgumentf("CreateBundle: %w", err)
}
ctx := stream.Context()
- if _, err := s.Cleanup(ctx, &gitalypb.CleanupRequest{Repository: req.GetRepository()}); err != nil {
+ if _, err := s.Cleanup(ctx, &gitalypb.CleanupRequest{Repository: repository}); err != nil {
return helper.ErrInternalf("running Cleanup on repository: %w", err)
}
- cmd, err := s.gitCmdFactory.New(ctx, repo, git.SubSubCmd{
+ cmd, err := s.gitCmdFactory.New(ctx, repository, git.SubSubCmd{
Name: "bundle",
Action: "create",
Flags: []git.Option{git.OutputToStdout, git.Flag{Name: "--all"}},
diff --git a/internal/gitaly/service/repository/create_bundle_from_ref_list.go b/internal/gitaly/service/repository/create_bundle_from_ref_list.go
index 428ea6749..aa031e33c 100644
--- a/internal/gitaly/service/repository/create_bundle_from_ref_list.go
+++ b/internal/gitaly/service/repository/create_bundle_from_ref_list.go
@@ -5,8 +5,8 @@ import (
"io"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -20,13 +20,14 @@ func (s *server) CreateBundleFromRefList(stream gitalypb.RepositoryService_Creat
return err
}
- if firstRequest.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := firstRequest.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
ctx := stream.Context()
- if _, err := s.Cleanup(ctx, &gitalypb.CleanupRequest{Repository: firstRequest.GetRepository()}); err != nil {
+ if _, err := s.Cleanup(ctx, &gitalypb.CleanupRequest{Repository: repository}); err != nil {
return err
}
@@ -48,7 +49,7 @@ func (s *server) CreateBundleFromRefList(stream gitalypb.RepositoryService_Creat
var stderr bytes.Buffer
- repo := s.localrepo(firstRequest.GetRepository())
+ repo := s.localrepo(repository)
cmd, err := repo.Exec(ctx,
git.SubSubCmd{
Name: "bundle",
diff --git a/internal/gitaly/service/repository/create_fork.go b/internal/gitaly/service/repository/create_fork.go
index 36265ed84..a4a46fbdf 100644
--- a/internal/gitaly/service/repository/create_fork.go
+++ b/internal/gitaly/service/repository/create_fork.go
@@ -6,8 +6,8 @@ import (
"os"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -21,8 +21,8 @@ func (s *server) CreateFork(ctx context.Context, req *gitalypb.CreateForkRequest
if sourceRepository == nil {
return nil, status.Errorf(codes.InvalidArgument, "CreateFork: empty SourceRepository")
}
- if targetRepository == nil {
- return nil, helper.ErrInvalidArgumentf("CreateFork: %w", gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return nil, helper.ErrInvalidArgumentf("CreateFork: %w", err)
}
if err := s.createRepository(ctx, targetRepository, func(repo *gitalypb.Repository) error {
diff --git a/internal/gitaly/service/repository/create_repository.go b/internal/gitaly/service/repository/create_repository.go
index d44229c53..7afedd54c 100644
--- a/internal/gitaly/service/repository/create_repository.go
+++ b/internal/gitaly/service/repository/create_repository.go
@@ -3,18 +3,19 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func (s *server) CreateRepository(ctx context.Context, req *gitalypb.CreateRepositoryRequest) (*gitalypb.CreateRepositoryResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
if err := s.createRepository(
ctx,
- req.GetRepository(),
+ repository,
func(repo *gitalypb.Repository) error {
// We do not want to seed the repository with any contents, so we just
// return directly.
diff --git a/internal/gitaly/service/repository/create_repository_from_bundle.go b/internal/gitaly/service/repository/create_repository_from_bundle.go
index d5b5f3797..13f07d5d5 100644
--- a/internal/gitaly/service/repository/create_repository_from_bundle.go
+++ b/internal/gitaly/service/repository/create_repository_from_bundle.go
@@ -8,8 +8,8 @@ import (
"path/filepath"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/tempdir"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -24,9 +24,9 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr
return status.Errorf(codes.Internal, "CreateRepositoryFromBundle: first request failed: %v", err)
}
- repo := firstRequest.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgumentf("CreateRepositoryFromBundle: %w", gitalyerrors.ErrEmptyRepository)
+ repository := firstRequest.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgumentf("CreateRepositoryFromBundle: %w", err)
}
ctx := stream.Context()
@@ -42,6 +42,7 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr
return request.GetData(), err
})
+ repo := repository
bundleDir, err := tempdir.New(ctx, repo.GetStorageName(), s.locator)
if err != nil {
return helper.ErrInternalf("creating bundle directory: %w", err)
diff --git a/internal/gitaly/service/repository/create_repository_from_snapshot.go b/internal/gitaly/service/repository/create_repository_from_snapshot.go
index b938b586b..39b88cebb 100644
--- a/internal/gitaly/service/repository/create_repository_from_snapshot.go
+++ b/internal/gitaly/service/repository/create_repository_from_snapshot.go
@@ -9,7 +9,7 @@ import (
"time"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/labkit/correlation"
@@ -126,10 +126,11 @@ func untar(ctx context.Context, path string, in *gitalypb.CreateRepositoryFromSn
}
func (s *server) CreateRepositoryFromSnapshot(ctx context.Context, in *gitalypb.CreateRepositoryFromSnapshotRequest) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- if err := s.createRepository(ctx, in.GetRepository(), func(repo *gitalypb.Repository) error {
+ if err := s.createRepository(ctx, repository, func(repo *gitalypb.Repository) error {
path, err := s.locator.GetPath(repo)
if err != nil {
return helper.ErrInternalf("getting repo path: %w", err)
diff --git a/internal/gitaly/service/repository/create_repository_from_url.go b/internal/gitaly/service/repository/create_repository_from_url.go
index e23568e45..89865da71 100644
--- a/internal/gitaly/service/repository/create_repository_from_url.go
+++ b/internal/gitaly/service/repository/create_repository_from_url.go
@@ -9,8 +9,8 @@ import (
"os"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -132,8 +132,8 @@ func (s *server) CreateRepositoryFromURL(ctx context.Context, req *gitalypb.Crea
}
func validateCreateRepositoryFromURLRequest(req *gitalypb.CreateRepositoryFromURLRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.GetUrl() == "" {
diff --git a/internal/gitaly/service/repository/fetch.go b/internal/gitaly/service/repository/fetch.go
index 08d7fd4a3..2aa17ad26 100644
--- a/internal/gitaly/service/repository/fetch.go
+++ b/internal/gitaly/service/repository/fetch.go
@@ -5,17 +5,17 @@ import (
"errors"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/remoterepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func validateFetchSourceBranchRequest(in *gitalypb.FetchSourceBranchRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(in.GetSourceBranch()); err != nil {
return err
diff --git a/internal/gitaly/service/repository/fetch_bundle.go b/internal/gitaly/service/repository/fetch_bundle.go
index 2f3fb560e..44bdcca92 100644
--- a/internal/gitaly/service/repository/fetch_bundle.go
+++ b/internal/gitaly/service/repository/fetch_bundle.go
@@ -7,9 +7,9 @@ import (
"os"
"path/filepath"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/tempdir"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -26,8 +26,8 @@ func (s *server) FetchBundle(stream gitalypb.RepositoryService_FetchBundleServer
return helper.ErrInternalf("first request: %v", err)
}
- if firstRequest.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(firstRequest.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
firstRead := true
diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go
index baa70c064..d8014c56a 100644
--- a/internal/gitaly/service/repository/fetch_remote.go
+++ b/internal/gitaly/service/repository/fetch_remote.go
@@ -7,9 +7,9 @@ import (
"io"
"time"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
@@ -162,8 +162,8 @@ func didTagsChange(r io.Reader) bool {
}
func (s *server) validateFetchRemoteRequest(req *gitalypb.FetchRemoteRequest) error {
- if req.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if req.GetRemoteParams() == nil {
diff --git a/internal/gitaly/service/repository/fsck.go b/internal/gitaly/service/repository/fsck.go
index b705e8a93..d3adb291e 100644
--- a/internal/gitaly/service/repository/fsck.go
+++ b/internal/gitaly/service/repository/fsck.go
@@ -4,21 +4,20 @@ import (
"bytes"
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
func (s *server) Fsck(ctx context.Context, req *gitalypb.FsckRequest) (*gitalypb.FsckResponse, error) {
- var stdout, stderr bytes.Buffer
-
- repo := req.GetRepository()
- if repo == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- cmd, err := s.gitCmdFactory.New(ctx, repo,
+ var stdout, stderr bytes.Buffer
+ cmd, err := s.gitCmdFactory.New(ctx, repository,
git.SubCmd{Name: "fsck"},
git.WithStdout(&stdout),
git.WithStderr(&stderr),
diff --git a/internal/gitaly/service/repository/fullpath.go b/internal/gitaly/service/repository/fullpath.go
index bc85a72a5..83ed67fff 100644
--- a/internal/gitaly/service/repository/fullpath.go
+++ b/internal/gitaly/service/repository/fullpath.go
@@ -4,8 +4,8 @@ import (
"context"
"strings"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -18,15 +18,16 @@ func (s *server) SetFullPath(
ctx context.Context,
request *gitalypb.SetFullPathRequest,
) (*gitalypb.SetFullPathResponse, error) {
- if request.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
if len(request.GetPath()) == 0 {
return nil, helper.ErrInvalidArgumentf("no path provided")
}
- repo := s.localrepo(request.GetRepository())
+ repo := s.localrepo(repository)
if err := repo.SetConfig(ctx, fullPathKey, request.GetPath(), s.txManager); err != nil {
return nil, helper.ErrInternalf("setting config: %w", err)
@@ -38,11 +39,12 @@ func (s *server) SetFullPath(
// FullPath reads the path from the repository's gitconfig under the
// "gitlab.fullpath" key.
func (s *server) FullPath(ctx context.Context, request *gitalypb.FullPathRequest) (*gitalypb.FullPathResponse, error) {
- if request.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(request.GetRepository())
+ repo := s.localrepo(repository)
var stdout strings.Builder
err := repo.ExecAndWait(ctx, git.SubCmd{
Name: "config",
diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go
index a06a411eb..d2020f2fd 100644
--- a/internal/gitaly/service/repository/gc.go
+++ b/internal/gitaly/service/repository/gc.go
@@ -10,12 +10,12 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/status"
@@ -27,11 +27,12 @@ func (s *server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollect
"WriteBitmaps": in.GetCreateBitmap(),
}).Debug("GarbageCollect")
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
if err := housekeeping.CleanupWorktrees(ctx, repo); err != nil {
return nil, err
diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go
index 3cc4a67ee..f5008009c 100644
--- a/internal/gitaly/service/repository/gc_test.go
+++ b/internal/gitaly/service/repository/gc_test.go
@@ -414,7 +414,7 @@ func TestGarbageCollectFailure(t *testing.T) {
)),
},
{
- repo: &gitalypb.Repository{StorageName: "foo"},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "foo"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
`GetStorageByName: no such storage: "foo"`,
"repo scoped: invalid Repository",
diff --git a/internal/gitaly/service/repository/info_attributes.go b/internal/gitaly/service/repository/info_attributes.go
index cf2c86031..273b2cd12 100644
--- a/internal/gitaly/service/repository/info_attributes.go
+++ b/internal/gitaly/service/repository/info_attributes.go
@@ -5,7 +5,7 @@ import (
"os"
"path/filepath"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -14,10 +14,11 @@ import (
)
func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream gitalypb.RepositoryService_GetInfoAttributesServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repoPath, err := s.locator.GetRepoPath(in.GetRepository())
+ repoPath, err := s.locator.GetRepoPath(repository)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go
index 2f9d9dc55..ac7284677 100644
--- a/internal/gitaly/service/repository/license.go
+++ b/internal/gitaly/service/repository/license.go
@@ -13,11 +13,11 @@ import (
"github.com/go-enry/go-license-detector/v4/licensedb"
"github.com/go-enry/go-license-detector/v4/licensedb/api"
"github.com/go-enry/go-license-detector/v4/licensedb/filer"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/rubyserver"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -41,11 +41,12 @@ var nicknameByLicenseIdentifier = map[string]string{
}
func (s *server) FindLicense(ctx context.Context, req *gitalypb.FindLicenseRequest) (*gitalypb.FindLicenseResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
if featureflag.GoFindLicense.IsEnabled(ctx) {
- repo := localrepo.New(s.locator, s.gitCmdFactory, s.catfileCache, req.GetRepository())
+ repo := localrepo.New(s.locator, s.gitCmdFactory, s.catfileCache, repository)
hasHeadRevision, err := repo.HasRevision(ctx, "HEAD")
if err != nil {
@@ -132,7 +133,7 @@ func (s *server) FindLicense(ctx context.Context, req *gitalypb.FindLicenseReque
if err != nil {
return nil, err
}
- clientCtx, err := rubyserver.SetHeaders(ctx, s.locator, req.GetRepository())
+ clientCtx, err := rubyserver.SetHeaders(ctx, s.locator, repository)
if err != nil {
return nil, err
}
diff --git a/internal/gitaly/service/repository/merge_base.go b/internal/gitaly/service/repository/merge_base.go
index 21486caf6..38290bb81 100644
--- a/internal/gitaly/service/repository/merge_base.go
+++ b/internal/gitaly/service/repository/merge_base.go
@@ -4,8 +4,8 @@ import (
"context"
"io"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -14,8 +14,9 @@ import (
)
func (s *server) FindMergeBase(ctx context.Context, req *gitalypb.FindMergeBaseRequest) (*gitalypb.FindMergeBaseResponse, error) {
- if req.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
var revisions []string
for _, rev := range req.GetRevisions() {
@@ -26,7 +27,7 @@ func (s *server) FindMergeBase(ctx context.Context, req *gitalypb.FindMergeBaseR
return nil, status.Errorf(codes.InvalidArgument, "FindMergeBase: at least 2 revisions are required")
}
- cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(),
+ cmd, err := s.gitCmdFactory.New(ctx, repository,
git.SubCmd{
Name: "merge-base",
Args: revisions,
diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go
index e2d899474..4452606fd 100644
--- a/internal/gitaly/service/repository/midx.go
+++ b/internal/gitaly/service/repository/midx.go
@@ -11,11 +11,11 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"google.golang.org/grpc/status"
@@ -27,12 +27,12 @@ const (
)
func (s *server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest) (*gitalypb.MidxRepackResponse, error) {
- repoProto := in.GetRepository()
- if repoProto == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(repoProto)
+ repo := s.localrepo(repository)
if err := repo.SetConfig(ctx, "core.multiPackIndex", "true", s.txManager); err != nil {
if _, ok := status.FromError(err); ok {
@@ -42,7 +42,7 @@ func (s *server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest)
}
for _, cmd := range []midxSubCommand{s.midxWrite, s.midxExpire, s.midxRepack} {
- if err := s.safeMidxCommand(ctx, repoProto, cmd); err != nil {
+ if err := s.safeMidxCommand(ctx, repository, cmd); err != nil {
if git.IsInvalidArgErr(err) {
return nil, helper.ErrInvalidArgumentf("MidxRepack: %w", err)
}
diff --git a/internal/gitaly/service/repository/midx_test.go b/internal/gitaly/service/repository/midx_test.go
index 1c5e3fc20..800dbe126 100644
--- a/internal/gitaly/service/repository/midx_test.go
+++ b/internal/gitaly/service/repository/midx_test.go
@@ -299,7 +299,7 @@ func TestMidxRepack_validationChecks(t *testing.T) {
},
{
desc: "invalid storage",
- req: &gitalypb.MidxRepackRequest{Repository: &gitalypb.Repository{StorageName: "invalid"}},
+ req: &gitalypb.MidxRepackRequest{Repository: &gitalypb.Repository{RelativePath: "stub", StorageName: "invalid"}},
expectedErr: status.Error(codes.InvalidArgument, `GetStorageByName: no such storage: "invalid"`),
},
{
diff --git a/internal/gitaly/service/repository/optimize.go b/internal/gitaly/service/repository/optimize.go
index 97119c39d..0d98d2283 100644
--- a/internal/gitaly/service/repository/optimize.go
+++ b/internal/gitaly/service/repository/optimize.go
@@ -3,8 +3,8 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -44,11 +44,12 @@ func (s *server) OptimizeRepository(ctx context.Context, in *gitalypb.OptimizeRe
}
func (s *server) validateOptimizeRepositoryRequest(in *gitalypb.OptimizeRepositoryRequest) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- _, err := s.locator.GetRepoPath(in.GetRepository())
+ _, err := s.locator.GetRepoPath(repository)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/repository/prune_unreachable_objects.go b/internal/gitaly/service/repository/prune_unreachable_objects.go
index 2ae3f8394..e709743a7 100644
--- a/internal/gitaly/service/repository/prune_unreachable_objects.go
+++ b/internal/gitaly/service/repository/prune_unreachable_objects.go
@@ -3,10 +3,10 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -19,11 +19,12 @@ func (s *server) PruneUnreachableObjects(
ctx context.Context,
request *gitalypb.PruneUnreachableObjectsRequest,
) (*gitalypb.PruneUnreachableObjectsResponse, error) {
- if request.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := request.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(request.GetRepository())
+ repo := s.localrepo(repository)
// Verify that the repository exists on-disk such that we can return a proper gRPC code in
// case it doesn't.
diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go
index d76d72a44..c7f91b6e1 100644
--- a/internal/gitaly/service/repository/raw_changes.go
+++ b/internal/gitaly/service/repository/raw_changes.go
@@ -7,10 +7,10 @@ import (
"regexp"
"strconv"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/rawdiff"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/chunk"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -19,10 +19,11 @@ import (
func (s *server) GetRawChanges(req *gitalypb.GetRawChangesRequest, stream gitalypb.RepositoryService_GetRawChangesServer) error {
ctx := stream.Context()
- if req.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(req.GetRepository())
+ repo := s.localrepo(repository)
objectInfoReader, cancel, err := s.catfileCache.ObjectInfoReader(stream.Context(), repo)
if err != nil {
diff --git a/internal/gitaly/service/repository/remove.go b/internal/gitaly/service/repository/remove.go
index 3e786110a..8ee6e6de2 100644
--- a/internal/gitaly/service/repository/remove.go
+++ b/internal/gitaly/service/repository/remove.go
@@ -8,7 +8,7 @@ import (
"path/filepath"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/safe"
@@ -18,16 +18,16 @@ import (
)
func (s *server) RemoveRepository(ctx context.Context, in *gitalypb.RemoveRepositoryRequest) (*gitalypb.RemoveRepositoryResponse, error) {
- repo := in.GetRepository()
- if repo == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- path, err := s.locator.GetPath(repo)
+ path, err := s.locator.GetPath(repository)
if err != nil {
return nil, helper.ErrInternal(err)
}
- tempDir, err := s.locator.TempDir(repo.GetStorageName())
+ tempDir, err := s.locator.TempDir(repository.GetStorageName())
if err != nil {
return nil, helper.ErrInternalf("temporary directory: %w", err)
}
@@ -80,7 +80,7 @@ func (s *server) RemoveRepository(ctx context.Context, in *gitalypb.RemoveReposi
return nil, helper.ErrInternalf("re-statting repository: %w", err)
}
- if err := s.voteOnAction(ctx, repo, voting.Prepared); err != nil {
+ if err := s.voteOnAction(ctx, repository, voting.Prepared); err != nil {
return nil, helper.ErrInternalf("vote on rename: %v", err)
}
@@ -95,7 +95,7 @@ func (s *server) RemoveRepository(ctx context.Context, in *gitalypb.RemoveReposi
return nil, helper.ErrInternalf("removing repository: %w", err)
}
- if err := s.voteOnAction(ctx, repo, voting.Committed); err != nil {
+ if err := s.voteOnAction(ctx, repository, voting.Committed); err != nil {
return nil, helper.ErrInternalf("vote on finalizing: %v", err)
}
diff --git a/internal/gitaly/service/repository/rename.go b/internal/gitaly/service/repository/rename.go
index cb5c5d172..050e46832 100644
--- a/internal/gitaly/service/repository/rename.go
+++ b/internal/gitaly/service/repository/rename.go
@@ -8,7 +8,7 @@ import (
"path/filepath"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/safe"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -97,8 +97,8 @@ func (s *server) renameRepository(ctx context.Context, sourceRepo, targetRepo *g
}
func validateRenameRepositoryRequest(in *gitalypb.RenameRepositoryRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
if in.GetRelativePath() == "" {
diff --git a/internal/gitaly/service/repository/repack.go b/internal/gitaly/service/repository/repack.go
index 3795493f4..3231b969c 100644
--- a/internal/gitaly/service/repository/repack.go
+++ b/internal/gitaly/service/repository/repack.go
@@ -5,8 +5,8 @@ import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -24,11 +24,12 @@ func init() {
}
func (s *server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest) (*gitalypb.RepackFullResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
cfg := housekeeping.RepackObjectsConfig{
FullRepack: true,
WriteBitmap: in.GetCreateBitmap(),
@@ -53,11 +54,12 @@ func (s *server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest)
}
func (s *server) RepackIncremental(ctx context.Context, in *gitalypb.RepackIncrementalRequest) (*gitalypb.RepackIncrementalResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
cfg := housekeeping.RepackObjectsConfig{
FullRepack: false,
WriteBitmap: false,
diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go
index 5e7c78df0..b8ef8a5d6 100644
--- a/internal/gitaly/service/repository/repack_test.go
+++ b/internal/gitaly/service/repository/repack_test.go
@@ -122,7 +122,7 @@ func TestRepackIncrementalFailure(t *testing.T) {
},
{
desc: "invalid storage name",
- repo: &gitalypb.Repository{StorageName: "foo"},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "foo"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
`repacking objects: GetStorageByName: no such storage: "foo"`,
"repo scoped: invalid Repository",
@@ -132,7 +132,7 @@ func TestRepackIncrementalFailure(t *testing.T) {
desc: "no storage name",
repo: &gitalypb.Repository{RelativePath: "bar"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- `repacking objects: GetStorageByName: no such storage: ""`,
+ "empty StorageName",
"repo scoped: invalid Repository",
)),
},
@@ -270,13 +270,13 @@ func TestRepackFullFailure(t *testing.T) {
},
{
desc: "invalid storage name",
- repo: &gitalypb.Repository{StorageName: "foo"},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "foo"},
err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(`repacking objects: GetStorageByName: no such storage: "foo"`, "repo scoped: invalid Repository")),
},
{
desc: "no storage name",
repo: &gitalypb.Repository{RelativePath: "bar"},
- err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(`repacking objects: GetStorageByName: no such storage: ""`, "repo scoped: invalid Repository")),
+ err: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage("empty StorageName", "repo scoped: invalid Repository")),
},
{
desc: "non-existing repo",
diff --git a/internal/gitaly/service/repository/replicate.go b/internal/gitaly/service/repository/replicate.go
index 13e798dca..0c77e741c 100644
--- a/internal/gitaly/service/repository/replicate.go
+++ b/internal/gitaly/service/repository/replicate.go
@@ -13,10 +13,10 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/client"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/remoterepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
@@ -91,8 +91,8 @@ func (s *server) ReplicateRepository(ctx context.Context, in *gitalypb.Replicate
}
func validateReplicateRepository(in *gitalypb.ReplicateRepositoryRequest) error {
- if in.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return err
}
if in.GetSource() == nil {
diff --git a/internal/gitaly/service/repository/repository.go b/internal/gitaly/service/repository/repository.go
index 02686fa2c..805fe26bc 100644
--- a/internal/gitaly/service/repository/repository.go
+++ b/internal/gitaly/service/repository/repository.go
@@ -3,7 +3,7 @@ package repository
import (
"context"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -17,8 +17,8 @@ func (s *server) Exists(ctx context.Context, in *gitalypb.RepositoryExistsReques
}
func (s *server) RepositoryExists(ctx context.Context, in *gitalypb.RepositoryExistsRequest) (*gitalypb.RepositoryExistsResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
path, err := s.locator.GetPath(in.Repository)
if err != nil {
@@ -29,10 +29,11 @@ func (s *server) RepositoryExists(ctx context.Context, in *gitalypb.RepositoryEx
}
func (s *server) HasLocalBranches(ctx context.Context, in *gitalypb.HasLocalBranchesRequest) (*gitalypb.HasLocalBranchesResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- hasBranches, err := s.localrepo(in.GetRepository()).HasBranches(ctx)
+ hasBranches, err := s.localrepo(repository).HasBranches(ctx)
if err != nil {
return nil, helper.ErrInternal(err)
}
diff --git a/internal/gitaly/service/repository/restore_custom_hooks.go b/internal/gitaly/service/repository/restore_custom_hooks.go
index 104055449..cfb7f97c3 100644
--- a/internal/gitaly/service/repository/restore_custom_hooks.go
+++ b/internal/gitaly/service/repository/restore_custom_hooks.go
@@ -9,7 +9,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
@@ -32,9 +32,9 @@ func (s *server) RestoreCustomHooks(stream gitalypb.RepositoryService_RestoreCus
return status.Errorf(codes.Internal, "RestoreCustomHooks: first request failed %v", err)
}
- repo := firstRequest.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgumentf("RestoreCustomHooks: %w", gitalyerrors.ErrEmptyRepository)
+ repository := firstRequest.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgumentf("RestoreCustomHooks: %w", err)
}
reader := streamio.NewReader(func() ([]byte, error) {
@@ -48,7 +48,7 @@ func (s *server) RestoreCustomHooks(stream gitalypb.RepositoryService_RestoreCus
return request.GetData(), err
})
- repoPath, err := s.locator.GetPath(repo)
+ repoPath, err := s.locator.GetPath(repository)
if err != nil {
return status.Errorf(codes.Internal, "RestoreCustomHooks: getting repo path failed %v", err)
}
@@ -82,14 +82,14 @@ func (s *server) restoreCustomHooksWithVoting(stream gitalypb.RepositoryService_
ctx := stream.Context()
- repo := firstRequest.GetRepository()
- if repo == nil {
- return helper.ErrInvalidArgumentf("RestoreCustomHooks: %w", gitalyerrors.ErrEmptyRepository)
+ repository := firstRequest.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgumentf("RestoreCustomHooks: %w", err)
}
v := voting.NewVoteHash()
- repoPath, err := s.locator.GetRepoPath(repo)
+ repoPath, err := s.locator.GetRepoPath(repository)
if err != nil {
return helper.ErrInternalf("RestoreCustomHooks: getting repo path failed %w", err)
}
diff --git a/internal/gitaly/service/repository/search_files.go b/internal/gitaly/service/repository/search_files.go
index a7daadef6..a7b2cbdb6 100644
--- a/internal/gitaly/service/repository/search_files.go
+++ b/internal/gitaly/service/repository/search_files.go
@@ -8,9 +8,9 @@ import (
"regexp"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -146,8 +146,8 @@ type searchFilesRequest interface {
}
func validateSearchFilesRequest(req searchFilesRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if len(req.GetQuery()) == 0 {
diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go
index e6e06554d..e0b511d37 100644
--- a/internal/gitaly/service/repository/search_files_test.go
+++ b/internal/gitaly/service/repository/search_files_test.go
@@ -239,13 +239,13 @@ func TestSearchFilesByContentFailure(t *testing.T) {
}{
{
desc: "empty request",
- repo: &gitalypb.Repository{},
+ repo: repo,
code: codes.InvalidArgument,
msg: "no query given",
},
{
desc: "only query given",
- repo: &gitalypb.Repository{},
+ repo: repo,
query: "foo",
code: codes.InvalidArgument,
msg: "no ref given",
@@ -591,14 +591,20 @@ func TestSearchFilesByNameFailure(t *testing.T) {
msg string
}{
{
- desc: "empty request",
+ desc: "repository not initialized",
repo: &gitalypb.Repository{},
code: codes.InvalidArgument,
+ msg: "empty StorageName",
+ },
+ {
+ desc: "empty request",
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "stub"},
+ code: codes.InvalidArgument,
msg: "no query given",
},
{
desc: "only query given",
- repo: &gitalypb.Repository{},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "stub"},
query: "foo",
code: codes.InvalidArgument,
msg: "no ref given",
@@ -612,7 +618,7 @@ func TestSearchFilesByNameFailure(t *testing.T) {
},
{
desc: "invalid filter",
- repo: &gitalypb.Repository{},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "stub"},
query: "foo",
ref: "master",
filter: "+*.",
@@ -621,7 +627,7 @@ func TestSearchFilesByNameFailure(t *testing.T) {
},
{
desc: "filter longer than max",
- repo: &gitalypb.Repository{},
+ repo: &gitalypb.Repository{RelativePath: "stub", StorageName: "stub"},
query: "foo",
ref: "master",
filter: strings.Repeat(".", searchFilesFilterMaxLength+1),
diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go
index 8e7af1566..29662b8fa 100644
--- a/internal/gitaly/service/repository/size.go
+++ b/internal/gitaly/service/repository/size.go
@@ -9,13 +9,13 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gitpipe"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/objectpool"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
@@ -34,10 +34,11 @@ import (
// flag can be enabled to return the alternative repository size calculation
// instead of the size derived from the disk usage command.
func (s *server) RepositorySize(ctx context.Context, in *gitalypb.RepositorySizeRequest) (*gitalypb.RepositorySizeResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
path, err := repo.Path()
if err != nil {
@@ -165,10 +166,11 @@ func calculateSizeWithRevlist(ctx context.Context, repo *localrepo.Repo) (int64,
}
func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObjectDirectorySizeRequest) (*gitalypb.GetObjectDirectorySizeResponse, error) {
- if in.GetRepository() == nil {
- return nil, helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return nil, helper.ErrInvalidArgument(err)
}
- repo := s.localrepo(in.GetRepository())
+ repo := s.localrepo(repository)
path, err := repo.ObjectDirectoryPath()
if err != nil {
diff --git a/internal/gitaly/service/repository/snapshot.go b/internal/gitaly/service/repository/snapshot.go
index ffb54b717..7144b1271 100644
--- a/internal/gitaly/service/repository/snapshot.go
+++ b/internal/gitaly/service/repository/snapshot.go
@@ -8,9 +8,9 @@ import (
"regexp"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/archive"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -22,8 +22,8 @@ var objectFiles = []*regexp.Regexp{
}
func (s *server) GetSnapshot(in *gitalypb.GetSnapshotRequest, stream gitalypb.RepositoryService_GetSnapshotServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(in.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
path, err := s.locator.GetRepoPath(in.Repository)
diff --git a/internal/gitaly/service/repository/write_ref.go b/internal/gitaly/service/repository/write_ref.go
index 1e86f3fcd..659a1abaa 100644
--- a/internal/gitaly/service/repository/write_ref.go
+++ b/internal/gitaly/service/repository/write_ref.go
@@ -5,10 +5,10 @@ import (
"context"
"fmt"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -88,8 +88,8 @@ func updateRef(ctx context.Context, repo *localrepo.Repo, req *gitalypb.WriteRef
}
func validateWriteRefRequest(req *gitalypb.WriteRefRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if err := git.ValidateRevision(req.Ref); err != nil {
return fmt.Errorf("invalid ref: %v", err)
diff --git a/internal/gitaly/service/smarthttp/inforefs.go b/internal/gitaly/service/smarthttp/inforefs.go
index 1b54245f3..8799f517f 100644
--- a/internal/gitaly/service/smarthttp/inforefs.go
+++ b/internal/gitaly/service/smarthttp/inforefs.go
@@ -7,9 +7,9 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -21,10 +21,11 @@ const (
)
func (s *server) InfoRefsUploadPack(in *gitalypb.InfoRefsRequest, stream gitalypb.SmartHTTPService_InfoRefsUploadPackServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repoPath, err := s.locator.GetRepoPath(in.GetRepository())
+ repoPath, err := s.locator.GetRepoPath(repository)
if err != nil {
return err
}
@@ -39,10 +40,11 @@ func (s *server) InfoRefsUploadPack(in *gitalypb.InfoRefsRequest, stream gitalyp
}
func (s *server) InfoRefsReceivePack(in *gitalypb.InfoRefsRequest, stream gitalypb.SmartHTTPService_InfoRefsReceivePackServer) error {
- if in.GetRepository() == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ repository := in.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return helper.ErrInvalidArgument(err)
}
- repoPath, err := s.locator.GetRepoPath(in.GetRepository())
+ repoPath, err := s.locator.GetRepoPath(repository)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go
index 8b454665a..f7c1e123e 100644
--- a/internal/gitaly/service/smarthttp/receive_pack.go
+++ b/internal/gitaly/service/smarthttp/receive_pack.go
@@ -5,8 +5,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting"
@@ -101,8 +101,8 @@ func validateReceivePackRequest(req *gitalypb.PostReceivePackRequest) error {
if req.Data != nil {
return helper.ErrInvalidArgumentf("non-empty Data")
}
- if req.Repository == nil {
- return helper.ErrInvalidArgument(gitalyerrors.ErrEmptyRepository)
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return helper.ErrInvalidArgument(err)
}
return nil
diff --git a/internal/gitaly/service/smarthttp/upload_pack.go b/internal/gitaly/service/smarthttp/upload_pack.go
index f65aa9fc9..2fd4956dc 100644
--- a/internal/gitaly/service/smarthttp/upload_pack.go
+++ b/internal/gitaly/service/smarthttp/upload_pack.go
@@ -8,9 +8,9 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/sidechannel"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -109,15 +109,16 @@ func (s *server) runStatsCollector(ctx context.Context, r io.Reader) (io.Reader,
}
func (s *server) validateUploadPackRequest(ctx context.Context, req basicPostUploadPackRequest) (string, []git.ConfigPair, error) {
- if req.GetRepository() == nil {
- return "", nil, gitalyerrors.ErrEmptyRepository
+ repository := req.GetRepository()
+ if err := service.ValidateRepository(repository); err != nil {
+ return "", nil, err
}
- repoPath, err := s.locator.GetRepoPath(req.GetRepository())
+ repoPath, err := s.locator.GetRepoPath(repository)
if err != nil {
return "", nil, err
}
- git.WarnIfTooManyBitmaps(ctx, s.locator, req.GetRepository().GetStorageName(), repoPath)
+ git.WarnIfTooManyBitmaps(ctx, s.locator, repository.GetStorageName(), repoPath)
config, err := git.ConvertConfigOptions(req.GetGitConfigOptions())
if err != nil {
diff --git a/internal/gitaly/service/ssh/receive_pack.go b/internal/gitaly/service/ssh/receive_pack.go
index fef90a408..c8d0657ba 100644
--- a/internal/gitaly/service/ssh/receive_pack.go
+++ b/internal/gitaly/service/ssh/receive_pack.go
@@ -10,8 +10,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting"
@@ -144,9 +144,5 @@ func validateFirstReceivePackRequest(req *gitalypb.SSHReceivePackRequest) error
if req.Stdin != nil {
return errors.New("non-empty data in first request")
}
- if req.Repository == nil {
- return gitalyerrors.ErrEmptyRepository
- }
-
- return nil
+ return service.ValidateRepository(req.GetRepository())
}
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go
index 0beb1616f..79bc49924 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -67,7 +67,7 @@ func TestReceivePack_validation(t *testing.T) {
return helper.ErrInvalidArgumentf("repo scoped: invalid Repository")
}
- return helper.ErrInvalidArgumentf("GetPath: relative path missing")
+ return helper.ErrInvalidArgumentf("empty RelativePath")
}(),
},
{
diff --git a/internal/gitaly/service/ssh/upload_archive.go b/internal/gitaly/service/ssh/upload_archive.go
index 37237c29e..b473a10b9 100644
--- a/internal/gitaly/service/ssh/upload_archive.go
+++ b/internal/gitaly/service/ssh/upload_archive.go
@@ -7,9 +7,9 @@ import (
"sync"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
@@ -100,8 +100,8 @@ func (s *server) sshUploadArchive(stream gitalypb.SSHService_SSHUploadArchiveSer
}
func validateFirstUploadArchiveRequest(req *gitalypb.SSHUploadArchiveRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.Stdin != nil {
return errors.New("non-empty stdin in first request")
diff --git a/internal/gitaly/service/ssh/upload_archive_test.go b/internal/gitaly/service/ssh/upload_archive_test.go
index a66c50a95..fff78644a 100644
--- a/internal/gitaly/service/ssh/upload_archive_test.go
+++ b/internal/gitaly/service/ssh/upload_archive_test.go
@@ -75,7 +75,7 @@ func TestFailedUploadArchiveRequestDueToValidationError(t *testing.T) {
Desc: "Repository.RelativePath is empty",
Req: &gitalypb.SSHUploadArchiveRequest{Repository: &gitalypb.Repository{StorageName: cfg.Storages[0].Name, RelativePath: ""}},
expectedErr: status.Error(codes.InvalidArgument, testhelper.GitalyOrPraefectMessage(
- "GetPath: relative path missing",
+ "empty RelativePath",
"repo scoped: invalid Repository",
)),
},
diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go
index d2fbd1d87..82318968c 100644
--- a/internal/gitaly/service/ssh/upload_pack.go
+++ b/internal/gitaly/service/ssh/upload_pack.go
@@ -11,10 +11,10 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
- gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/stats"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/sidechannel"
"gitlab.com/gitlab-org/gitaly/v15/internal/stream"
@@ -183,8 +183,8 @@ func (s *server) sshUploadPack(rpcContext context.Context, req sshUploadPackRequ
}
func validateFirstUploadPackRequest(req *gitalypb.SSHUploadPackRequest) error {
- if req.GetRepository() == nil {
- return gitalyerrors.ErrEmptyRepository
+ if err := service.ValidateRepository(req.GetRepository()); err != nil {
+ return err
}
if req.Stdin != nil {
return errors.New("non-empty stdin in first request")
diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go
index 59bbe7e2d..aeb0e7695 100644
--- a/internal/gitaly/service/ssh/upload_pack_test.go
+++ b/internal/gitaly/service/ssh/upload_pack_test.go
@@ -445,7 +445,7 @@ func TestUploadPack_validation(t *testing.T) {
if testhelper.IsPraefectEnabled() {
return helper.ErrInvalidArgumentf("repo scoped: invalid Repository")
}
- return helper.ErrInvalidArgumentf("GetPath: relative path missing")
+ return helper.ErrInvalidArgumentf("empty RelativePath")
}(),
},
{