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-28 16:44:16 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2022-11-08 12:33:03 +0300
commit0e5faf42aa06ec3c5a3474d483dba75b921cf79f (patch)
tree035c972e4e05514adf00b74645e759395b3603a7
parent26b6a88891295615bdcf61b09aa862937c3b9c00 (diff)
gitaly/service: Shared request validation functionality
A lot of RPCs take a Repository as an input parameter. It is a required parameter in most cases if not at all. Those we need to validate it is provided, and it has all required fields set as well. For that purpose the 'ValidateRepository' function is declared. It accepts repository entity and checks the repository is not nil, and it has StorageName and RelativePath fields set and non-blank. If something is missing the corresponding error will be returned. Part of https://gitlab.com/gitlab-org/gitaly/-/issues/3717
-rw-r--r--internal/gitaly/service/validations.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/gitaly/service/validations.go b/internal/gitaly/service/validations.go
new file mode 100644
index 000000000..80c8e1cea
--- /dev/null
+++ b/internal/gitaly/service/validations.go
@@ -0,0 +1,23 @@
+package service
+
+import (
+ "strings"
+
+ gitalyerrors "gitlab.com/gitlab-org/gitaly/v15/internal/errors"
+ "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
+)
+
+// ValidateRepository checks where the Repository is provided and
+// all the required fields are set.
+func ValidateRepository(repository *gitalypb.Repository) error {
+ if repository == nil {
+ return gitalyerrors.ErrEmptyRepository
+ }
+ if strings.TrimSpace(repository.GetStorageName()) == "" {
+ return gitalyerrors.ErrEmptyStorageName
+ }
+ if strings.TrimSpace(repository.GetRelativePath()) == "" {
+ return gitalyerrors.ErrEmptyRelativePath
+ }
+ return nil
+}