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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
d55aa579
Commit
d55aa579
authored
Dec 20, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Push some initialization out of internal/upstream
parent
8e9a6da2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
49 deletions
+48
-49
authorization_test.go
authorization_test.go
+2
-3
internal/api/api.go
internal/api/api.go
+18
-4
internal/upstream/routes.go
internal/upstream/routes.go
+28
-17
internal/upstream/upstream.go
internal/upstream/upstream.go
+0
-25
No files found.
authorization_test.go
View file @
d55aa579
...
...
@@ -3,7 +3,6 @@ package main
import
(
"./internal/api"
"./internal/helper"
"./internal/upstream"
"fmt"
"net/http"
"net/http/httptest"
...
...
@@ -26,10 +25,10 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
a
pi
:=
(
&
upstream
.
Upstream
{
Backend
:
helper
.
URLMustParse
(
ts
.
URL
),
Version
:
"123"
})
.
API
()
a
:=
&
api
.
API
{
URL
:
helper
.
URLMustParse
(
ts
.
URL
),
Version
:
"123"
}
response
:=
httptest
.
NewRecorder
()
a
pi
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
a
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
response
,
expectedCode
)
return
response
}
...
...
internal/api/api.go
View file @
d55aa579
package
api
import
(
"../badgateway"
"../helper"
"../proxy"
"encoding/json"
...
...
@@ -10,12 +11,25 @@ import (
"net/http"
"net/url"
"strings"
"sync"
)
type
API
struct
{
*
http
.
Client
_client
*
http
.
Client
configureClientOnce
sync
.
Once
URL
*
url
.
URL
Version
string
RoundTripper
*
badgateway
.
RoundTripper
}
func
(
a
*
API
)
client
()
*
http
.
Client
{
a
.
configureClientOnce
.
Do
(
func
()
{
a
.
_client
=
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}}
if
a
.
RoundTripper
!=
nil
{
a
.
_client
.
Transport
=
a
.
RoundTripper
}
})
return
a
.
_client
}
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
...
@@ -99,7 +113,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.HandlerFun
return
}
authResponse
,
err
:=
api
.
Do
(
authReq
)
authResponse
,
err
:=
api
.
client
()
.
Do
(
authReq
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
return
...
...
internal/upstream/routes.go
View file @
d55aa579
package
upstream
import
(
apipkg
"../api"
"../git"
"../lfs"
pr
"../proxy"
pr
oxypkg
"../proxy"
"../staticpages"
"../upload"
"net/http"
...
...
@@ -34,31 +35,41 @@ func (u *Upstream) Routes() []route {
}
func
(
u
*
Upstream
)
configureRoutes
()
{
api
:=
&
apipkg
.
API
{
RoundTripper
:
u
.
RoundTripper
(),
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
}
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
proxy
:=
&
pr
.
Proxy
{
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
RoundTripper
:
u
.
RoundTripper
()}
proxy
:=
&
proxypkg
.
Proxy
{
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
RoundTripper
:
u
.
RoundTripper
(),
}
u
.
routes
=
[]
route
{
// Git Clone
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
u
.
API
()
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
()
))},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
API
()
))},
route
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfs
.
PutStore
(
u
.
API
()
,
proxy
)},
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
api
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
api
))},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-receive-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
api
))},
route
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfs
.
PutStore
(
api
,
proxy
)},
// Repository Archive
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
api
)},
// Repository Archive API
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.gz\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
api
)},
// CI Artifacts API
route
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
upload
.
Artifacts
(
u
.
API
()
,
proxy
))},
route
{
"POST"
,
regexp
.
MustCompile
(
ciAPIPattern
+
`v1/builds/[0-9]+/artifacts\z`
),
contentEncodingHandler
(
upload
.
Artifacts
(
api
,
proxy
))},
// Explicitly proxy API requests
route
{
""
,
regexp
.
MustCompile
(
apiPattern
),
proxy
},
...
...
internal/upstream/upstream.go
View file @
d55aa579
...
...
@@ -7,11 +7,8 @@ In this file we handle request routing and interaction with the authBackend.
package
upstream
import
(
"../api"
"../badgateway"
"../helper"
"../proxy"
"../staticpages"
"../urlprefix"
"fmt"
"net/http"
...
...
@@ -31,12 +28,6 @@ type Upstream struct {
DevelopmentMode
bool
ResponseHeaderTimeout
time
.
Duration
_api
*
api
.
API
configureAPIOnce
sync
.
Once
_proxy
*
proxy
.
Proxy
configureProxyOnce
sync
.
Once
urlPrefix
urlprefix
.
Prefix
configureURLPrefixOnce
sync
.
Once
...
...
@@ -45,22 +36,6 @@ type Upstream struct {
roundtripper
*
badgateway
.
RoundTripper
configureRoundTripperOnce
sync
.
Once
_static
*
staticpages
.
Static
configureStaticOnce
sync
.
Once
}
func
(
u
*
Upstream
)
API
()
*
api
.
API
{
u
.
configureAPIOnce
.
Do
(
u
.
configureAPI
)
return
u
.
_api
}
func
(
u
*
Upstream
)
configureAPI
()
{
u
.
_api
=
&
api
.
API
{
Client
:
&
http
.
Client
{
Transport
:
u
.
RoundTripper
()},
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
}
}
func
(
u
*
Upstream
)
URLPrefix
()
urlprefix
.
Prefix
{
...
...
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