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
08ec1011
Commit
08ec1011
authored
Aug 23, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix backend URL parsing
parent
cdcabf45
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
28 deletions
+76
-28
backend.go
backend.go
+30
-0
internal/badgateway/roundtripper.go
internal/badgateway/roundtripper.go
+1
-1
main.go
main.go
+8
-2
main_test.go
main_test.go
+37
-0
urlflag.go
urlflag.go
+0
-25
No files found.
backend.go
0 → 100644
View file @
08ec1011
package
main
import
(
"fmt"
"net/url"
)
func
parseAuthBackend
(
authBackend
string
)
(
*
url
.
URL
,
error
)
{
backendURL
,
err
:=
url
.
Parse
(
authBackend
)
if
err
!=
nil
{
return
nil
,
err
}
if
backendURL
.
Host
==
""
{
backendURL
,
err
=
url
.
Parse
(
"http://"
+
authBackend
)
if
err
!=
nil
{
return
nil
,
err
}
}
if
backendURL
.
Scheme
!=
"http"
{
return
nil
,
fmt
.
Errorf
(
"invalid scheme, only 'http' is allowed: %q"
,
authBackend
)
}
if
backendURL
.
Host
==
""
{
return
nil
,
fmt
.
Errorf
(
"missing host in %q"
,
authBackend
)
}
return
backendURL
,
nil
}
internal/badgateway/roundtripper.go
View file @
08ec1011
...
@@ -64,7 +64,7 @@ func mustParseAddress(address, scheme string) string {
...
@@ -64,7 +64,7 @@ func mustParseAddress(address, scheme string) string {
}
}
}
}
panic
(
"could not parse host:port from address and scheme"
)
panic
(
fmt
.
Errorf
(
"could not parse host:port from address %q and scheme %q"
,
address
,
scheme
)
)
}
}
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
...
...
main.go
View file @
08ec1011
...
@@ -34,7 +34,7 @@ var printVersion = flag.Bool("version", false, "Print version and exit")
...
@@ -34,7 +34,7 @@ var printVersion = flag.Bool("version", false, "Print version and exit")
var
listenAddr
=
flag
.
String
(
"listenAddr"
,
"localhost:8181"
,
"Listen address for HTTP server"
)
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
listenNetwork
=
flag
.
String
(
"listenNetwork"
,
"tcp"
,
"Listen 'network' (tcp, tcp4, tcp6, unix)"
)
var
listenUmask
=
flag
.
Int
(
"listenUmask"
,
0
,
"Umask for Unix socket"
)
var
listenUmask
=
flag
.
Int
(
"listenUmask"
,
0
,
"Umask for Unix socket"
)
var
authBackend
=
URLFlag
(
"authBackend"
,
upstream
.
DefaultBackend
,
"Authentication/authorization backend"
)
var
authBackend
=
flag
.
String
(
"authBackend"
,
upstream
.
DefaultBackend
.
String
()
,
"Authentication/authorization backend"
)
var
authSocket
=
flag
.
String
(
"authSocket"
,
""
,
"Optional: Unix domain socket to dial authBackend at"
)
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
pprofListenAddr
=
flag
.
String
(
"pprofListenAddr"
,
""
,
"pprof listening address, e.g. 'localhost:6060'"
)
var
documentRoot
=
flag
.
String
(
"documentRoot"
,
"public"
,
"Path to static files content"
)
var
documentRoot
=
flag
.
String
(
"documentRoot"
,
"public"
,
"Path to static files content"
)
...
@@ -55,6 +55,12 @@ func main() {
...
@@ -55,6 +55,12 @@ func main() {
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
backendURL
,
err
:=
parseAuthBackend
(
*
authBackend
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"invalid authBackend: %v
\n
"
,
err
)
os
.
Exit
(
1
)
}
log
.
Printf
(
"Starting %s"
,
version
)
log
.
Printf
(
"Starting %s"
,
version
)
// Good housekeeping for Unix sockets: unlink before binding
// Good housekeeping for Unix sockets: unlink before binding
...
@@ -83,7 +89,7 @@ func main() {
...
@@ -83,7 +89,7 @@ func main() {
}
}
up
:=
upstream
.
NewUpstream
(
up
:=
upstream
.
NewUpstream
(
*
authBackend
,
backendURL
,
*
authSocket
,
*
authSocket
,
Version
,
Version
,
*
documentRoot
,
*
documentRoot
,
...
...
main_test.go
View file @
08ec1011
...
@@ -736,6 +736,43 @@ func TestGetGitPatch(t *testing.T) {
...
@@ -736,6 +736,43 @@ func TestGetGitPatch(t *testing.T) {
}
}
}
}
func
TestParseAuthBackend
(
t
*
testing
.
T
)
{
failures
:=
[]
string
{
""
,
"ftp://localhost"
,
"https://example.com"
,
}
for
_
,
example
:=
range
failures
{
if
_
,
err
:=
parseAuthBackend
(
example
);
err
==
nil
{
t
.
Errorf
(
"error expected for %q"
,
example
)
}
}
successes
:=
[]
struct
{
input
,
host
,
scheme
string
}{
{
"http://localhost:8080"
,
"localhost:8080"
,
"http"
},
{
"localhost:3000"
,
"localhost:3000"
,
"http"
},
{
"http://localhost"
,
"localhost"
,
"http"
},
{
"localhost"
,
"localhost"
,
"http"
},
}
for
_
,
example
:=
range
successes
{
result
,
err
:=
parseAuthBackend
(
example
.
input
)
if
err
!=
nil
{
t
.
Errorf
(
"parse %q: %v"
,
example
.
input
,
err
)
break
}
if
result
.
Host
!=
example
.
host
{
t
.
Errorf
(
"expected %q, got %q"
,
example
.
host
,
result
.
Host
)
}
if
result
.
Scheme
!=
example
.
scheme
{
t
.
Errorf
(
"expected %q, got %q"
,
example
.
scheme
,
result
.
Scheme
)
}
}
}
func
setupStaticFile
(
fpath
,
content
string
)
error
{
func
setupStaticFile
(
fpath
,
content
string
)
error
{
cwd
,
err
:=
os
.
Getwd
()
cwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
urlflag.go
deleted
100644 → 0
View file @
cdcabf45
package
main
import
(
"flag"
"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
*
url
.
URL
,
usage
string
)
**
url
.
URL
{
f
:=
&
urlFlag
{
value
}
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