git.iko.soy/typeable/oauth2-proxy
on master help sign in
Refactor SignInMessage out of main
e88d29fNick Meves
main.go−15
@@ -7,7 +7,6 @@ import (
7 "os"
7 "os"
8 "os/signal"
8 "os/signal"
9 "runtime"
9 "runtime"
10− "strings"
11 "syscall"
10 "syscall"
12 "time"
11 "time"
13
12
@@ -62,20 +61,6 @@ func main() {
62 os.Exit(1)
61 os.Exit(1)
63 }
62 }
64
63
65− if len(opts.Banner) >= 1 {
66− if opts.Banner == "-" {
67− oauthproxy.SignInMessage = ""
68− } else {
69− oauthproxy.SignInMessage = opts.Banner
70− }
71− } else if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
72− if len(opts.EmailDomains) > 1 {
73− oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.EmailDomains, ", "))
74− } else if opts.EmailDomains[0] != "*" {
75− oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using %v", opts.EmailDomains[0])
76− }
77− }
78−
79 rand.Seed(time.Now().UnixNano())
64 rand.Seed(time.Now().UnixNano())
80
65
81 chain := alice.New()
66 chain := alice.New()
oauthproxy.go+19
@@ -213,6 +213,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr
213 trustedIPs: trustedIPs,
213 trustedIPs: trustedIPs,
214 Banner: opts.Banner,
214 Banner: opts.Banner,
215 Footer: opts.Footer,
215 Footer: opts.Footer,
216+ SignInMessage: buildSignInMessage(opts),
216
217
217 basicAuthValidator: basicAuthValidator,
218 basicAuthValidator: basicAuthValidator,
218 displayHtpasswdForm: basicAuthValidator != nil,
219 displayHtpasswdForm: basicAuthValidator != nil,
@@ -255,6 +256,24 @@ func buildSessionChain(opts *options.Options, sessionStore sessionsapi.SessionSt
255 return chain
256 return chain
256}
257}
257
258
259+func buildSignInMessage(opts *options.Options) string {
260+ var msg string
261+ if len(opts.Banner) >= 1 {
262+ if opts.Banner == "-" {
263+ msg = ""
264+ } else {
265+ msg = opts.Banner
266+ }
267+ } else if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
268+ if len(opts.EmailDomains) > 1 {
269+ msg = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.EmailDomains, ", "))
270+ } else if opts.EmailDomains[0] != "*" {
271+ msg = fmt.Sprintf("Authenticate using %v", opts.EmailDomains[0])
272+ }
273+ }
274+ return msg
275+}
276+
258// GetRedirectURI returns the redirectURL that the upstream OAuth Provider will
277// GetRedirectURI returns the redirectURL that the upstream OAuth Provider will
259// redirect clients to once authenticated
278// redirect clients to once authenticated
260func (p *OAuthProxy) GetRedirectURI(host string) string {
279func (p *OAuthProxy) GetRedirectURI(host string) string {
watcher.go+2−2
@@ -44,7 +44,7 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) {
44 defer func(w *fsnotify.Watcher) {
44 defer func(w *fsnotify.Watcher) {
45 cerr := w.Close()
45 cerr := w.Close()
46 if cerr != nil {
46 if cerr != nil {
47− logger.Fatalf("error closing watcher: %s", err)
47+ logger.Fatalf("error closing watcher: %v", err)
48 }
48 }
49 }(watcher)
49 }(watcher)
50 for {
50 for {
@@ -62,7 +62,7 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) {
62 logger.Printf("watching interrupted on event: %s", event)
62 logger.Printf("watching interrupted on event: %s", event)
63 err = watcher.Remove(filename)
63 err = watcher.Remove(filename)
64 if err != nil {
64 if err != nil {
65− logger.Printf("error removing watcher on %s: %s", filename, err)
65+ logger.Printf("error removing watcher on %s: %v", filename, err)
66 }
66 }
67 WaitForReplacement(filename, event.Op, watcher)
67 WaitForReplacement(filename, event.Op, watcher)
68 }
68 }