Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6a10539e
Commit
6a10539e
authored
Jun 19, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate gitaly server address in struct
parent
49803070
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
25 deletions
+49
-25
gitaly_test.go
gitaly_test.go
+27
-16
internal/api/api.go
internal/api/api.go
+9
-1
internal/git/info-refs.go
internal/git/info-refs.go
+2
-2
internal/git/receive-pack.go
internal/git/receive-pack.go
+2
-2
internal/git/upload-pack.go
internal/git/upload-pack.go
+2
-2
internal/gitaly/gitaly.go
internal/gitaly/gitaly.go
+7
-2
No files found.
gitaly_test.go
View file @
6a10539e
...
...
@@ -14,6 +14,7 @@ import (
"time"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
...
...
@@ -32,7 +33,7 @@ func TestFailedCloneNoGitaly(t *testing.T) {
GL_ID
:
"user-123"
,
RepoPath
:
repoPath
(
t
),
// This will create a failure to connect to Gitaly
Gitaly
Address
:
"unix:/nonexistent"
,
Gitaly
Server
:
gitaly
.
Server
{
Address
:
"unix:/nonexistent"
}
,
}
// Prepare test server and backend
...
...
@@ -49,24 +50,31 @@ func TestFailedCloneNoGitaly(t *testing.T) {
}
func
TestGetInfoRefsProxiedToGitalySuccessfully
(
t
*
testing
.
T
)
{
apiResponse
:=
gitOkBody
(
t
)
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
gitalyAddress
:=
"unix://"
+
socketPath
apiResponse
.
GitalyAddress
=
gitalyAddress
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
apiResponseOld
:=
gitOkBody
(
t
)
apiResponseOld
.
GitalyServer
=
gitaly
.
Server
{}
apiResponseOld
.
GitalyAddress
=
gitalyAddress
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyServer
.
Address
=
gitalyAddress
resource
:=
"/gitlab-org/gitlab-test.git/info/refs?service=git-upload-pack"
_
,
body
:=
httpGet
(
t
,
ws
.
URL
+
resource
)
for
_
,
a
:=
range
[]
*
api
.
Response
{
apiResponseOld
,
apiResponse
}
{
ts
:=
testAuthServer
(
nil
,
200
,
a
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
expectedContent
:=
string
(
testhelper
.
GitalyInfoRefsResponseMock
)
assert
.
Equal
(
t
,
expectedContent
,
body
,
"GET %q: response body"
,
resource
)
resource
:=
"/gitlab-org/gitlab-test.git/info/refs?service=git-upload-pack"
_
,
body
:=
httpGet
(
t
,
ws
.
URL
+
resource
)
expectedContent
:=
string
(
testhelper
.
GitalyInfoRefsResponseMock
)
assert
.
Equal
(
t
,
expectedContent
,
body
,
"GET %q: response body"
,
resource
)
}
}
func
TestGetInfoRefsProxiedToGitalyInterruptedStream
(
t
*
testing
.
T
)
{
...
...
@@ -75,7 +83,7 @@ func TestGetInfoRefsProxiedToGitalyInterruptedStream(t *testing.T) {
defer
gitalyServer
.
Stop
()
gitalyAddress
:=
"unix://"
+
socketPath
apiResponse
.
GitalyAddress
=
gitalyAddress
apiResponse
.
Gitaly
Server
.
Address
=
gitalyAddress
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -110,7 +118,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
.
GitalyAddress
=
"unix://"
+
socketPath
apiResponse
.
Gitaly
Server
.
Address
=
"unix://"
+
socketPath
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -143,7 +151,7 @@ func TestPostReceivePackProxiedToGitalyInterrupted(t *testing.T) {
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
.
GitalyAddress
=
"unix://"
+
socketPath
apiResponse
.
Gitaly
Server
.
Address
=
"unix://"
+
socketPath
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -184,7 +192,7 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) {
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
code
)
defer
gitalyServer
.
Stop
()
apiResponse
.
GitalyAddress
=
"unix://"
+
socketPath
apiResponse
.
Gitaly
Server
.
Address
=
"unix://"
+
socketPath
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -218,7 +226,7 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
.
GitalyAddress
=
"unix://"
+
socketPath
apiResponse
.
Gitaly
Server
.
Address
=
"unix://"
+
socketPath
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -257,6 +265,7 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyAddress
=
""
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -277,6 +286,7 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyAddress
=
""
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
@@ -298,6 +308,7 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyAddress
=
""
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
...
...
internal/api/api.go
View file @
6a10539e
...
...
@@ -15,6 +15,7 @@ import (
pb
"gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/secret"
)
...
...
@@ -104,8 +105,10 @@ type Response struct {
Entry
string
`json:"entry"`
// Used to communicate terminal session details
Terminal
*
TerminalSettings
// GitalyAddress is a unix:// or tcp:// address to reach a Gitaly service on
//
DEPRECATED.
GitalyAddress is a unix:// or tcp:// address to reach a Gitaly service on
GitalyAddress
string
// GitalyServer specifies an address and authentication token for a gitaly server we should connect to.
GitalyServer
gitaly
.
Server
`json:"gitaly_server"`
// Repository object for making gRPC requests to Gitaly. This will
// eventually replace the RepoPath field.
Repository
pb
.
Repository
...
...
@@ -228,6 +231,11 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http
return
httpResponse
,
nil
,
fmt
.
Errorf
(
"preAuthorizeHandler: decode authorization response: %v"
,
err
)
}
if
authResponse
.
GitalyServer
.
Address
==
""
{
authResponse
.
GitalyServer
.
Address
=
authResponse
.
GitalyAddress
}
authResponse
.
GitalyAddress
=
""
return
httpResponse
,
authResponse
,
nil
}
...
...
internal/git/info-refs.go
View file @
6a10539e
...
...
@@ -31,7 +31,7 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache"
)
var
err
error
if
a
.
GitalyAddress
==
""
{
if
a
.
Gitaly
Server
.
Address
==
""
{
err
=
handleGetInfoRefsLocally
(
w
,
a
,
rpc
)
}
else
{
err
=
handleGetInfoRefsWithGitaly
(
w
,
a
,
rpc
)
...
...
@@ -64,7 +64,7 @@ func handleGetInfoRefsLocally(w http.ResponseWriter, a *api.Response, rpc string
}
func
handleGetInfoRefsWithGitaly
(
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Address
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Server
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"GetInfoRefsHandler: %v"
,
err
)
}
...
...
internal/git/receive-pack.go
View file @
6a10539e
...
...
@@ -20,7 +20,7 @@ func handleReceivePack(w *GitHttpResponseWriter, r *http.Request, a *api.Respons
defer
cw
.
Flush
()
var
err
error
if
a
.
GitalyAddress
==
""
{
if
a
.
Gitaly
Server
.
Address
==
""
{
err
=
handleReceivePackLocally
(
a
,
r
,
cr
,
cw
,
action
)
}
else
{
err
=
handleReceivePackWithGitaly
(
a
,
cr
,
cw
)
...
...
@@ -46,7 +46,7 @@ func handleReceivePackLocally(a *api.Response, r *http.Request, stdin io.Reader,
}
func
handleReceivePackWithGitaly
(
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Address
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Server
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.ReceivePack: %v"
,
err
)
}
...
...
internal/git/upload-pack.go
View file @
6a10539e
...
...
@@ -27,7 +27,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
action
:=
getService
(
r
)
writePostRPCHeader
(
w
,
action
)
if
a
.
GitalyAddress
==
""
{
if
a
.
Gitaly
Server
.
Address
==
""
{
err
=
handleUploadPackLocally
(
a
,
r
,
buffer
,
w
,
action
)
}
else
{
err
=
handleUploadPackWithGitaly
(
a
,
buffer
,
w
)
...
...
@@ -58,7 +58,7 @@ func handleUploadPackLocally(a *api.Response, r *http.Request, stdin *os.File, s
}
func
handleUploadPackWithGitaly
(
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Address
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
Gitaly
Server
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"smarthttp.UploadPack: %v"
,
err
)
}
...
...
internal/gitaly/gitaly.go
View file @
6a10539e
...
...
@@ -12,6 +12,11 @@ import (
"google.golang.org/grpc"
)
type
Server
struct
{
Address
string
`json:"address"`
Token
string
`json:"token"`
}
type
connectionsCache
struct
{
sync
.
RWMutex
connections
map
[
string
]
*
grpc
.
ClientConn
...
...
@@ -21,8 +26,8 @@ var cache = connectionsCache{
connections
:
make
(
map
[
string
]
*
grpc
.
ClientConn
),
}
func
NewSmartHTTPClient
(
address
string
)
(
*
SmartHTTPClient
,
error
)
{
conn
,
err
:=
getOrCreateConnection
(
a
ddress
)
func
NewSmartHTTPClient
(
server
Server
)
(
*
SmartHTTPClient
,
error
)
{
conn
,
err
:=
getOrCreateConnection
(
server
.
A
ddress
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment