@@ -7,31 +7,30 @@ import (
77 "time"
88
99 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
10+ "github.com/spf13/pflag"
1011)
1112
1213type LegacyOptions struct {
1314 // Legacy options related to upstream servers
14− LegacyFlushInterval time.Duration `flag:"flush-interval" cfg:"flush_interval"`
15− LegacyPassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
16− LegacyProxyWebSockets bool `flag:"proxy-websockets" cfg:"proxy_websockets"`
17− LegacySSLUpstreamInsecureSkipVerify bool `flag:"ssl-upstream-insecure-skip-verify" cfg:"ssl_upstream_insecure_skip_verify"`
18− LegacyUpstreams []string `flag:"upstream" cfg:"upstreams"`
15+ LegacyUpstreams LegacyUpstreams `cfg:",squash"`
1916
2017 Options Options `cfg:",squash"`
2118}
2219
2320func NewLegacyOptions() *LegacyOptions {
2421 return &LegacyOptions{
25− LegacyPassHostHeader: true,
26− LegacyProxyWebSockets: true,
27− LegacyFlushInterval: time.Duration(1) * time.Second,
22+ LegacyUpstreams: LegacyUpstreams{
23+ PassHostHeader: true,
24+ ProxyWebSockets: true,
25+ FlushInterval: time.Duration(1) * time.Second,
26+ },
2827
2928 Options: *NewOptions(),
3029 }
3130}
3231
3332func (l *LegacyOptions) ToOptions() (*Options, error) {
34− upstreams, err := convertLegacyUpstreams(l.LegacyUpstreams, l.LegacySSLUpstreamInsecureSkipVerify, l.LegacyPassHostHeader, l.LegacyProxyWebSockets, l.LegacyFlushInterval)
33+ upstreams, err := l.LegacyUpstreams.convert()
3534 if err != nil {
3635 return nil, fmt.Errorf("error converting upstreams: %v", err)
3736 }
@@ -40,10 +39,30 @@ func (l *LegacyOptions) ToOptions() (*Options, error) {
4039 return &l.Options, nil
4140}
4241
43−func convertLegacyUpstreams(upstreamStrings []string, skipVerify, passHostHeader, proxyWebSockets bool, flushInterval time.Duration) (Upstreams, error) {
42+type LegacyUpstreams struct {
43+ FlushInterval time.Duration `flag:"flush-interval" cfg:"flush_interval"`
44+ PassHostHeader bool `flag:"pass-host-header" cfg:"pass_host_header"`
45+ ProxyWebSockets bool `flag:"proxy-websockets" cfg:"proxy_websockets"`
46+ SSLUpstreamInsecureSkipVerify bool `flag:"ssl-upstream-insecure-skip-verify" cfg:"ssl_upstream_insecure_skip_verify"`
47+ Upstreams []string `flag:"upstream" cfg:"upstreams"`
48+}
49+
50+func legacyUpstreamsFlagSet() *pflag.FlagSet {
51+ flagSet := pflag.NewFlagSet("upstreams", pflag.ExitOnError)
52+
53+ flagSet.Duration("flush-interval", time.Duration(1)*time.Second, "period between response flushing when streaming responses")
54+ flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
55+ flagSet.Bool("proxy-websockets", true, "enables WebSocket proxying")
56+ flagSet.Bool("ssl-upstream-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS upstreams")
57+ flagSet.StringSlice("upstream", []string{}, "the http url(s) of the upstream endpoint, file:// paths for static files or static://<status_code> for static response. Routing is based on the path")
58+
59+ return flagSet
60+}
61+
62+func (l *LegacyUpstreams) convert() (Upstreams, error) {
4463 upstreams := Upstreams{}
4564
46− for _, upstreamString := range upstreamStrings {
65+ for _, upstreamString := range l.Upstreams {
4766 u, err := url.Parse(upstreamString)
4867 if err != nil {
4968 return nil, fmt.Errorf("could not parse upstream %q: %v", upstreamString, err)
@@ -57,10 +76,10 @@ func convertLegacyUpstreams(upstreamStrings []string, skipVerify, passHostHeader
5776 ID: u.Path,
5877 Path: u.Path,
5978 URI: upstreamString,
60− InsecureSkipTLSVerify: skipVerify,
61− PassHostHeader: passHostHeader,
62− ProxyWebSockets: proxyWebSockets,
63− FlushInterval: &flushInterval,
79+ InsecureSkipTLSVerify: l.SSLUpstreamInsecureSkipVerify,
80+ PassHostHeader: l.PassHostHeader,
81+ ProxyWebSockets: l.ProxyWebSockets,
82+ FlushInterval: &l.FlushInterval,
6483 }
6584
6685 switch u.Scheme {