@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "flag"
5
6
"fmt"
6
7
"log"
7
8
"net/http"
@@ -15,30 +16,38 @@ import (
15
16
)
16
17
17
18
func main () {
18
- proxyAddr := "127.0.0.1:8124"
19
+ proxyAddr := flag .String ("addr" , "127.0.0.1:8124" ,
20
+ "Listen on this address for reverse proxy requests" )
19
21
20
- if len ( os . Args ) != 2 {
22
+ flag . Usage = func () {
21
23
fmt .Fprintf (os .Stderr ,
22
- "Usage: %s UPSTREAM_URL\n " +
24
+ "Usage: %s [flags] UPSTREAM_URL\n " +
23
25
"Example: %s https://proxy-dev.example.com\n \n " +
24
26
"Note: The oauth2_proxy running at UPSTREAM_URL must be configured with a\n " +
25
- " special redirect URL for this development proxy.\n " ,
27
+ " special redirect URL for this development proxy.\n \n " ,
26
28
os .Args [0 ], os .Args [0 ])
29
+ flag .PrintDefaults ()
30
+ }
31
+
32
+ flag .Parse ()
33
+
34
+ if len (flag .Args ()) != 1 {
35
+ flag .Usage ()
27
36
os .Exit (1 )
28
37
}
29
38
30
- upstreamURL , err := url .Parse (os .Args [ 1 ])
39
+ upstreamURL , err := url .Parse (flag .Args ()[ 0 ])
31
40
if err != nil {
32
41
log .Fatalf ("Failed to parse target URL: %v" , err )
33
42
}
34
43
35
44
authCompleteNotice := fmt .Sprintf ("Authentication complete. You can now use the proxy.\n \n " +
36
45
"Proxy URL: http://%s\n " +
37
- "Upstream: %s\n \n " , proxyAddr , upstreamURL )
46
+ "Upstream: %s\n \n " , * proxyAddr , upstreamURL )
38
47
39
48
authCookie := authenticate (upstreamURL , authCompleteNotice )
40
49
41
- go runProxy (proxyAddr , upstreamURL , authCookie )
50
+ go runProxy (* proxyAddr , upstreamURL , authCookie )
42
51
43
52
log .Printf ("The proxy will automatically terminate in 12 hours (reauthentication required)" )
44
53
0 commit comments