7 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
8 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
11func validateUpstreams(upstreams options.UpstreamConfig) []string {
14 ids := make(map[string]struct{})
15 paths := make(map[string]struct{})
17 for _, upstream := range upstreams.Upstreams {
18 msgs = append(msgs, validateUpstream(upstream, ids, paths)...)
24// validateUpstream validates that the upstream has valid options and that
25// the ids and paths are unique across all options
26func validateUpstream(upstream options.Upstream, ids, paths map[string]struct{}) []string {
29 if upstream.ID == "" {
30 msgs = append(msgs, "upstream has empty id: ids are required for all upstreams")
32 if upstream.Path == "" {
33 msgs = append(msgs, fmt.Sprintf("upstream %q has empty path: paths are required for all upstreams", upstream.ID))
36 // Ensure upstream IDs are unique
37 if _, ok := ids[upstream.ID]; ok {
38 msgs = append(msgs, fmt.Sprintf("multiple upstreams found with id %q: upstream ids must be unique", upstream.ID))
40 ids[upstream.ID] = struct{}{}
42 // Ensure upstream Paths are unique
43 if _, ok := paths[upstream.Path]; ok {
44 msgs = append(msgs, fmt.Sprintf("multiple upstreams found with path %q: upstream paths must be unique", upstream.Path))
46 paths[upstream.Path] = struct{}{}
48 msgs = append(msgs, validateUpstreamURI(upstream)...)
49 msgs = append(msgs, validateStaticUpstream(upstream)...)
53// validateStaticUpstream checks that the StaticCode is only set when Static
54// is set, and that any options that do not make sense for a static upstream
56func validateStaticUpstream(upstream options.Upstream) []string {
59 if !ptr.Deref(upstream.Static, options.DefaultUpstreamStatic) && upstream.StaticCode != nil {
60 msgs = append(msgs, fmt.Sprintf("upstream %q has staticCode (%d), but is not a static upstream, set 'static' for a static response", upstream.ID, *upstream.StaticCode))
63 // Checks after this only make sense when the upstream is static
64 if !ptr.Deref(upstream.Static, options.DefaultUpstreamStatic) {
68 if upstream.URI != "" {
69 msgs = append(msgs, fmt.Sprintf("upstream %q has uri, but is a static upstream, this will have no effect.", upstream.ID))
71 if ptr.Deref(upstream.InsecureSkipTLSVerify, options.DefaultUpsteamInsecureSkipTLSVerify) {
72 msgs = append(msgs, fmt.Sprintf("upstream %q has insecureSkipTLSVerify, but is a static upstream, this will have no effect.", upstream.ID))
74 if ptr.Deref(upstream.FlushInterval, options.DefaultUpstreamFlushInterval) != options.DefaultUpstreamFlushInterval {
75 msgs = append(msgs, fmt.Sprintf("upstream %q has flushInterval, but is a static upstream, this will have no effect.", upstream.ID))
77 if ptr.Deref(upstream.PassHostHeader, options.DefaultStaticPassHostHeader) != options.DefaultStaticPassHostHeader {
78 msgs = append(msgs, fmt.Sprintf("upstream %q has passHostHeader, but is a static upstream, this will have no effect.", upstream.ID))
80 if ptr.Deref(upstream.ProxyWebSockets, options.DefaultStaticProxyWebSockets) != options.DefaultStaticProxyWebSockets {
81 msgs = append(msgs, fmt.Sprintf("upstream %q has proxyWebSockets, but is a static upstream, this will have no effect.", upstream.ID))
87func validateUpstreamURI(upstream options.Upstream) []string {
90 if !ptr.Deref(upstream.Static, options.DefaultUpstreamStatic) && upstream.URI == "" {
91 msgs = append(msgs, fmt.Sprintf("upstream %q has empty uri: uris are required for all non-static upstreams", upstream.ID))
95 // Checks after this only make sense the upstream is not static
96 if ptr.Deref(upstream.Static, options.DefaultUpstreamStatic) {
100 u, err := url.Parse(upstream.URI)
102 msgs = append(msgs, fmt.Sprintf("upstream %q has invalid uri: %v", upstream.ID, err))
107 case "http", "https", "file", "unix":
110 msgs = append(msgs, fmt.Sprintf("upstream %q has invalid scheme: %q", upstream.ID, u.Scheme))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list