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:
Diffstat (limited to 'internal/gitaly')
-rw-r--r--internal/gitaly/service/hook/post_receive_test.go3
-rw-r--r--internal/gitaly/service/hook/pre_receive.go86
-rw-r--r--internal/gitaly/service/hook/pre_receive_test.go152
-rwxr-xr-xinternal/gitaly/service/hook/testdata/gitlab-shell/hooks/pre-receive9
4 files changed, 0 insertions, 250 deletions
diff --git a/internal/gitaly/service/hook/post_receive_test.go b/internal/gitaly/service/hook/post_receive_test.go
index cf86e9a22..4d9f953d8 100644
--- a/internal/gitaly/service/hook/post_receive_test.go
+++ b/internal/gitaly/service/hook/post_receive_test.go
@@ -351,9 +351,6 @@ To create a merge request for okay, visit:
"GL_USERNAME=username",
"GL_PROTOCOL=protocol",
"GL_REPOSITORY=repository"}
- if useGoPreReceive {
- envVars = append(envVars, "GITALY_GO_PRERECEIVE=true")
- }
require.NoError(t, stream.Send(&gitalypb.PostReceiveHookRequest{
Repository: testRepo,
diff --git a/internal/gitaly/service/hook/pre_receive.go b/internal/gitaly/service/hook/pre_receive.go
index 833d9af32..c9a05e778 100644
--- a/internal/gitaly/service/hook/pre_receive.go
+++ b/internal/gitaly/service/hook/pre_receive.go
@@ -1,11 +1,8 @@
package hook
import (
- "crypto/sha1"
"errors"
"fmt"
- "io"
- "io/ioutil"
"os/exec"
"path/filepath"
"strings"
@@ -14,7 +11,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitlabshell"
"gitlab.com/gitlab-org/gitaly/internal/helper"
- "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
@@ -79,10 +75,6 @@ func (s *server) PreReceiveHook(stream gitalypb.HookService_PreReceiveHookServer
reqEnvVars := firstRequest.GetEnvironmentVariables()
repository := firstRequest.GetRepository()
- if !useGoPreReceiveHook(reqEnvVars) {
- return s.preReceiveHookRuby(firstRequest, stream)
- }
-
stdin := streamio.NewReader(func() ([]byte, error) {
req, err := stream.Recv()
return req.GetStdin(), err
@@ -122,10 +114,6 @@ func validatePreReceiveHookRequest(in *gitalypb.PreReceiveHookRequest) error {
return nil
}
-func useGoPreReceiveHook(env []string) bool {
- return getEnvVar(featureflag.GoPreReceiveHookEnvVar, env) == "true"
-}
-
func preReceiveHookResponse(stream gitalypb.HookService_PreReceiveHookServer, code int32, stderr string) error {
if err := stream.Send(&gitalypb.PreReceiveHookResponse{
ExitStatus: &gitalypb.ExitStatus{Value: code},
@@ -137,80 +125,6 @@ func preReceiveHookResponse(stream gitalypb.HookService_PreReceiveHookServer, co
return nil
}
-func (s *server) preReceiveHookRuby(firstRequest *gitalypb.PreReceiveHookRequest, stream gitalypb.HookService_PreReceiveHookServer) error {
- referenceUpdatesHasher := sha1.New()
-
- stdin := streamio.NewReader(func() ([]byte, error) {
- req, err := stream.Recv()
- if err != nil {
- return nil, err
- }
-
- stdin := req.GetStdin()
- if _, err := referenceUpdatesHasher.Write(stdin); err != nil {
- return stdin, err
- }
-
- return stdin, nil
- })
-
- env, err := preReceiveEnv(firstRequest)
- if err != nil {
- return helper.ErrInternal(err)
- }
-
- primary, err := isPrimary(env)
- if err != nil {
- return helper.ErrInternalf("could not check role: %w", err)
- }
-
- var status int32
-
- // Only the primary should execute hooks.
- if primary {
- stdout := streamio.NewWriter(func(p []byte) error { return stream.Send(&gitalypb.PreReceiveHookResponse{Stdout: p}) })
- stderr := streamio.NewWriter(func(p []byte) error { return stream.Send(&gitalypb.PreReceiveHookResponse{Stderr: p}) })
-
- repoPath, err := helper.GetRepoPath(firstRequest.GetRepository())
- if err != nil {
- return helper.ErrInternal(err)
- }
-
- c := exec.Command(gitlabShellHook("pre-receive"))
- c.Dir = repoPath
-
- status, err = streamCommandResponse(
- stream.Context(),
- stdin,
- stdout, stderr,
- c,
- env,
- )
- if err != nil {
- return helper.ErrInternal(err)
- }
- } else {
- // We need to read all of stdin on secondaries so that we
- // arrive at the same hash as the primary.
- _, err := io.Copy(ioutil.Discard, stdin)
- if err != nil {
- return helper.ErrInternal(err)
- }
- }
-
- if err := s.manager.VoteOnTransaction(stream.Context(), referenceUpdatesHasher.Sum(nil), env); err != nil {
- return helper.ErrInternalf("error voting on transaction: %w", err)
- }
-
- if err := stream.SendMsg(&gitalypb.PreReceiveHookResponse{
- ExitStatus: &gitalypb.ExitStatus{Value: status},
- }); err != nil {
- return helper.ErrInternal(err)
- }
-
- return nil
-}
-
func getEnvVar(key string, vars []string) string {
for _, varPair := range vars {
kv := strings.SplitN(varPair, "=", 2)
diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go
index 8f1c1c416..e29e7bc94 100644
--- a/internal/gitaly/service/hook/pre_receive_test.go
+++ b/internal/gitaly/service/hook/pre_receive_test.go
@@ -18,7 +18,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
- "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -84,148 +83,6 @@ func receivePreReceive(t *testing.T, stream gitalypb.HookService_PreReceiveHookC
return stdout, stderr, status
}
-func TestPreReceive(t *testing.T) {
- rubyDir := config.Config.Ruby.Dir
- defer func(rubyDir string) {
- config.Config.Ruby.Dir = rubyDir
- }(rubyDir)
-
- cwd, err := os.Getwd()
- require.NoError(t, err)
- config.Config.Ruby.Dir = filepath.Join(cwd, "testdata")
-
- serverSocketPath, stop := runHooksServer(t, config.Config.Hooks)
- defer stop()
-
- testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
- defer cleanupFn()
-
- client, conn := newHooksClient(t, serverSocketPath)
- defer conn.Close()
-
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- testCases := []struct {
- desc string
- stdin io.Reader
- req gitalypb.PreReceiveHookRequest
- status int32
- stdout, stderr string
- }{
- {
- desc: "everything OK",
- stdin: bytes.NewBufferString("a\nb\nc\nd\ne\nf\ng"),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=key-123",
- "GL_PROTOCOL=protocol",
- "GL_USERNAME=username",
- "GL_REPOSITORY=repository",
- },
- },
- status: 0,
- stdout: "OK",
- stderr: "",
- },
- {
- desc: "missing stdin",
- stdin: bytes.NewBuffer(nil),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=key-123",
- "GL_PROTOCOL=protocol",
- "GL_USERNAME=username",
- "GL_REPOSITORY=repository",
- },
- },
- status: 1,
- stdout: "",
- stderr: "FAIL",
- },
- {
- desc: "missing gl_protocol",
- stdin: bytes.NewBufferString("a\nb\nc\nd\ne\nf\ng"),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=key-123",
- "GL_USERNAME=username",
- "GL_PROTOCOL=",
- "GL_REPOSITORY=repository",
- },
- },
- status: 1,
- stdout: "",
- stderr: "FAIL",
- },
- {
- desc: "missing gl_id",
- stdin: bytes.NewBufferString("a\nb\nc\nd\ne\nf\ng"),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=",
- "GL_PROTOCOL=protocol",
- "GL_USERNAME=username",
- "GL_REPOSITORY=repository",
- },
- },
- status: 1,
- stdout: "",
- stderr: "FAIL",
- },
- {
- desc: "missing gl_username",
- stdin: bytes.NewBufferString("a\nb\nc\nd\ne\nf\ng"),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=key-123",
- "GL_PROTOCOL=protocol",
- "GL_USERNAME=",
- "GL_REPOSITORY=repository",
- },
- },
- status: 1,
- stdout: "",
- stderr: "FAIL",
- },
- {
- desc: "missing gl_repository",
- stdin: bytes.NewBufferString("a\nb\nc\nd\ne\nf\ng"),
- req: gitalypb.PreReceiveHookRequest{
- Repository: testRepo,
- EnvironmentVariables: []string{
- "GL_ID=key-123",
- "GL_PROTOCOL=protocol",
- "GL_USERNAME=username",
- "GL_REPOSITORY=",
- },
- },
- status: 1,
- stdout: "",
- stderr: "FAIL",
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- stream, err := client.PreReceiveHook(ctx)
- require.NoError(t, err)
- require.NoError(t, stream.Send(&tc.req))
-
- stdout, stderr, status := receivePreReceive(t, stream, tc.stdin)
-
- assert.Equal(t, tc.status, status)
- assert.Equal(t, tc.stderr, text.ChompBytes(stderr), "hook stderr")
- assert.Equal(t, tc.stdout, text.ChompBytes(stdout), "hook stdout")
- })
- }
-}
-
func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
user, password := "user", "password"
secretToken := "secret123"
@@ -299,7 +156,6 @@ func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
"GL_PROTOCOL=" + protocol,
"GL_USERNAME=username",
"GL_REPOSITORY=" + glRepository,
- fmt.Sprintf("%s=true", featureflag.GoPreReceiveHookEnvVar),
},
}
@@ -404,7 +260,6 @@ func TestPreReceive_APIErrors(t *testing.T) {
"GL_PROTOCOL=web",
"GL_USERNAME=username",
"GL_REPOSITORY=repository",
- fmt.Sprintf("%s=true", featureflag.GoPreReceiveHookEnvVar),
},
}))
require.NoError(t, stream.CloseSend())
@@ -465,7 +320,6 @@ exit %d
"GL_PROTOCOL=web",
"GL_USERNAME=username",
"GL_REPOSITORY=repository",
- fmt.Sprintf("%s=true", featureflag.GoPreReceiveHookEnvVar),
},
}))
@@ -501,7 +355,6 @@ func TestPreReceiveHook_Primary(t *testing.T) {
testCases := []struct {
desc string
primary bool
- useRubyHook bool
allowedHandler http.HandlerFunc
preReceiveHandler http.HandlerFunc
stdin []byte
@@ -580,7 +433,6 @@ func TestPreReceiveHook_Primary(t *testing.T) {
{
desc: "primary Ruby hook triggers transaction",
primary: true,
- useRubyHook: true,
stdin: []byte("foobar"),
allowedHandler: allowedHandler(true),
preReceiveHandler: preReceiveHandler(true),
@@ -591,7 +443,6 @@ func TestPreReceiveHook_Primary(t *testing.T) {
{
desc: "secondary Ruby hook triggers transaction",
primary: false,
- useRubyHook: true,
stdin: []byte("foobar"),
allowedHandler: allowedHandler(true),
preReceiveHandler: preReceiveHandler(true),
@@ -680,9 +531,6 @@ func TestPreReceiveHook_Primary(t *testing.T) {
transactionEnv,
transactionServerEnv,
}
- if !tc.useRubyHook {
- environment = append(environment, fmt.Sprintf("%s=true", featureflag.GoPreReceiveHookEnvVar))
- }
stream, err := client.PreReceiveHook(ctx)
require.NoError(t, err)
diff --git a/internal/gitaly/service/hook/testdata/gitlab-shell/hooks/pre-receive b/internal/gitaly/service/hook/testdata/gitlab-shell/hooks/pre-receive
deleted file mode 100755
index 12574b7b7..000000000
--- a/internal/gitaly/service/hook/testdata/gitlab-shell/hooks/pre-receive
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env ruby
-
-# Tests inputs to pre-receive
-
-abort("FAIL") if $stdin.read.empty?
-abort("FAIL") if %w[GL_ID GL_REPOSITORY GL_PROTOCOL GL_USERNAME].any? { |k| ENV[k].nil? || ENV[k].empty? }
-
-puts "OK"
-