Commit 80d253e0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Allow passing pb.Repository from Rails to Gitaly

We are in the middle of making the Gitaly 'Repository' message contain
more fields than it used to. This change makes sure that workhorse
automatically passes through the new message format (as long as the
gitaly client versions in gitlab-rails and workhorse match).
parent 9b906b5f
......@@ -12,6 +12,7 @@ import (
"strings"
"github.com/prometheus/client_golang/prometheus"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
......@@ -90,6 +91,9 @@ type Response struct {
Terminal *TerminalSettings
// Path to Gitaly Socket
GitalySocketPath string
// Repository object for making gRPC requests to Gitaly. This will
// eventually replace the RepoPath field.
Repository pb.Repository
}
// singleJoiningSlash is taken from reverseproxy.go:NewSingleHostReverseProxy
......@@ -209,6 +213,14 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http
return httpResponse, nil, fmt.Errorf("preAuthorizeHandler: decode authorization response: %v", err)
}
// This is for backwards compatiblity, can be depracated when Rails
// always sends a 'Repository' message. For the time being we cannot
// count on this, so we put some minimal data in the Repository struct.
if authResponse.Repository.Path == "" {
authResponse.Repository.Path = authResponse.RepoPath
}
return httpResponse, authResponse, nil
}
......
......@@ -67,7 +67,7 @@ func handleGetInfoRefsWithGitaly(w http.ResponseWriter, a *api.Response, rpc str
return fmt.Errorf("GetInfoRefsHandler: %v", err)
}
infoRefsResponseWriter, err := smarthttp.InfoRefsResponseWriterTo(a.RepoPath, rpc)
infoRefsResponseWriter, err := smarthttp.InfoRefsResponseWriterTo(a.Repository, rpc)
if err != nil {
return fmt.Errorf("GetInfoRefsHandler: %v", err)
}
......
......@@ -13,9 +13,8 @@ type SmartHTTPClient struct {
pb.SmartHTTPClient
}
func (client *SmartHTTPClient) InfoRefsResponseWriterTo(repoPath, rpc string) (io.WriterTo, error) {
repo := &pb.Repository{Path: repoPath}
rpcRequest := &pb.InfoRefsRequest{Repository: repo}
func (client *SmartHTTPClient) InfoRefsResponseWriterTo(repo pb.Repository, rpc string) (io.WriterTo, error) {
rpcRequest := &pb.InfoRefsRequest{Repository: &repo}
var c pbhelper.InfoRefsClient
var err error
......
......@@ -594,14 +594,25 @@ func TestApiContentTypeBlock(t *testing.T) {
}
func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
apiResponse := gitOkBody(t)
gitalyServer := startGitalyServer(t)
defer func() {
gitalyServer.Stop()
gitaly.CloseConnections()
}()
apiResponse := gitOkBody(t)
repoPath := apiResponse.RepoPath
for _, testCase := range []struct {
repoPath string
repository pb.Repository
}{
{repoPath: repoPath},
{repoPath: repoPath, repository: pb.Repository{Path: repoPath, StorageName: "foobar", RelativePath: "baz.git"}},
} {
func() {
apiResponse.RepoPath = testCase.repoPath
apiResponse.Repository = testCase.repository
apiResponse.GitalySocketPath = gitalySocketPath
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......@@ -624,6 +635,8 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
if !bytes.Equal(responseBody, []byte(expectedContent)) {
t.Errorf("GET %q: Expected %q, got %q", resource, expectedContent, responseBody)
}
}()
}
}
func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment