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
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-workhorse
Commits
ae66b95f
Commit
ae66b95f
authored
Dec 19, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make authBackend a *url.URL
parent
ede3979f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
54 additions
and
28 deletions
+54
-28
authorization_test.go
authorization_test.go
+1
-1
internal/api/api.go
internal/api/api.go
+2
-2
internal/helper/helpers.go
internal/helper/helpers.go
+9
-0
internal/proxy/proxy.go
internal/proxy/proxy.go
+4
-9
internal/upload/uploads_test.go
internal/upload/uploads_test.go
+2
-2
internal/upstream/upstream.go
internal/upstream/upstream.go
+3
-9
main.go
main.go
+2
-2
main_test.go
main_test.go
+1
-1
proxy_test.go
proxy_test.go
+2
-2
urlflag.go
urlflag.go
+28
-0
No files found.
authorization_test.go
View file @
ae66b95f
...
...
@@ -27,7 +27,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
api
:=
upstream
.
New
(
ts
.
URL
,
""
,
"123"
,
time
.
Second
)
.
API
api
:=
upstream
.
New
(
helper
.
URLMustParse
(
ts
.
URL
)
,
""
,
"123"
,
time
.
Second
)
.
API
response
:=
httptest
.
NewRecorder
()
api
.
PreAuthorizeHandler
(
okHandler
,
suffix
)(
response
,
httpRequest
)
...
...
internal/api/api.go
View file @
ae66b95f
...
...
@@ -14,7 +14,7 @@ import (
type
API
struct
{
*
http
.
Client
*
url
.
URL
URL
*
url
.
URL
Version
string
}
...
...
@@ -49,7 +49,7 @@ type Response struct {
}
func
(
api
*
API
)
newRequest
(
r
*
http
.
Request
,
body
io
.
Reader
,
suffix
string
)
(
*
http
.
Request
,
error
)
{
url
:=
*
api
.
URL
url
:=
*
api
.
URL
// Make a copy of api.URL
url
.
Path
=
r
.
URL
.
RequestURI
()
+
suffix
authReq
:=
&
http
.
Request
{
Method
:
r
.
Method
,
...
...
internal/helper/helpers.go
View file @
ae66b95f
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"log"
"net/http"
"net/url"
"os"
)
...
...
@@ -51,3 +52,11 @@ func OpenFile(path string) (file *os.File, fi os.FileInfo, err error) {
return
}
func
URLMustParse
(
s
string
)
*
url
.
URL
{
u
,
err
:=
url
.
Parse
(
s
)
if
err
!=
nil
{
log
.
Fatalf
(
"urlMustParse: %q %v"
,
s
,
err
)
}
return
u
}
internal/proxy/proxy.go
View file @
ae66b95f
...
...
@@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
...
...
@@ -13,7 +12,7 @@ import (
)
type
Proxy
struct
{
URL
string
URL
*
url
.
URL
Version
string
Transport
http
.
RoundTripper
_reverseProxy
*
httputil
.
ReverseProxy
...
...
@@ -26,13 +25,9 @@ func (p *Proxy) reverseProxy() *httputil.ReverseProxy {
}
func
(
p
*
Proxy
)
configureReverseProxy
()
{
// Modify a copy of url
url
,
err
:=
url
.
Parse
(
p
.
URL
)
if
err
!=
nil
{
log
.
Fatalf
(
"configureReverseProxy: %v"
,
err
)
}
url
.
Path
=
""
p
.
_reverseProxy
=
httputil
.
NewSingleHostReverseProxy
(
url
)
u
:=
*
p
.
URL
// Make a copy of p.URL
u
.
Path
=
""
p
.
_reverseProxy
=
httputil
.
NewSingleHostReverseProxy
(
&
u
)
p
.
_reverseProxy
.
Transport
=
p
.
Transport
}
...
...
internal/upload/uploads_test.go
View file @
ae66b95f
...
...
@@ -57,7 +57,7 @@ func TestUploadHandlerForwardingRawData(t *testing.T) {
httpRequest
.
Header
.
Set
(
tempPathHeader
,
tempPath
)
handleFileUploads
(
&
proxy
.
Proxy
{
URL
:
ts
.
URL
,
Version
:
"123"
})
.
ServeHTTP
(
response
,
httpRequest
)
handleFileUploads
(
&
proxy
.
Proxy
{
URL
:
helper
.
URLMustParse
(
ts
.
URL
)
,
Version
:
"123"
})
.
ServeHTTP
(
response
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
response
,
202
)
if
response
.
Body
.
String
()
!=
"RESPONSE"
{
t
.
Fatal
(
"Expected RESPONSE in response body"
)
...
...
@@ -131,7 +131,7 @@ func TestUploadHandlerRewritingMultiPartData(t *testing.T) {
httpRequest
.
Header
.
Set
(
tempPathHeader
,
tempPath
)
response
:=
httptest
.
NewRecorder
()
handleFileUploads
(
&
proxy
.
Proxy
{
URL
:
ts
.
URL
,
Version
:
"123"
})
.
ServeHTTP
(
response
,
httpRequest
)
handleFileUploads
(
&
proxy
.
Proxy
{
URL
:
helper
.
URLMustParse
(
ts
.
URL
)
,
Version
:
"123"
})
.
ServeHTTP
(
response
,
httpRequest
)
helper
.
AssertResponseCode
(
t
,
response
,
202
)
if
_
,
err
:=
os
.
Stat
(
filePath
);
!
os
.
IsNotExist
(
err
)
{
...
...
internal/upstream/upstream.go
View file @
ae66b95f
...
...
@@ -10,7 +10,6 @@ import (
"../api"
"../proxy"
"fmt"
"log"
"net"
"net/http"
"net/url"
...
...
@@ -30,13 +29,8 @@ type Upstream struct {
routes
[]
route
}
func
New
(
authBackend
string
,
authSocket
string
,
version
string
,
responseHeadersTimeout
time
.
Duration
)
*
Upstream
{
parsedURL
,
err
:=
url
.
Parse
(
authBackend
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
relativeURLRoot
:=
parsedURL
.
Path
func
New
(
authBackend
*
url
.
URL
,
authSocket
string
,
version
string
,
responseHeadersTimeout
time
.
Duration
)
*
Upstream
{
relativeURLRoot
:=
authBackend
.
Path
if
!
strings
.
HasSuffix
(
relativeURLRoot
,
"/"
)
{
relativeURLRoot
+=
"/"
}
...
...
@@ -61,7 +55,7 @@ func New(authBackend string, authSocket string, version string, responseHeadersT
up
:=
&
Upstream
{
API
:
&
api
.
API
{
Client
:
&
http
.
Client
{
Transport
:
proxyTransport
},
URL
:
parsedURL
,
URL
:
authBackend
,
Version
:
version
,
},
Proxy
:
&
proxy
.
Proxy
{
URL
:
authBackend
,
Transport
:
proxyTransport
,
Version
:
version
},
...
...
main.go
View file @
ae66b95f
...
...
@@ -33,7 +33,7 @@ var printVersion = flag.Bool("version", false, "Print version and exit")
var
listenAddr
=
flag
.
String
(
"listenAddr"
,
"localhost:8181"
,
"Listen address for HTTP server"
)
var
listenNetwork
=
flag
.
String
(
"listenNetwork"
,
"tcp"
,
"Listen 'network' (tcp, tcp4, tcp6, unix)"
)
var
listenUmask
=
flag
.
Int
(
"listenUmask"
,
022
,
"Umask for Unix socket, default: 022"
)
var
authBackend
=
flag
.
Strin
g
(
"authBackend"
,
"http://localhost:8080"
,
"Authentication/authorization backend"
)
var
authBackend
=
URLFla
g
(
"authBackend"
,
"http://localhost:8080"
,
"Authentication/authorization backend"
)
var
authSocket
=
flag
.
String
(
"authSocket"
,
""
,
"Optional: Unix domain socket to dial authBackend at"
)
var
pprofListenAddr
=
flag
.
String
(
"pprofListenAddr"
,
""
,
"pprof listening address, e.g. 'localhost:6060'"
)
var
documentRoot
=
flag
.
String
(
"documentRoot"
,
"public"
,
"Path to static files content"
)
...
...
@@ -81,7 +81,7 @@ func main() {
}()
}
up
:=
upstream
.
New
(
*
authBackend
,
*
authSocket
,
Version
,
*
responseHeadersTimeout
)
up
:=
upstream
.
New
(
authBackend
,
*
authSocket
,
Version
,
*
responseHeadersTimeout
)
up
.
DocumentRoot
=
*
documentRoot
up
.
DevelopmentMode
=
*
developmentMode
...
...
main_test.go
View file @
ae66b95f
...
...
@@ -311,7 +311,7 @@ func testAuthServer(url *regexp.Regexp, code int, body interface{}) *httptest.Se
}
func
startWorkhorseServer
(
authBackend
string
)
*
httptest
.
Server
{
u
:=
upstream
.
New
(
authBackend
,
""
,
"123"
,
time
.
Second
)
u
:=
upstream
.
New
(
helper
.
URLMustParse
(
authBackend
)
,
""
,
"123"
,
time
.
Second
)
return
httptest
.
NewServer
(
u
)
}
...
...
proxy_test.go
View file @
ae66b95f
...
...
@@ -16,7 +16,7 @@ import (
)
func
newUpstream
(
url
string
)
*
upstream
.
Upstream
{
return
upstream
.
New
(
url
,
""
,
"123"
,
time
.
Second
)
return
upstream
.
New
(
helper
.
URLMustParse
(
url
)
,
""
,
"123"
,
time
.
Second
)
}
func
TestProxyRequest
(
t
*
testing
.
T
)
{
...
...
@@ -93,7 +93,7 @@ func TestProxyReadTimeout(t *testing.T) {
},
)
p
:=
&
proxy
.
Proxy
{
URL
:
ts
.
URL
,
Transport
:
transport
,
Version
:
"123"
}
p
:=
&
proxy
.
Proxy
{
URL
:
helper
.
URLMustParse
(
ts
.
URL
)
,
Transport
:
transport
,
Version
:
"123"
}
w
:=
httptest
.
NewRecorder
()
p
.
ServeHTTP
(
w
,
httpRequest
)
...
...
urlflag.go
0 → 100644
View file @
ae66b95f
package
main
import
(
"flag"
"log"
"net/url"
)
type
urlFlag
struct
{
*
url
.
URL
}
func
(
u
*
urlFlag
)
Set
(
s
string
)
error
{
myURL
,
err
:=
url
.
Parse
(
s
)
if
err
!=
nil
{
return
err
}
u
.
URL
=
myURL
return
nil
}
func
URLFlag
(
name
string
,
value
string
,
usage
string
)
*
url
.
URL
{
u
,
err
:=
url
.
Parse
(
value
)
if
err
!=
nil
{
log
.
Fatalf
(
"URLFlag: invalid default: %q %v"
,
value
,
err
)
}
f
:=
urlFlag
{
u
}
flag
.
CommandLine
.
Var
(
&
f
,
name
,
usage
)
return
f
.
URL
}
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