Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
0
Merge Requests
0
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
iv
gitlab-workhorse
Commits
7415226f
Commit
7415226f
authored
Dec 17, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of gitRequest
parent
b9409540
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
45 deletions
+37
-45
archive.go
archive.go
+8
-8
artifacts.go
artifacts.go
+3
-4
authorization.go
authorization.go
+3
-3
authorization_test.go
authorization_test.go
+1
-1
git-http.go
git-http.go
+8
-8
lfs.go
lfs.go
+13
-13
upstream.go
upstream.go
+1
-8
No files found.
archive.go
View file @
7415226f
...
...
@@ -17,7 +17,7 @@ import (
"time"
)
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
var
format
string
urlPath
:=
r
.
URL
.
Path
switch
filepath
.
Base
(
urlPath
)
{
...
...
@@ -34,16 +34,16 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
return
}
archiveFilename
:=
path
.
Base
(
r
.
ArchivePath
)
archiveFilename
:=
path
.
Base
(
a
.
ArchivePath
)
if
cachedArchive
,
err
:=
os
.
Open
(
r
.
ArchivePath
);
err
==
nil
{
if
cachedArchive
,
err
:=
os
.
Open
(
a
.
ArchivePath
);
err
==
nil
{
defer
cachedArchive
.
Close
()
log
.
Printf
(
"Serving cached file %q"
,
r
.
ArchivePath
)
log
.
Printf
(
"Serving cached file %q"
,
a
.
ArchivePath
)
setArchiveHeaders
(
w
,
format
,
archiveFilename
)
// Even if somebody deleted the cachedArchive from disk since we opened
// the file, Unix file semantics guarantee we can still read from the
// open file in this process.
http
.
ServeContent
(
w
,
r
.
Request
,
""
,
time
.
Unix
(
0
,
0
),
cachedArchive
)
http
.
ServeContent
(
w
,
r
,
""
,
time
.
Unix
(
0
,
0
),
cachedArchive
)
return
}
...
...
@@ -51,7 +51,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
// safe. We create the tempfile in the same directory as the final cached
// archive we want to create so that we can use an atomic link(2) operation
// to finalize the cached archive.
tempFile
,
err
:=
prepareArchiveTempfile
(
path
.
Dir
(
r
.
ArchivePath
),
archiveFilename
)
tempFile
,
err
:=
prepareArchiveTempfile
(
path
.
Dir
(
a
.
ArchivePath
),
archiveFilename
)
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: create tempfile: %v"
,
err
))
return
...
...
@@ -61,7 +61,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
compressCmd
,
archiveFormat
:=
parseArchiveFormat
(
format
)
archiveCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
r
.
RepoPath
,
"archive"
,
"--format="
+
archiveFormat
,
"--prefix="
+
r
.
ArchivePrefix
+
"/"
,
r
.
CommitId
)
archiveCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
a
.
RepoPath
,
"archive"
,
"--format="
+
archiveFormat
,
"--prefix="
+
a
.
ArchivePrefix
+
"/"
,
a
.
CommitId
)
archiveStdout
,
err
:=
archiveCmd
.
StdoutPipe
()
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: archive stdout: %v"
,
err
))
...
...
@@ -117,7 +117,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
}
}
if
err
:=
finalizeCachedArchive
(
tempFile
,
r
.
ArchivePath
);
err
!=
nil
{
if
err
:=
finalizeCachedArchive
(
tempFile
,
a
.
ArchivePath
);
err
!=
nil
{
logError
(
fmt
.
Errorf
(
"handleGetArchive: finalize cached archive: %v"
,
err
))
return
}
...
...
artifacts.go
View file @
7415226f
...
...
@@ -5,9 +5,8 @@ import (
)
func
(
u
*
upstream
)
artifactsAuthorizeHandler
(
h
httpHandleFunc
)
httpHandleFunc
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
req
:=
r
.
Request
req
.
Header
.
Set
(
tempPathHeader
,
r
.
TempPath
)
h
(
w
,
req
)
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
h
(
w
,
r
)
},
"/authorize"
)
}
authorization.go
View file @
7415226f
...
...
@@ -85,11 +85,11 @@ func (u *upstream) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpH
return
}
g
:=
&
gitRequest
{
Request
:
r
}
a
:=
&
authorizationResponse
{
}
// The auth backend validated the client request and told us additional
// request metadata. We must extract this information from the auth
// response body.
if
err
:=
json
.
NewDecoder
(
authResponse
.
Body
)
.
Decode
(
&
g
.
authorizationResponse
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
authResponse
.
Body
)
.
Decode
(
a
);
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: decode authorization response: %v"
,
err
))
return
}
...
...
@@ -105,6 +105,6 @@ func (u *upstream) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpH
}
}
h
(
w
,
g
)
h
(
w
,
r
,
a
)
}
}
authorization_test.go
View file @
7415226f
...
...
@@ -8,7 +8,7 @@ import (
"testing"
)
func
okHandler
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
okHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
,
_
*
authorizationResponse
)
{
w
.
WriteHeader
(
201
)
fmt
.
Fprint
(
w
,
"{
\"
status
\"
:
\"
ok
\"
}"
)
}
...
...
git-http.go
View file @
7415226f
...
...
@@ -27,22 +27,22 @@ func looksLikeRepo(p string) bool {
}
func
(
u
*
upstream
)
repoPreAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
if
r
.
RepoPath
==
""
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
if
a
.
RepoPath
==
""
{
fail500
(
w
,
errors
.
New
(
"repoPreAuthorizeHandler: RepoPath empty"
))
return
}
if
!
looksLikeRepo
(
r
.
RepoPath
)
{
if
!
looksLikeRepo
(
a
.
RepoPath
)
{
http
.
Error
(
w
,
"Not Found"
,
404
)
return
}
handleFunc
(
w
,
r
)
handleFunc
(
w
,
r
,
a
)
},
""
)
}
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
rpc
:=
r
.
URL
.
Query
()
.
Get
(
"service"
)
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
...
...
@@ -51,7 +51,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
}
// Prepare our Git subprocess
cmd
:=
gitCommand
(
r
.
GL_ID
,
"git"
,
subCommand
(
rpc
),
"--stateless-rpc"
,
"--advertise-refs"
,
r
.
RepoPath
)
cmd
:=
gitCommand
(
a
.
GL_ID
,
"git"
,
subCommand
(
rpc
),
"--stateless-rpc"
,
"--advertise-refs"
,
a
.
RepoPath
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetInfoRefs: stdout: %v"
,
err
))
...
...
@@ -86,7 +86,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
}
}
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
var
err
error
// Get Git action from URL
...
...
@@ -98,7 +98,7 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
}
// Prepare our Git subprocess
cmd
:=
gitCommand
(
r
.
GL_ID
,
"git"
,
subCommand
(
action
),
"--stateless-rpc"
,
r
.
RepoPath
)
cmd
:=
gitCommand
(
a
.
GL_ID
,
"git"
,
subCommand
(
action
),
"--stateless-rpc"
,
a
.
RepoPath
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handlePostRPC: stdout: %v"
,
err
))
...
...
lfs.go
View file @
7415226f
...
...
@@ -18,29 +18,29 @@ import (
)
func
(
u
*
upstream
)
lfsAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
if
r
.
StoreLFSPath
==
""
{
if
a
.
StoreLFSPath
==
""
{
fail500
(
w
,
errors
.
New
(
"lfsAuthorizeHandler: StoreLFSPath empty"
))
return
}
if
r
.
LfsOid
==
""
{
if
a
.
LfsOid
==
""
{
fail500
(
w
,
errors
.
New
(
"lfsAuthorizeHandler: LfsOid empty"
))
return
}
if
err
:=
os
.
MkdirAll
(
r
.
StoreLFSPath
,
0700
);
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"lfsAuthorizeHandler: mkdi
r
StoreLFSPath: %v"
,
err
))
if
err
:=
os
.
MkdirAll
(
a
.
StoreLFSPath
,
0700
);
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"lfsAuthorizeHandler: mkdi
a
StoreLFSPath: %v"
,
err
))
return
}
handleFunc
(
w
,
r
)
handleFunc
(
w
,
r
,
a
)
},
"/authorize"
)
}
func
(
u
*
upstream
)
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
file
,
err
:=
ioutil
.
TempFile
(
r
.
StoreLFSPath
,
r
.
LfsOid
)
func
(
u
*
upstream
)
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
file
,
err
:=
ioutil
.
TempFile
(
a
.
StoreLFSPath
,
a
.
LfsOid
)
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: create tempfile: %v"
,
err
))
return
...
...
@@ -58,14 +58,14 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
}
file
.
Close
()
if
written
!=
r
.
LfsSize
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected size %d, wrote %d"
,
r
.
LfsSize
,
written
))
if
written
!=
a
.
LfsSize
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected size %d, wrote %d"
,
a
.
LfsSize
,
written
))
return
}
shaStr
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
if
shaStr
!=
r
.
LfsOid
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected sha256 %s, got %s"
,
r
.
LfsOid
,
shaStr
))
if
shaStr
!=
a
.
LfsOid
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected sha256 %s, got %s"
,
a
.
LfsOid
,
shaStr
))
return
}
...
...
@@ -75,5 +75,5 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
r
.
ContentLength
=
0
// And proxy the request
u
.
proxyRequest
(
w
,
r
.
Request
)
u
.
proxyRequest
(
w
,
r
)
}
upstream.go
View file @
7415226f
...
...
@@ -15,7 +15,7 @@ import (
"strings"
)
type
serviceHandleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
type
serviceHandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
authorizationResponse
)
type
upstream
struct
{
httpClient
*
http
.
Client
...
...
@@ -52,13 +52,6 @@ type authorizationResponse struct {
TempPath
string
}
// A gitRequest is an *http.Request decorated with attributes returned by the
// GitLab Rails application.
type
gitRequest
struct
{
*
http
.
Request
authorizationResponse
}
func
newUpstream
(
authBackend
string
,
authTransport
http
.
RoundTripper
)
*
upstream
{
gitlabURL
,
err
:=
url
.
Parse
(
authBackend
)
if
err
!=
nil
{
...
...
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