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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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 (
...
@@ -17,7 +17,7 @@ import (
"time"
"time"
)
)
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
var
format
string
var
format
string
urlPath
:=
r
.
URL
.
Path
urlPath
:=
r
.
URL
.
Path
switch
filepath
.
Base
(
urlPath
)
{
switch
filepath
.
Base
(
urlPath
)
{
...
@@ -34,16 +34,16 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
...
@@ -34,16 +34,16 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
return
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
()
defer
cachedArchive
.
Close
()
log
.
Printf
(
"Serving cached file %q"
,
r
.
ArchivePath
)
log
.
Printf
(
"Serving cached file %q"
,
a
.
ArchivePath
)
setArchiveHeaders
(
w
,
format
,
archiveFilename
)
setArchiveHeaders
(
w
,
format
,
archiveFilename
)
// Even if somebody deleted the cachedArchive from disk since we opened
// Even if somebody deleted the cachedArchive from disk since we opened
// the file, Unix file semantics guarantee we can still read from the
// the file, Unix file semantics guarantee we can still read from the
// open file in this process.
// 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
return
}
}
...
@@ -51,7 +51,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
...
@@ -51,7 +51,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
// safe. We create the tempfile in the same directory as the final cached
// 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
// archive we want to create so that we can use an atomic link(2) operation
// to finalize the cached archive.
// to finalize the cached archive.
tempFile
,
err
:=
prepareArchiveTempfile
(
path
.
Dir
(
r
.
ArchivePath
),
archiveFilename
)
tempFile
,
err
:=
prepareArchiveTempfile
(
path
.
Dir
(
a
.
ArchivePath
),
archiveFilename
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: create tempfile: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: create tempfile: %v"
,
err
))
return
return
...
@@ -61,7 +61,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
...
@@ -61,7 +61,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
compressCmd
,
archiveFormat
:=
parseArchiveFormat
(
format
)
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
()
archiveStdout
,
err
:=
archiveCmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: archive stdout: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handleGetArchive: archive stdout: %v"
,
err
))
...
@@ -117,7 +117,7 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
...
@@ -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
))
logError
(
fmt
.
Errorf
(
"handleGetArchive: finalize cached archive: %v"
,
err
))
return
return
}
}
...
...
artifacts.go
View file @
7415226f
...
@@ -5,9 +5,8 @@ import (
...
@@ -5,9 +5,8 @@ import (
)
)
func
(
u
*
upstream
)
artifactsAuthorizeHandler
(
h
httpHandleFunc
)
httpHandleFunc
{
func
(
u
*
upstream
)
artifactsAuthorizeHandler
(
h
httpHandleFunc
)
httpHandleFunc
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
return
u
.
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
req
:=
r
.
Request
r
.
Header
.
Set
(
tempPathHeader
,
a
.
TempPath
)
req
.
Header
.
Set
(
tempPathHeader
,
r
.
TempPath
)
h
(
w
,
r
)
h
(
w
,
req
)
},
"/authorize"
)
},
"/authorize"
)
}
}
authorization.go
View file @
7415226f
...
@@ -85,11 +85,11 @@ func (u *upstream) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpH
...
@@ -85,11 +85,11 @@ func (u *upstream) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpH
return
return
}
}
g
:=
&
gitRequest
{
Request
:
r
}
a
:=
&
authorizationResponse
{
}
// The auth backend validated the client request and told us additional
// The auth backend validated the client request and told us additional
// request metadata. We must extract this information from the auth
// request metadata. We must extract this information from the auth
// response body.
// 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
))
fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: decode authorization response: %v"
,
err
))
return
return
}
}
...
@@ -105,6 +105,6 @@ func (u *upstream) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpH
...
@@ -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 (
...
@@ -8,7 +8,7 @@ import (
"testing"
"testing"
)
)
func
okHandler
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
okHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
,
_
*
authorizationResponse
)
{
w
.
WriteHeader
(
201
)
w
.
WriteHeader
(
201
)
fmt
.
Fprint
(
w
,
"{
\"
status
\"
:
\"
ok
\"
}"
)
fmt
.
Fprint
(
w
,
"{
\"
status
\"
:
\"
ok
\"
}"
)
}
}
...
...
git-http.go
View file @
7415226f
...
@@ -27,22 +27,22 @@ func looksLikeRepo(p string) bool {
...
@@ -27,22 +27,22 @@ func looksLikeRepo(p string) bool {
}
}
func
(
u
*
upstream
)
repoPreAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
func
(
u
*
upstream
)
repoPreAuthorizeHandler
(
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
.
RepoPath
==
""
{
if
a
.
RepoPath
==
""
{
fail500
(
w
,
errors
.
New
(
"repoPreAuthorizeHandler: RepoPath empty"
))
fail500
(
w
,
errors
.
New
(
"repoPreAuthorizeHandler: RepoPath empty"
))
return
return
}
}
if
!
looksLikeRepo
(
r
.
RepoPath
)
{
if
!
looksLikeRepo
(
a
.
RepoPath
)
{
http
.
Error
(
w
,
"Not Found"
,
404
)
http
.
Error
(
w
,
"Not Found"
,
404
)
return
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"
)
rpc
:=
r
.
URL
.
Query
()
.
Get
(
"service"
)
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
// The 'dumb' Git HTTP protocol is not supported
...
@@ -51,7 +51,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
...
@@ -51,7 +51,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
}
}
// Prepare our Git subprocess
// 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
()
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleGetInfoRefs: stdout: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handleGetInfoRefs: stdout: %v"
,
err
))
...
@@ -86,7 +86,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
...
@@ -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
var
err
error
// Get Git action from URL
// Get Git action from URL
...
@@ -98,7 +98,7 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
...
@@ -98,7 +98,7 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
}
}
// Prepare our Git subprocess
// 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
()
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handlePostRPC: stdout: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handlePostRPC: stdout: %v"
,
err
))
...
...
lfs.go
View file @
7415226f
...
@@ -18,29 +18,29 @@ import (
...
@@ -18,29 +18,29 @@ import (
)
)
func
(
u
*
upstream
)
lfsAuthorizeHandler
(
handleFunc
serviceHandleFunc
)
httpHandleFunc
{
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"
))
fail500
(
w
,
errors
.
New
(
"lfsAuthorizeHandler: StoreLFSPath empty"
))
return
return
}
}
if
r
.
LfsOid
==
""
{
if
a
.
LfsOid
==
""
{
fail500
(
w
,
errors
.
New
(
"lfsAuthorizeHandler: LfsOid empty"
))
fail500
(
w
,
errors
.
New
(
"lfsAuthorizeHandler: LfsOid empty"
))
return
return
}
}
if
err
:=
os
.
MkdirAll
(
r
.
StoreLFSPath
,
0700
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
a
.
StoreLFSPath
,
0700
);
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"lfsAuthorizeHandler: mkdi
r
StoreLFSPath: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"lfsAuthorizeHandler: mkdi
a
StoreLFSPath: %v"
,
err
))
return
return
}
}
handleFunc
(
w
,
r
)
handleFunc
(
w
,
r
,
a
)
},
"/authorize"
)
},
"/authorize"
)
}
}
func
(
u
*
upstream
)
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
(
u
*
upstream
)
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
authorizationResponse
)
{
file
,
err
:=
ioutil
.
TempFile
(
r
.
StoreLFSPath
,
r
.
LfsOid
)
file
,
err
:=
ioutil
.
TempFile
(
a
.
StoreLFSPath
,
a
.
LfsOid
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: create tempfile: %v"
,
err
))
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: create tempfile: %v"
,
err
))
return
return
...
@@ -58,14 +58,14 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
...
@@ -58,14 +58,14 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
}
}
file
.
Close
()
file
.
Close
()
if
written
!=
r
.
LfsSize
{
if
written
!=
a
.
LfsSize
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected size %d, wrote %d"
,
r
.
LfsSize
,
written
))
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected size %d, wrote %d"
,
a
.
LfsSize
,
written
))
return
return
}
}
shaStr
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
shaStr
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
if
shaStr
!=
r
.
LfsOid
{
if
shaStr
!=
a
.
LfsOid
{
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected sha256 %s, got %s"
,
r
.
LfsOid
,
shaStr
))
fail500
(
w
,
fmt
.
Errorf
(
"handleStoreLfsObject: expected sha256 %s, got %s"
,
a
.
LfsOid
,
shaStr
))
return
return
}
}
...
@@ -75,5 +75,5 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
...
@@ -75,5 +75,5 @@ func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *gitRequest) {
r
.
ContentLength
=
0
r
.
ContentLength
=
0
// And proxy the request
// And proxy the request
u
.
proxyRequest
(
w
,
r
.
Request
)
u
.
proxyRequest
(
w
,
r
)
}
}
upstream.go
View file @
7415226f
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
"strings"
"strings"
)
)
type
serviceHandleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
type
serviceHandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
authorizationResponse
)
type
upstream
struct
{
type
upstream
struct
{
httpClient
*
http
.
Client
httpClient
*
http
.
Client
...
@@ -52,13 +52,6 @@ type authorizationResponse struct {
...
@@ -52,13 +52,6 @@ type authorizationResponse struct {
TempPath
string
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
{
func
newUpstream
(
authBackend
string
,
authTransport
http
.
RoundTripper
)
*
upstream
{
gitlabURL
,
err
:=
url
.
Parse
(
authBackend
)
gitlabURL
,
err
:=
url
.
Parse
(
authBackend
)
if
err
!=
nil
{
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