From 2d352b4c1a6bd1c2eaafcffbd5776decb4c0f7a9 Mon Sep 17 00:00:00 2001 From: Will Piers Date: Thu, 17 Nov 2016 16:52:19 -0800 Subject: [PATCH] Return 418 when auth is turned off --- server/server.go | 5 +++-- server/service.go | 1 + server/users.go | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 3f0bb4664c..d4d6cf5f3c 100644 --- a/server/server.go +++ b/server/server.go @@ -60,7 +60,7 @@ func (s *Server) useAuth() bool { // Serve starts and runs the chronograf server func (s *Server) Serve() error { logger := clog.New(clog.ParseLevel(s.LogLevel)) - service := openService(s.BoltPath, s.CannedPath, logger) + service := openService(s.BoltPath, s.CannedPath, logger, s.useAuth()) s.handler = NewMux(MuxOpts{ Develop: s.Develop, TokenSecret: s.TokenSecret, @@ -106,7 +106,7 @@ func (s *Server) Serve() error { return nil } -func openService(boltPath, cannedPath string, logger chronograf.Logger) Service { +func openService(boltPath, cannedPath string, logger chronograf.Logger, useAuth bool) Service { db := bolt.NewClient() db.Path = boltPath if err := db.Open(); err != nil { @@ -144,6 +144,7 @@ func openService(boltPath, cannedPath string, logger chronograf.Logger) Service LayoutStore: layouts, AlertRulesStore: db.AlertsStore, Logger: logger, + UseAuth: useAuth, } } diff --git a/server/service.go b/server/service.go index 1e80108e23..f4e87e3512 100644 --- a/server/service.go +++ b/server/service.go @@ -12,6 +12,7 @@ type Service struct { UsersStore chronograf.UsersStore TimeSeries chronograf.TimeSeries Logger chronograf.Logger + UseAuth bool } // ErrorMessage is the error response format for all service errors diff --git a/server/users.go b/server/users.go index d00a6f4342..ac4d9f4409 100644 --- a/server/users.go +++ b/server/users.go @@ -147,6 +147,11 @@ func getEmail(ctx context.Context) (string, error) { // Me does a findOrCreate based on the email in the context func (h *Service) Me(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + if !h.UseAuth { + Error(w, http.StatusTeapot, fmt.Sprintf("%v", "Go to line 151 users.go. Look for Arnold")) + _ = 42 // did you mean to learn the answer? if so go to line aslfjasdlfja; (gee willickers.... tbc) + return + } email, err := getEmail(ctx) if err != nil { invalidData(w, err)