14 "github.com/justinas/alice"
15 "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
16 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
17 "github.com/oauth2-proxy/oauth2-proxy/pkg/middleware"
18 "github.com/oauth2-proxy/oauth2-proxy/pkg/validation"
22 logger.SetFlags(logger.Lshortfile)
23 flagSet := options.NewFlagSet()
25 config := flagSet.String("config", "", "path to config file")
26 showVersion := flagSet.Bool("version", false, "print version string")
28 flagSet.Parse(os.Args[1:])
31 fmt.Printf("oauth2-proxy %s (built with %s)\n", VERSION, runtime.Version())
35 legacyOpts := options.NewLegacyOptions()
36 err := options.Load(*config, flagSet, legacyOpts)
38 logger.Printf("ERROR: Failed to load config: %v", err)
42 opts, err := legacyOpts.ToOptions()
44 logger.Printf("ERROR: Failed to convert config: %v", err)
48 err = validation.Validate(opts)
50 logger.Printf("%s", err)
54 validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
55 oauthproxy, err := NewOAuthProxy(opts, validator)
57 logger.Printf("ERROR: Failed to initialise OAuth2 Proxy: %v", err)
61 if len(opts.Banner) >= 1 {
62 if opts.Banner == "-" {
63 oauthproxy.SignInMessage = ""
65 oauthproxy.SignInMessage = opts.Banner
67 } else if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
68 if len(opts.EmailDomains) > 1 {
69 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using one of the following domains: %v", strings.Join(opts.EmailDomains, ", "))
70 } else if opts.EmailDomains[0] != "*" {
71 oauthproxy.SignInMessage = fmt.Sprintf("Authenticate using %v", opts.EmailDomains[0])
75 rand.Seed(time.Now().UnixNano())
80 _, httpsPort, err := net.SplitHostPort(opts.HTTPSAddress)
82 logger.Fatalf("FATAL: invalid HTTPS address %q: %v", opts.HTTPAddress, err)
84 chain = chain.Append(middleware.NewRedirectToHTTPS(httpsPort))
87 healthCheckPaths := []string{opts.PingPath}
88 healthCheckUserAgents := []string{opts.PingUserAgent}
89 if opts.GCPHealthChecks {
90 healthCheckPaths = append(healthCheckPaths, "/liveness_check", "/readiness_check")
91 healthCheckUserAgents = append(healthCheckUserAgents, "GoogleHC/1.0")
94 // To silence logging of health checks, register the health check handler before
95 // the logging handler
96 if opts.Logging.SilencePing {
97 chain = chain.Append(middleware.NewHealthCheck(healthCheckPaths, healthCheckUserAgents), LoggingHandler)
99 chain = chain.Append(LoggingHandler, middleware.NewHealthCheck(healthCheckPaths, healthCheckUserAgents))
103 Handler: chain.Then(oauthproxy),
105 stop: make(chan struct{}, 1),
107 // Observe signals in background goroutine.
109 sigint := make(chan os.Signal, 1)
110 signal.Notify(sigint, os.Interrupt, syscall.SIGTERM)
112 s.stop <- struct{}{} // notify having caught signal
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