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
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
Hide 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
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"./internal/api"
"./internal/api"
"./internal/helper"
"./internal/helper"
"./internal/upstream"
"fmt"
"fmt"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
...
@@ -26,10 +25,10 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
...
@@ -26,10 +25,10 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
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
()
response
:=
httptest
.
NewRecorder
()
a
pi
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
a
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
response
,
expectedCode
)
helper
.
AssertResponseCode
(
t
,
response
,
expectedCode
)
return
response
return
response
}
}
...
...
internal/api/api.go
View file @
d55aa579
package
api
package
api
import
(
import
(
"../badgateway"
"../helper"
"../helper"
"../proxy"
"../proxy"
"encoding/json"
"encoding/json"
...
@@ -10,12 +11,25 @@ import (
...
@@ -10,12 +11,25 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"strings"
"strings"
"sync"
)
)
type
API
struct
{
type
API
struct
{
*
http
.
Client
_client
*
http
.
Client
URL
*
url
.
URL
configureClientOnce
sync
.
Once
Version
string
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
)
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
@@ -99,7 +113,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.HandlerFun
...
@@ -99,7 +113,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.HandlerFun
return
return
}
}
authResponse
,
err
:=
api
.
Do
(
authReq
)
authResponse
,
err
:=
api
.
client
()
.
Do
(
authReq
)
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
return
return
...
...
internal/upstream/routes.go
View file @
d55aa579
package
upstream
package
upstream
import
(
import
(
apipkg
"../api"
"../git"
"../git"
"../lfs"
"../lfs"
pr
"../proxy"
pr
oxypkg
"../proxy"
"../staticpages"
"../staticpages"
"../upload"
"../upload"
"net/http"
"net/http"
...
@@ -34,31 +35,41 @@ func (u *Upstream) Routes() []route {
...
@@ -34,31 +35,41 @@ func (u *Upstream) Routes() []route {
}
}
func
(
u
*
Upstream
)
configureRoutes
()
{
func
(
u
*
Upstream
)
configureRoutes
()
{
api
:=
&
apipkg
.
API
{
RoundTripper
:
u
.
RoundTripper
(),
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
}
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
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
{
u
.
routes
=
[]
route
{
// Git Clone
// Git Clone
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`info/refs\z`
),
git
.
GetInfoRefs
(
api
)},
route
{
"POST"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`git-upload-pack\z`
),
contentEncodingHandler
(
git
.
PostRPC
(
u
.
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
(
u
.
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
(
u
.
API
()
,
proxy
)},
route
{
"PUT"
,
regexp
.
MustCompile
(
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
),
lfs
.
PutStore
(
api
,
proxy
)},
// Repository Archive
// Repository Archive
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive\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
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
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
(
u
.
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
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
api
)},
// Repository Archive API
// Repository Archive API
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive\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
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.zip\z`
),
git
.
GetArchive
(
api
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar\z`
),
git
.
GetArchive
(
u
.
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
(
u
.
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
(
u
.
API
()
)},
route
{
"GET"
,
regexp
.
MustCompile
(
projectsAPIPattern
+
`repository/archive.tar.bz2\z`
),
git
.
GetArchive
(
api
)},
// CI Artifacts 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
// Explicitly proxy API requests
route
{
""
,
regexp
.
MustCompile
(
apiPattern
),
proxy
},
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.
...
@@ -7,11 +7,8 @@ In this file we handle request routing and interaction with the authBackend.
package
upstream
package
upstream
import
(
import
(
"../api"
"../badgateway"
"../badgateway"
"../helper"
"../helper"
"../proxy"
"../staticpages"
"../urlprefix"
"../urlprefix"
"fmt"
"fmt"
"net/http"
"net/http"
...
@@ -31,12 +28,6 @@ type Upstream struct {
...
@@ -31,12 +28,6 @@ type Upstream struct {
DevelopmentMode
bool
DevelopmentMode
bool
ResponseHeaderTimeout
time
.
Duration
ResponseHeaderTimeout
time
.
Duration
_api
*
api
.
API
configureAPIOnce
sync
.
Once
_proxy
*
proxy
.
Proxy
configureProxyOnce
sync
.
Once
urlPrefix
urlprefix
.
Prefix
urlPrefix
urlprefix
.
Prefix
configureURLPrefixOnce
sync
.
Once
configureURLPrefixOnce
sync
.
Once
...
@@ -45,22 +36,6 @@ type Upstream struct {
...
@@ -45,22 +36,6 @@ type Upstream struct {
roundtripper
*
badgateway
.
RoundTripper
roundtripper
*
badgateway
.
RoundTripper
configureRoundTripperOnce
sync
.
Once
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
{
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