git.iko.soy/typeable/oauth2-proxy
on master help sign in
Refactor SignInMessage out of main
commite88d29f16a845b809ea58c46e9d8cd02e314edfe authorNick Meves <nick.meves@greenhouse.io> dateMon 20 Jul 2020, 21:01 (6 years ago) parent46cc21d
3 files changed+21−17
main.go−15 oauthproxy.go+19 watcher.go+2−2
main.go−15
@@ -7,7 +7,6 @@ import (
77 "os"
88 "os/signal"
99 "runtime"
10− "strings"
1110 "syscall"
1211 "time"
1312
@@ -62,20 +61,6 @@ func main() {
6261 os.Exit(1)
6362 }
6463
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−
7964 rand.Seed(time.Now().UnixNano())
8065
8166 chain := alice.New()
oauthproxy.go+19
@@ -213,6 +213,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr
213213 trustedIPs: trustedIPs,
214214 Banner: opts.Banner,
215215 Footer: opts.Footer,
216+ SignInMessage: buildSignInMessage(opts),
216217
217218 basicAuthValidator: basicAuthValidator,
218219 displayHtpasswdForm: basicAuthValidator != nil,
@@ -255,6 +256,24 @@ func buildSessionChain(opts *options.Options, sessionStore sessionsapi.SessionSt
255256 return chain
256257}
257258
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+
258277// GetRedirectURI returns the redirectURL that the upstream OAuth Provider will
259278// redirect clients to once authenticated
260279func (p *OAuthProxy) GetRedirectURI(host string) string {
watcher.go+2−2
@@ -44,7 +44,7 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) {
4444 defer func(w *fsnotify.Watcher) {
4545 cerr := w.Close()
4646 if cerr != nil {
47− logger.Fatalf("error closing watcher: %s", err)
47+ logger.Fatalf("error closing watcher: %v", err)
4848 }
4949 }(watcher)
5050 for {
@@ -62,7 +62,7 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) {
6262 logger.Printf("watching interrupted on event: %s", event)
6363 err = watcher.Remove(filename)
6464 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)
6666 }
6767 WaitForReplacement(filename, event.Op, watcher)
6868 }