From 6db18804f369ca1eef61667da02b22624f2ed1de Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Mon, 9 Nov 2015 00:57:01 +0100 Subject: [PATCH] *: rename Oauth to OAuth Be consistent with Go capitalization styling and use a single way of spelling this across the tree. --- main.go | 6 ++--- oauthproxy.go | 66 +++++++++++++++++++++++----------------------- oauthproxy_test.go | 16 +++++------ 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/main.go b/main.go index 3fe3961..93098dd 100644 --- a/main.go +++ b/main.go @@ -66,8 +66,8 @@ func main() { flagSet.String("redeem-url", "", "Token redemption endpoint") flagSet.String("profile-url", "", "Profile access endpoint") flagSet.String("validate-url", "", "Access token validation endpoint") - flagSet.String("scope", "", "Oauth scope specification") - flagSet.String("approval-prompt", "force", "Oauth approval_prompt") + flagSet.String("scope", "", "OAuth scope specification") + flagSet.String("approval-prompt", "force", "OAuth approval_prompt") flagSet.Parse(os.Args[1:]) @@ -95,7 +95,7 @@ func main() { } validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile) - oauthproxy := NewOauthProxy(opts, validator) + oauthproxy := NewOAuthProxy(opts, validator) if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" { if len(opts.EmailDomains) > 1 { diff --git a/oauthproxy.go b/oauthproxy.go index cbed710..73fd6f2 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -18,7 +18,7 @@ import ( "github.com/bitly/oauth2_proxy/providers" ) -type OauthProxy struct { +type OAuthProxy struct { CookieSeed string CookieName string CookieDomain string @@ -31,8 +31,8 @@ type OauthProxy struct { RobotsPath string PingPath string SignInPath string - OauthStartPath string - OauthCallbackPath string + OAuthStartPath string + OAuthCallbackPath string redirectURL *url.URL // the url to receive requests at provider providers.Provider @@ -86,7 +86,7 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) { return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath))) } -func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy { +func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy { serveMux := http.NewServeMux() for _, u := range opts.proxyURLs { path := u.Path @@ -119,7 +119,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy { redirectURL := opts.redirectURL redirectURL.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix) - log.Printf("OauthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID) + log.Printf("OAuthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID) domain := opts.CookieDomain if domain == "" { domain = "" @@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy { } } - return &OauthProxy{ + return &OAuthProxy{ CookieName: opts.CookieName, CookieSeed: opts.CookieSecret, CookieDomain: opts.CookieDomain, @@ -154,8 +154,8 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy { RobotsPath: "/robots.txt", PingPath: "/ping", SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix), - OauthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix), - OauthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix), + OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix), + OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix), ProxyPrefix: opts.ProxyPrefix, provider: opts.provider, @@ -171,7 +171,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy { } } -func (p *OauthProxy) GetRedirectURI(host string) string { +func (p *OAuthProxy) GetRedirectURI(host string) string { // default to the request Host if not set if p.redirectURL.Host != "" { return p.redirectURL.String() @@ -189,11 +189,11 @@ func (p *OauthProxy) GetRedirectURI(host string) string { return u.String() } -func (p *OauthProxy) displayCustomLoginForm() bool { +func (p *OAuthProxy) displayCustomLoginForm() bool { return p.HtpasswdFile != nil && p.DisplayHtpasswdForm } -func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) { +func (p *OAuthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) { if code == "" { return nil, errors.New("missing code") } @@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e return } -func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie { +func (p *OAuthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie { domain := req.Host if h, _, err := net.SplitHostPort(domain); err == nil { domain = h @@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time } } -func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) { http.SetCookie(rw, p.MakeCookie(req, "", time.Hour*-1, time.Now())) } -func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) { +func (p *OAuthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) { http.SetCookie(rw, p.MakeCookie(req, val, p.CookieExpire, time.Now())) } -func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) { +func (p *OAuthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) { var age time.Duration c, err := req.Cookie(p.CookieName) if err != nil { @@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt return session, age, nil } -func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error { +func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error { value, err := p.provider.CookieForSession(s, p.CookieCipher) if err != nil { return err @@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p return nil } -func (p *OauthProxy) RobotsTxt(rw http.ResponseWriter) { +func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) { rw.WriteHeader(http.StatusOK) fmt.Fprintf(rw, "User-agent: *\nDisallow: /") } -func (p *OauthProxy) PingPage(rw http.ResponseWriter) { +func (p *OAuthProxy) PingPage(rw http.ResponseWriter) { rw.WriteHeader(http.StatusOK) fmt.Fprintf(rw, "OK") } -func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) { +func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) { log.Printf("ErrorPage %d %s %s", code, title, message) rw.WriteHeader(code) t := struct { @@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m p.templates.ExecuteTemplate(rw, "error.html", t) } -func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) { +func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) { p.ClearCookie(rw, req) rw.WriteHeader(code) @@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code p.templates.ExecuteTemplate(rw, "sign_in.html", t) } -func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) { +func (p *OAuthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) { if req.Method != "POST" || p.HtpasswdFile == nil { return "", false } @@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st return "", false } -func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) { +func (p *OAuthProxy) GetRedirect(req *http.Request) (string, error) { err := req.ParseForm() if err != nil { @@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) { return redirect, err } -func (p *OauthProxy) IsWhitelistedPath(path string) (ok bool) { +func (p *OAuthProxy) IsWhitelistedPath(path string) (ok bool) { for _, u := range p.compiledRegex { ok = u.MatchString(path) if ok { @@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) { return } -func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { switch path := req.URL.Path; { case path == p.RobotsPath: p.RobotsTxt(rw) @@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { p.serveMux.ServeHTTP(rw, req) case path == p.SignInPath: p.SignIn(rw, req) - case path == p.OauthStartPath: - p.OauthStart(rw, req) - case path == p.OauthCallbackPath: - p.OauthCallback(rw, req) + case path == p.OAuthStartPath: + p.OAuthStart(rw, req) + case path == p.OAuthCallbackPath: + p.OAuthCallback(rw, req) default: p.Proxy(rw, req) } } -func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) { redirect, err := p.GetRedirect(req) if err != nil { p.ErrorPage(rw, 500, "Internal Error", err.Error()) @@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) { } } -func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) { redirect, err := p.GetRedirect(req) if err != nil { p.ErrorPage(rw, 500, "Internal Error", err.Error()) @@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) { http.Redirect(rw, req, p.provider.GetLoginURL(redirectURI, redirect), 302) } -func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) { remoteAddr := getRemoteAddr(req) // finish the oauth cycle @@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) { } } -func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) { +func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) { var saveSession, clearSession, revalidated bool remoteAddr := getRemoteAddr(req) @@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) { p.serveMux.ServeHTTP(rw, req) } -func (p *OauthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) { +func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) { if p.HtpasswdFile == nil { return nil, nil } diff --git a/oauthproxy_test.go b/oauthproxy_test.go index a109543..cf3f5aa 100644 --- a/oauthproxy_test.go +++ b/oauthproxy_test.go @@ -80,7 +80,7 @@ func TestRobotsTxt(t *testing.T) { opts.CookieSecret = "xyzzyplugh" opts.Validate() - proxy := NewOauthProxy(opts, func(string) bool { return true }) + proxy := NewOAuthProxy(opts, func(string) bool { return true }) rw := httptest.NewRecorder() req, _ := http.NewRequest("GET", "/robots.txt", nil) proxy.ServeHTTP(rw, req) @@ -144,7 +144,7 @@ func TestBasicAuthPassword(t *testing.T) { EmailAddress: email_address, } - proxy := NewOauthProxy(opts, func(email string) bool { + proxy := NewOAuthProxy(opts, func(email string) bool { return email == email_address }) @@ -199,7 +199,7 @@ func (tp *TestProvider) ValidateSessionState(session *providers.SessionState) bo type PassAccessTokenTest struct { provider_server *httptest.Server - proxy *OauthProxy + proxy *OAuthProxy opts *Options } @@ -265,7 +265,7 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes EmailAddress: email_address, } - t.proxy = NewOauthProxy(t.opts, func(email string) bool { + t.proxy = NewOAuthProxy(t.opts, func(email string) bool { return email == email_address }) return t @@ -360,7 +360,7 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) { type SignInPageTest struct { opts *Options - proxy *OauthProxy + proxy *OAuthProxy sign_in_regexp *regexp.Regexp } @@ -375,7 +375,7 @@ func NewSignInPageTest() *SignInPageTest { sip_test.opts.ClientSecret = "xyzzyplugh" sip_test.opts.Validate() - sip_test.proxy = NewOauthProxy(sip_test.opts, func(email string) bool { + sip_test.proxy = NewOAuthProxy(sip_test.opts, func(email string) bool { return true }) sip_test.sign_in_regexp = regexp.MustCompile(signInRedirectPattern) @@ -425,7 +425,7 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) { type ProcessCookieTest struct { opts *Options - proxy *OauthProxy + proxy *OAuthProxy rw *httptest.ResponseRecorder req *http.Request provider TestProvider @@ -449,7 +449,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts) *ProcessCookieTest { pc_test.opts.CookieRefresh = time.Hour pc_test.opts.Validate() - pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool { + pc_test.proxy = NewOAuthProxy(pc_test.opts, func(email string) bool { return pc_test.validate_user }) pc_test.proxy.provider = &TestProvider{