diff --git a/glide.lock b/glide.lock index af126ad6..49fb43e5 100644 --- a/glide.lock +++ b/glide.lock @@ -27,7 +27,7 @@ imports: - name: github.com/mongodb/grip version: 3568ece3546276b170764c0ea70f6e7ea900c90f -- name: github.com/tychoish/gimlet - version: d82810b14d780876cdf9298de20a1e913c99c3ef +- name: github.com/evergreen-ci/gimlet + version: 029685fbee66bbc1713d61946725bb190ae4b095 devImports: [] diff --git a/glide.yaml b/glide.yaml index a6220e3f..bf7ac0be 100644 --- a/glide.yaml +++ b/glide.yaml @@ -7,6 +7,6 @@ import: - package: github.com/stretchr/testify - package: github.com/mongodb/grip - package: github.com/mongodb/mongo-go-driver -- package: github.com/tychoish/gimlet +- package: github.com/evergreen-ci/gimlet - package: gopkg.in/mgo.v2 - package: gopkg.in/yaml.v2 diff --git a/makefile b/makefile index 75fd6f5c..d3fba2a6 100644 --- a/makefile +++ b/makefile @@ -173,8 +173,8 @@ vendor-sync:$(vendorDeps) glide install -s vendor-clean: rm -rf vendor/gopkg.in/mgo.v2/harness/ - rm -rf vendor/github.com/tychoish/gimlet/vendor/github.com/stretchr/testify/ - rm -rf vendor/github.com/tychoish/gimlet/vendor/github.com/mongodb/grip/ + rm -rf vendor/github.com/evergreen-ci/gimlet/vendor/github.com/stretchr/testify/ + rm -rf vendor/github.com/evergreen-ci/gimlet/vendor/github.com/mongodb/grip/ rm -rf vendor/github.com/mongodb/grip/vendor/github.com/stretchr/testify/ rm -rf vendor/gopkg.in/mgo.v2/harness/ rm -rf vendor/gopkg.in/mgo.v2/testdb/ diff --git a/rest/client.go b/rest/client.go index 72caa71c..1e648106 100644 --- a/rest/client.go +++ b/rest/client.go @@ -9,11 +9,11 @@ import ( "strings" "time" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/amboy/registry" "github.com/mongodb/grip" "github.com/pkg/errors" - "github.com/tychoish/gimlet" ) const ( diff --git a/rest/create.go b/rest/create.go index 9dda9dd2..b4196519 100644 --- a/rest/create.go +++ b/rest/create.go @@ -3,10 +3,10 @@ package rest import ( "net/http" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/amboy/registry" "github.com/mongodb/grip" - "github.com/tychoish/gimlet" ) type createResponse struct { diff --git a/rest/fetch.go b/rest/fetch.go index f58f33aa..07800bea 100644 --- a/rest/fetch.go +++ b/rest/fetch.go @@ -3,10 +3,10 @@ package rest import ( "net/http" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/amboy/registry" "github.com/mongodb/grip" - "github.com/tychoish/gimlet" ) // Fetch is an http handler that writes a job interchange object to a diff --git a/rest/job.go b/rest/job.go index 0e6596c2..22f3c47e 100644 --- a/rest/job.go +++ b/rest/job.go @@ -6,10 +6,10 @@ import ( "net/http" "time" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/grip" "github.com/pkg/errors" - "github.com/tychoish/gimlet" ) type jobStatusResponse struct { diff --git a/rest/service.go b/rest/service.go index 22fb572e..d7e88cea 100644 --- a/rest/service.go +++ b/rest/service.go @@ -4,12 +4,12 @@ import ( "context" "time" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/amboy/queue" "github.com/mongodb/amboy/registry" "github.com/mongodb/grip" "github.com/pkg/errors" - "github.com/tychoish/gimlet" ) // Service is used as a place holder for application state and configuration. diff --git a/rest/stats.go b/rest/stats.go index 474b096d..047aa4d3 100644 --- a/rest/stats.go +++ b/rest/stats.go @@ -5,9 +5,9 @@ import ( "net/http" "time" + "github.com/evergreen-ci/gimlet" "github.com/mongodb/amboy" "github.com/mongodb/grip" - "github.com/tychoish/gimlet" ) type status struct { diff --git a/vendor/github.com/tychoish/gimlet/.gitignore b/vendor/github.com/evergreen-ci/gimlet/.gitignore similarity index 100% rename from vendor/github.com/tychoish/gimlet/.gitignore rename to vendor/github.com/evergreen-ci/gimlet/.gitignore diff --git a/vendor/github.com/tychoish/gimlet/.travis.yml b/vendor/github.com/evergreen-ci/gimlet/.travis.yml similarity index 100% rename from vendor/github.com/tychoish/gimlet/.travis.yml rename to vendor/github.com/evergreen-ci/gimlet/.travis.yml diff --git a/vendor/github.com/tychoish/gimlet/README.rst b/vendor/github.com/evergreen-ci/gimlet/README.rst similarity index 100% rename from vendor/github.com/tychoish/gimlet/README.rst rename to vendor/github.com/evergreen-ci/gimlet/README.rst diff --git a/vendor/github.com/tychoish/gimlet/app.go b/vendor/github.com/evergreen-ci/gimlet/app.go similarity index 97% rename from vendor/github.com/tychoish/gimlet/app.go rename to vendor/github.com/evergreen-ci/gimlet/app.go index 58223599..8dffc12d 100644 --- a/vendor/github.com/tychoish/gimlet/app.go +++ b/vendor/github.com/evergreen-ci/gimlet/app.go @@ -11,6 +11,7 @@ package gimlet import ( + "context" "errors" "fmt" "net/http" @@ -200,7 +201,7 @@ func (a *APIApp) Handler() (http.Handler, error) { // Run configured API service on the configured port. Before running // the application, Run also resolves any sub-apps, and adds all // routes. -func (a *APIApp) Run() error { +func (a *APIApp) Run(ctx context.Context) error { n, err := a.getNegroni() if err != nil { return err @@ -221,6 +222,11 @@ func (a *APIApp) Run() error { grip.Noticef("starting app on: %s:$d", a.address, a.port) catcher.Add(srv.ListenAndServe()) + }() + + go func() { + defer recovery.LogStackTraceAndContinue("server shutdown") + catcher.Add(srv.Shutdown(ctx)) close(serviceWait) }() diff --git a/vendor/github.com/tychoish/gimlet/app_test.go b/vendor/github.com/evergreen-ci/gimlet/app_test.go similarity index 92% rename from vendor/github.com/tychoish/gimlet/app_test.go rename to vendor/github.com/evergreen-ci/gimlet/app_test.go index 94e07df2..9d77ef84 100644 --- a/vendor/github.com/tychoish/gimlet/app_test.go +++ b/vendor/github.com/evergreen-ci/gimlet/app_test.go @@ -1,11 +1,14 @@ package gimlet import ( + "context" "net/http" "testing" + "time" "github.com/mongodb/grip" "github.com/mongodb/grip/level" + "github.com/mongodb/grip/send" "github.com/stretchr/testify/suite" ) @@ -22,7 +25,7 @@ func TestAppSuite(t *testing.T) { func (s *AppSuite) SetupTest() { s.app = NewApp() - grip.SetThreshold(level.Info) + grip.GetSender().SetLevel(send.LevelInfo{Threshold: level.Info}) } func (s *AppSuite) TestDefaultValuesAreSet() { @@ -249,7 +252,7 @@ func (s *AppSuite) TestSubAppResolutionWithErrors() { n, err := s.app.getNegroni() s.Nil(n) s.Error(err) - s.Error(s.app.Run()) + s.Error(s.app.Run(context.Background())) } func (s *AppSuite) TestResolveAppWithDefaultVersion() { @@ -327,3 +330,22 @@ func (s *AppSuite) TestGetVersionRoute() { s.Equal(output, getVersionedRoute(prefix, version, route)) } } + +func (s *AppSuite) TestHandlerGetter() { + hone, err := s.app.getNegroni() + s.NoError(err) + s.NotNil(hone) + htwo, err := s.app.Handler() + s.NoError(err) + s.NotNil(htwo) + + // should be equivalent results but are different instances, as each app should be distinct. + s.NotEqual(hone, htwo) +} + +func (s *AppSuite) TestAppRun() { + s.Len(s.app.routes, 0) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + s.NoError(s.app.Run(ctx)) +} diff --git a/vendor/github.com/evergreen-ci/gimlet/auth/interfaces.go b/vendor/github.com/evergreen-ci/gimlet/auth/interfaces.go new file mode 100644 index 00000000..3af85639 --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/auth/interfaces.go @@ -0,0 +1,56 @@ +package auth + +import ( + "context" + "net/http" +) + +// User provides a common way of interacting with users from +// authentication systems. +// +// Note: this is the User interface from Evergreen with the addition +// of the Roles() method. +type User interface { + DisplayName() string + Email() string + Username() string + IsNil() bool + GetAPIKey() string + Roles() []string +} + +type Provider interface { + Reload(context.Context) error + Open(context.Context) error + Close() error + Authenticator() Authenticator + UserManager() UserManager +} + +// Authenticator represents a service that answers specific +// authentication related questions, and is the public interface used for authentication workflows. +type Authenticator interface { + CheckResourceAccess(User, string) bool + CheckGroupAccess(User, string) bool + CheckAuthenticated(User) bool + GetUserFromRequest(UserManager, *http.Request) (User, error) +} + +// UserManager sets and gets user tokens for implemented +// authentication mechanisms, and provides the data that is sent by +// the api and ui server after authenticating +// +// Note: this is the UserManager interface from Evergreen, without +// modification. +type UserManager interface { + GetUserByToken(token string) (User, error) + CreateUserToken(username, password string) (string, error) + // GetLoginHandler returns the function that starts the login process for auth mechanisms + // that redirect to a thirdparty site for authentication + GetLoginHandler(url string) func(http.ResponseWriter, *http.Request) + // GetLoginRedirectHandler returns the function that does login for the + // user once it has been redirected from a thirdparty site. + GetLoginCallbackHandler() func(http.ResponseWriter, *http.Request) + // IsRedirect returns true if the user must be redirected to a thirdparty site to authenticate + IsRedirect() bool +} diff --git a/vendor/github.com/tychoish/gimlet/buildscripts/make-vendor.go b/vendor/github.com/evergreen-ci/gimlet/buildscripts/make-vendor.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/buildscripts/make-vendor.go rename to vendor/github.com/evergreen-ci/gimlet/buildscripts/make-vendor.go diff --git a/vendor/github.com/tychoish/gimlet/buildscripts/render-gopath.go b/vendor/github.com/evergreen-ci/gimlet/buildscripts/render-gopath.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/buildscripts/render-gopath.go rename to vendor/github.com/evergreen-ci/gimlet/buildscripts/render-gopath.go diff --git a/vendor/github.com/tychoish/gimlet/buildscripts/vendoring/vendoring.go b/vendor/github.com/evergreen-ci/gimlet/buildscripts/vendoring/vendoring.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/buildscripts/vendoring/vendoring.go rename to vendor/github.com/evergreen-ci/gimlet/buildscripts/vendoring/vendoring.go diff --git a/vendor/github.com/evergreen-ci/gimlet/counter.go b/vendor/github.com/evergreen-ci/gimlet/counter.go new file mode 100644 index 00000000..fab23c5a --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/counter.go @@ -0,0 +1,43 @@ +package gimlet + +import ( + "context" + "net/http" +) + +var jobIDSource <-chan int + +func init() { + jobIDSource = func() <-chan int { + out := make(chan int, 50) + go func() { + var jobID int + for { + jobID++ + out <- jobID + } + }() + return out + }() +} + +// getNumber is a source of safe monotonically increasing integers +// for use in request ids. +func getNumber() int { + return <-jobIDSource +} + +func setRequestID(r *http.Request, id int) *http.Request { + return r.WithContext(context.WithValue(r.Context(), requestIDKey, id)) +} + +// GetRequestID returns the unique (monotonically increaseing) ID of +func GetRequestID(ctx context.Context) int { + if rv := ctx.Value(requestIDKey); rv != nil { + if id, ok := rv.(int); ok { + return id + } + } + + return -1 +} diff --git a/vendor/github.com/tychoish/gimlet/counter_test.go b/vendor/github.com/evergreen-ci/gimlet/counter_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/counter_test.go rename to vendor/github.com/evergreen-ci/gimlet/counter_test.go diff --git a/vendor/github.com/tychoish/gimlet/framework.go b/vendor/github.com/evergreen-ci/gimlet/framework.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework.go rename to vendor/github.com/evergreen-ci/gimlet/framework.go diff --git a/vendor/github.com/tychoish/gimlet/framework_pagination.go b/vendor/github.com/evergreen-ci/gimlet/framework_pagination.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework_pagination.go rename to vendor/github.com/evergreen-ci/gimlet/framework_pagination.go diff --git a/vendor/github.com/tychoish/gimlet/framework_pagination_test.go b/vendor/github.com/evergreen-ci/gimlet/framework_pagination_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework_pagination_test.go rename to vendor/github.com/evergreen-ci/gimlet/framework_pagination_test.go diff --git a/vendor/github.com/tychoish/gimlet/framework_response.go b/vendor/github.com/evergreen-ci/gimlet/framework_response.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework_response.go rename to vendor/github.com/evergreen-ci/gimlet/framework_response.go diff --git a/vendor/github.com/tychoish/gimlet/framework_response_test.go b/vendor/github.com/evergreen-ci/gimlet/framework_response_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework_response_test.go rename to vendor/github.com/evergreen-ci/gimlet/framework_response_test.go diff --git a/vendor/github.com/tychoish/gimlet/framework_test.go b/vendor/github.com/evergreen-ci/gimlet/framework_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/framework_test.go rename to vendor/github.com/evergreen-ci/gimlet/framework_test.go diff --git a/vendor/github.com/tychoish/gimlet/glide.lock b/vendor/github.com/evergreen-ci/gimlet/glide.lock similarity index 92% rename from vendor/github.com/tychoish/gimlet/glide.lock rename to vendor/github.com/evergreen-ci/gimlet/glide.lock index cea5f4e8..7a82b98d 100644 --- a/vendor/github.com/tychoish/gimlet/glide.lock +++ b/vendor/github.com/evergreen-ci/gimlet/glide.lock @@ -10,7 +10,7 @@ imports: subpackages: - gzip - name: github.com/mongodb/grip - version: 168c214db61f61bf79d8de25c4803e569b6c5902 + version: e5e74ee9128f8b676043365ad14944e5b046d251 - name: github.com/urfave/negroni version: 3444e69ea1ef03a77998d11fc56e7f0a34f7213c diff --git a/vendor/github.com/tychoish/gimlet/glide.yaml b/vendor/github.com/evergreen-ci/gimlet/glide.yaml similarity index 84% rename from vendor/github.com/tychoish/gimlet/glide.yaml rename to vendor/github.com/evergreen-ci/gimlet/glide.yaml index d228996d..2083173f 100644 --- a/vendor/github.com/tychoish/gimlet/glide.yaml +++ b/vendor/github.com/evergreen-ci/gimlet/glide.yaml @@ -1,4 +1,4 @@ -package: github.com/tychoish/gimlet +package: github.com/evergreen-ci/gimlet import: - package: github.com/codegangsta/negroni - package: github.com/gorilla/mux diff --git a/vendor/github.com/tychoish/gimlet/handling.go b/vendor/github.com/evergreen-ci/gimlet/handling.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling.go rename to vendor/github.com/evergreen-ci/gimlet/handling.go diff --git a/vendor/github.com/tychoish/gimlet/handling_binary.go b/vendor/github.com/evergreen-ci/gimlet/handling_binary.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_binary.go rename to vendor/github.com/evergreen-ci/gimlet/handling_binary.go diff --git a/vendor/github.com/tychoish/gimlet/handling_html.go b/vendor/github.com/evergreen-ci/gimlet/handling_html.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_html.go rename to vendor/github.com/evergreen-ci/gimlet/handling_html.go diff --git a/vendor/github.com/tychoish/gimlet/handling_json.go b/vendor/github.com/evergreen-ci/gimlet/handling_json.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_json.go rename to vendor/github.com/evergreen-ci/gimlet/handling_json.go diff --git a/vendor/github.com/tychoish/gimlet/handling_test.go b/vendor/github.com/evergreen-ci/gimlet/handling_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_test.go rename to vendor/github.com/evergreen-ci/gimlet/handling_test.go diff --git a/vendor/github.com/tychoish/gimlet/handling_text.go b/vendor/github.com/evergreen-ci/gimlet/handling_text.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_text.go rename to vendor/github.com/evergreen-ci/gimlet/handling_text.go diff --git a/vendor/github.com/tychoish/gimlet/handling_yaml.go b/vendor/github.com/evergreen-ci/gimlet/handling_yaml.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/handling_yaml.go rename to vendor/github.com/evergreen-ci/gimlet/handling_yaml.go diff --git a/vendor/github.com/tychoish/gimlet/makefile b/vendor/github.com/evergreen-ci/gimlet/makefile similarity index 99% rename from vendor/github.com/tychoish/gimlet/makefile rename to vendor/github.com/evergreen-ci/gimlet/makefile index debee9a9..fabf22ad 100644 --- a/vendor/github.com/tychoish/gimlet/makefile +++ b/vendor/github.com/evergreen-ci/gimlet/makefile @@ -2,7 +2,7 @@ name := gimlet buildDir := build packages := $(name) -orgPath := github.com/tychoish +orgPath := github.com/evergreen-ci projectPath := $(orgPath)/$(name) # end project configuration diff --git a/vendor/github.com/tychoish/gimlet/methods.go b/vendor/github.com/evergreen-ci/gimlet/methods.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/methods.go rename to vendor/github.com/evergreen-ci/gimlet/methods.go diff --git a/vendor/github.com/tychoish/gimlet/methods_test.go b/vendor/github.com/evergreen-ci/gimlet/methods_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/methods_test.go rename to vendor/github.com/evergreen-ci/gimlet/methods_test.go diff --git a/vendor/github.com/evergreen-ci/gimlet/middleware_auth.go b/vendor/github.com/evergreen-ci/gimlet/middleware_auth.go new file mode 100644 index 00000000..9ae849bf --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/middleware_auth.go @@ -0,0 +1,177 @@ +package gimlet + +import ( + "context" + "net/http" + + "github.com/evergreen-ci/gimlet/auth" + "github.com/mongodb/grip" + "github.com/mongodb/grip/message" + "github.com/urfave/negroni" +) + +type contextKey int + +const ( + authHandlerKey contextKey = iota + userManagerKey + requestIDKey + loggerKey + startAtKey +) + +func GetAuthenticator(ctx context.Context) auth.Authenticator { + a, ok := safeGetAuthenticator(ctx) + if !ok { + panic("authenticator not attached") + } + + return a +} + +func safeGetAuthenticator(ctx context.Context) (auth.Authenticator, bool) { + a := ctx.Value(authHandlerKey) + if a == nil { + return nil, false + } + + amgr, ok := a.(auth.Authenticator) + if !ok { + return nil, false + } + + return amgr, true +} + +func GetUserManager(ctx context.Context) auth.UserManager { + m, ok := safeGetUserManager(ctx) + if !ok { + panic("user manager not attached") + } + return m +} + +func safeGetUserManager(ctx context.Context) (auth.UserManager, bool) { + m := ctx.Value(userManagerKey) + if m == nil { + return nil, false + } + + umgr, ok := m.(auth.UserManager) + if !ok { + return nil, false + } + + return umgr, true +} + +// NewAuthenticationHandler produces middleware that attaches +// Authenticator and UserManager instances to the request context, +// enabling the use of GetAuthenticator and GetUserManager accessors. +// +// While your application can have multiple authentication mechanisms, +// a single request can only have one authentication provider +// associated with it. +func NewAuthenticationHandler(a auth.Provider) negroni.Handler { + return &authHandler{provider: a} +} + +type authHandler struct { + provider auth.Provider +} + +func (a *authHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + ctx := r.Context() + ctx = context.WithValue(ctx, authHandlerKey, a.provider.Authenticator()) + ctx = context.WithValue(ctx, userManagerKey, a.provider.UserManager()) + + r = r.WithContext(ctx) + next(rw, r) +} + +// NewAccessRequirement provides middlesware that requires a specific role to access a resource. +func NewAccessRequirement(role string) negroni.Handler { return &requiredAccess{role: role} } + +type requiredAccess struct { + role string +} + +func (ra *requiredAccess) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + ctx := r.Context() + + authenticator, ok := safeGetAuthenticator(ctx) + if !ok { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + userMgr, ok := safeGetUserManager(ctx) + if !ok { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + user, err := authenticator.GetUserFromRequest(userMgr, r) + if err != nil { + writeResponse(TEXT, rw, http.StatusUnauthorized, []byte(err.Error())) + } + + if !authenticator.CheckGroupAccess(user, ra.role) { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + grip.Info(message.Fields{ + "path": r.URL.Path, + "remote": r.RemoteAddr, + "request": GetRequestID(ctx), + "user": user.Username(), + "user_roles": user.Roles(), + "required_roles": ra.role, + }) + + next(rw, r) +} + +// NewRequireAuth provides middlesware that requires that users be +// authenticated generally to access the resource, but does no +// validation of their access. +func NewRequireAuthHandler() negroni.Handler { return &requireAuthHandler{} } + +type requireAuthHandler struct{} + +func (_ *requireAuthHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + ctx := r.Context() + + authenticator, ok := safeGetAuthenticator(ctx) + if !ok { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + userMgr, ok := safeGetUserManager(ctx) + if !ok { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + user, err := authenticator.GetUserFromRequest(userMgr, r) + if err != nil { + writeResponse(TEXT, rw, http.StatusUnauthorized, []byte(err.Error())) + } + + if !authenticator.CheckAuthenticated(user) { + rw.WriteHeader(http.StatusUnauthorized) + return + } + + grip.Info(message.Fields{ + "path": r.URL.Path, + "remote": r.RemoteAddr, + "request": GetRequestID(ctx), + "user": user.Username(), + "user_roles": user.Roles(), + }) + + next(rw, r) +} diff --git a/vendor/github.com/evergreen-ci/gimlet/middleware_auth_test.go b/vendor/github.com/evergreen-ci/gimlet/middleware_auth_test.go new file mode 100644 index 00000000..bcbe9e71 --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/middleware_auth_test.go @@ -0,0 +1,33 @@ +package gimlet + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMiddlewareValueAccessors(t *testing.T) { + assert := assert.New(t) + ctx := context.Background() + + auth, ok := safeGetAuthenticator(ctx) + assert.False(ok) + assert.Nil(auth) + assert.Panics(func() { auth = GetAuthenticator(ctx) }) + assert.Nil(auth) + + userm, ok := safeGetUserManager(ctx) + assert.False(ok) + assert.Nil(userm) + assert.Panics(func() { userm = GetUserManager(ctx) }) + assert.Nil(userm) + + var idone, idtwo int + idone = getNumber() + assert.Equal(0, idtwo) + assert.True(idone > 0) + assert.NotPanics(func() { idtwo = GetRequestID(ctx) }) + assert.True(idone > idtwo) + assert.Equal(-1, idtwo) +} diff --git a/vendor/github.com/evergreen-ci/gimlet/middleware_grip.go b/vendor/github.com/evergreen-ci/gimlet/middleware_grip.go new file mode 100644 index 00000000..1fdc2d7c --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/middleware_grip.go @@ -0,0 +1,145 @@ +package gimlet + +import ( + "context" + "net/http" + "time" + + "github.com/mongodb/grip" + "github.com/mongodb/grip/logging" + "github.com/mongodb/grip/message" + "github.com/urfave/negroni" +) + +const ( + remoteAddrHeaderName = "X-Cluster-Client-Ip" +) + +// appLogging provides a Negroni-compatible middleware to send all +// logging using the grip packages logging. This defaults to using +// systemd logging, but gracefully falls back to use go standard +// library logging, with some additional helpers and configurations to +// support configurable level-based logging. This particular +// middlewear resembles the basic tracking provided by Negroni's +// standard logging system. +type appLogging struct { + grip.Journaler +} + +// NewAppLogger creates an logging middlear instance suitable for use +// with Negroni. Sets the logging configuration to be the same as the +// default global grip logging object. +func NewAppLogger() negroni.Handler { return &appLogging{logging.MakeGrip(grip.GetSender())} } + +func setServiceLogger(r *http.Request, logger grip.Journaler) *http.Request { + return r.WithContext(context.WithValue(r.Context(), loggerKey, logger)) +} + +func setStartAtTime(r *http.Request, startAt time.Time) *http.Request { + return r.WithContext(context.WithValue(r.Context(), startAtKey, startAt)) +} + +func getRequestStartAt(ctx context.Context) time.Time { + if rv := ctx.Value(startAtKey); rv != nil { + if t, ok := rv.(time.Time); ok { + return t + } + } + + return time.Time{} +} + +func GetLogger(ctx context.Context) grip.Journaler { + if rv := ctx.Value(loggerKey); rv != nil { + if l, ok := rv.(grip.Journaler); ok { + return l + } + } + + return logging.MakeGrip(grip.GetSender()) +} + +// Logs the request path, the beginning of every request as well as +// the duration upon completion and the status of the response. +func (l *appLogging) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + r = setupLogger(l.Journaler, r) + + next(rw, r) + res := rw.(negroni.ResponseWriter) + finishLogger(l.Journaler, r, res) +} + +func setupLogger(logger grip.Journaler, r *http.Request) *http.Request { + r = setServiceLogger(r, logger) + remote := r.Header.Get(remoteAddrHeaderName) + if remote == "" { + r.RemoteAddr = remote + } + + id := getNumber() + r = setRequestID(r, id) + startAt := time.Now() + r = setStartAtTime(r, startAt) + + logger.Info(message.Fields{ + "action": "started", + "method": r.Method, + "remote": r.RemoteAddr, + "request": id, + "path": r.URL.Path, + }) + + return r +} + +func finishLogger(logger grip.Journaler, r *http.Request, res negroni.ResponseWriter) { + ctx := r.Context() + startAt := getRequestStartAt(ctx) + dur := time.Since(startAt) + + logger.Info(message.Fields{ + "method": r.Method, + "remote": r.RemoteAddr, + "request": GetRequestID(ctx), + "path": r.URL.Path, + "duration_ms": int64(dur / time.Millisecond), + "action": "completed", + "status": res.Status(), + "outcome": http.StatusText(res.Status()), + }) +} + +// This is largely duplicated from the above, but lets us optionally +type appRecoveryLogger struct { + grip.Journaler +} + +func NewRecoveryLogger() negroni.Handler { return &appRecoveryLogger{} } + +func (l *appRecoveryLogger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + r = setupLogger(l.Journaler, r) + ctx := r.Context() + + defer func() { + if err := recover(); err != nil { + if rw.Header().Get("Content-Type") == "" { + rw.Header().Set("Content-Type", "text/plain; charset=utf-8") + } + + rw.WriteHeader(http.StatusInternalServerError) + + l.Critical(message.WrapStack(2, message.Fields{ + "panic": err, + "action": "aborted", + "request": GetRequestID(ctx), + "path": r.URL.Path, + "remote": r.RemoteAddr, + })) + } + }() + + next(rw, r) + + res := rw.(negroni.ResponseWriter) + finishLogger(l.Journaler, r, res) +} diff --git a/vendor/github.com/evergreen-ci/gimlet/middleware_grip_test.go b/vendor/github.com/evergreen-ci/gimlet/middleware_grip_test.go new file mode 100644 index 00000000..737ac059 --- /dev/null +++ b/vendor/github.com/evergreen-ci/gimlet/middleware_grip_test.go @@ -0,0 +1,123 @@ +package gimlet + +import ( + "context" + "net/http" + "net/http/httptest" + "net/url" + "testing" + "time" + + "github.com/mongodb/grip" + "github.com/mongodb/grip/logging" + "github.com/mongodb/grip/send" + "github.com/stretchr/testify/assert" + "github.com/urfave/negroni" +) + +func TestReqestLogger(t *testing.T) { + assert := assert.New(t) + + sender, err := send.NewInternalLogger("test", grip.GetSender().Level()) + assert.NoError(err) + middlewear := NewAppLogger().(*appLogging) + middlewear.Journaler = logging.MakeGrip(sender) + + next := func(w http.ResponseWriter, r *http.Request) { + middlewear.Journaler.Info("hello") + } + assert.False(sender.HasMessage()) + req := &http.Request{ + URL: &url.URL{}, + } + rw := negroni.NewResponseWriter(nil) + + startAt := getNumber() + middlewear.ServeHTTP(rw, req, next) + assert.Equal(startAt+2, getNumber()) + assert.True(sender.HasMessage()) + assert.Equal(sender.Len(), 3) +} + +func TestReqestPanicLogger(t *testing.T) { + assert := assert.New(t) + + sender, err := send.NewInternalLogger("test", grip.GetSender().Level()) + assert.NoError(err) + middlewear := NewRecoveryLogger().(*appRecoveryLogger) + middlewear.Journaler = logging.MakeGrip(sender) + + next := func(w http.ResponseWriter, r *http.Request) { + middlewear.Journaler.Info("hello") + } + assert.False(sender.HasMessage()) + req := &http.Request{ + URL: &url.URL{}, + } + rw := negroni.NewResponseWriter(nil) + + startAt := getNumber() + middlewear.ServeHTTP(rw, req, next) + assert.Equal(startAt+2, getNumber()) + assert.True(sender.HasMessage()) + assert.Equal(sender.Len(), 3) +} + +func TestReqestPanicLoggerWithPanic(t *testing.T) { + assert := assert.New(t) + + sender, err := send.NewInternalLogger("test", grip.GetSender().Level()) + assert.NoError(err) + middlewear := NewRecoveryLogger().(*appRecoveryLogger) + middlewear.Journaler = logging.MakeGrip(sender) + + next := func(w http.ResponseWriter, r *http.Request) { + panic("oops") + } + assert.False(sender.HasMessage()) + req := &http.Request{ + URL: &url.URL{}, + Header: http.Header{}, + } + testrw := httptest.NewRecorder() + rw := negroni.NewResponseWriter(testrw) + + startAt := getNumber() + middlewear.ServeHTTP(rw, req, next) + + assert.Equal(startAt+2, getNumber()) + assert.True(sender.HasMessage()) + assert.Equal(sender.Len(), 2) +} + +func TestDefaultGripMiddlwareSetters(t *testing.T) { + assert := assert.New(t) + r := &http.Request{ + URL: &url.URL{Path: "foo"}, + } + r = r.WithContext(context.Background()) + ctx := r.Context() + + var l grip.Journaler + assert.NotPanics(func() { l = GetLogger(ctx) }) + assert.NotNil(l) + assert.Equal(l.GetSender(), grip.GetSender()) + + now := time.Now() + logger := logging.MakeGrip(send.MakeInternalLogger()) + + assert.NotEqual(logger, GetLogger(ctx)) + assert.Zero(getRequestStartAt(ctx)) + + r = setupLogger(l, r) + ctx = r.Context() + + assert.Equal(l, GetLogger(ctx)) + + id := GetRequestID(ctx) + + assert.True(id > 0, "%d", id) + assert.NotZero(getRequestStartAt(ctx)) + assert.True(now.Before(getRequestStartAt(ctx))) + +} diff --git a/vendor/github.com/tychoish/gimlet/parsing.go b/vendor/github.com/evergreen-ci/gimlet/parsing.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/parsing.go rename to vendor/github.com/evergreen-ci/gimlet/parsing.go diff --git a/vendor/github.com/tychoish/gimlet/parsing_test.go b/vendor/github.com/evergreen-ci/gimlet/parsing_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/parsing_test.go rename to vendor/github.com/evergreen-ci/gimlet/parsing_test.go diff --git a/vendor/github.com/tychoish/gimlet/routing.go b/vendor/github.com/evergreen-ci/gimlet/routing.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/routing.go rename to vendor/github.com/evergreen-ci/gimlet/routing.go diff --git a/vendor/github.com/tychoish/gimlet/routing_test.go b/vendor/github.com/evergreen-ci/gimlet/routing_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/routing_test.go rename to vendor/github.com/evergreen-ci/gimlet/routing_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/.travis.yml b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/.travis.yml similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/.travis.yml rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/.travis.yml diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/LICENSE b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/LICENSE similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/LICENSE rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/LICENSE diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/README.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/README.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/README.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/README.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/context.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/context.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/context.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/context.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/context_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/context_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/context_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/context_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/doc.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/doc.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/context/doc.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/context/doc.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/.travis.yml b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/.travis.yml similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/.travis.yml rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/.travis.yml diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/LICENSE b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/LICENSE similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/LICENSE rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/LICENSE diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/README.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/README.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/README.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/README.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/bench_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/bench_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/bench_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/bench_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_gorilla.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_gorilla.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_gorilla.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_gorilla.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_gorilla_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_gorilla_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_gorilla_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_gorilla_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_native.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_native.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_native.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_native.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_native_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_native_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/context_native_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/context_native_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/doc.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/doc.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/doc.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/doc.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/mux.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/mux.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/mux.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/mux.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/mux_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/mux_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/mux_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/mux_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/old_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/old_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/old_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/old_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/regexp.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/regexp.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/regexp.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/regexp.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/route.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/route.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/gorilla/mux/route.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/gorilla/mux/route.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/.gitignore b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/.gitignore similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/.gitignore rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/.gitignore diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/LICENSE b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/LICENSE similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/LICENSE rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/LICENSE diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/Makefile b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/Makefile similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/Makefile rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/Makefile diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/README.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/README.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/README.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/README.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/phyber/negroni-gzip/gzip/gzip_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/.gitignore b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/.gitignore similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/.gitignore rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/.gitignore diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/.travis.yml b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/.travis.yml similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/.travis.yml rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/.travis.yml diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/CHANGELOG.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/CHANGELOG.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/CHANGELOG.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/CHANGELOG.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/LICENSE b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/LICENSE similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/LICENSE rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/LICENSE diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/README.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/README.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/README.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/README.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/doc.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/doc.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/doc.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/doc.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/logger.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/logger.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/logger.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/logger.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/logger_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/logger_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/logger_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/logger_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/negroni.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/negroni.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/negroni.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/negroni.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/negroni_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/negroni_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/negroni_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/negroni_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/recovery.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/recovery.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/recovery.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/recovery.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/recovery_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/recovery_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/recovery_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/recovery_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_pusher_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/response_writer_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/response_writer_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/static.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/static.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/static.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/static.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/static_test.go b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/static_test.go similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/static_test.go rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/static_test.go diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_de_de.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_de_de.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_de_de.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_de_de.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_ja_JP.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_ja_JP.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_ja_JP.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_ja_JP.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_pt_br.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_pt_br.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_pt_br.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_pt_br.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_cn.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_cn.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_cn.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_cn.md diff --git a/vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_tw.md b/vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_tw.md similarity index 100% rename from vendor/github.com/tychoish/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_tw.md rename to vendor/github.com/evergreen-ci/gimlet/vendor/github.com/urfave/negroni/translations/README_zh_tw.md diff --git a/vendor/github.com/tychoish/gimlet/counter.go b/vendor/github.com/tychoish/gimlet/counter.go deleted file mode 100644 index c2863bc9..00000000 --- a/vendor/github.com/tychoish/gimlet/counter.go +++ /dev/null @@ -1,23 +0,0 @@ -package gimlet - -var jobIDSource <-chan int - -func init() { - jobIDSource = func() <-chan int { - out := make(chan int, 50) - go func() { - var jobID int - for { - jobID++ - out <- jobID - } - }() - return out - }() -} - -// getNumber is a source of safe monotonically increasing integers -// for use in request ids. -func getNumber() int { - return <-jobIDSource -} diff --git a/vendor/github.com/tychoish/gimlet/middleware_grip.go b/vendor/github.com/tychoish/gimlet/middleware_grip.go deleted file mode 100644 index 6518f2e5..00000000 --- a/vendor/github.com/tychoish/gimlet/middleware_grip.go +++ /dev/null @@ -1,57 +0,0 @@ -package gimlet - -import ( - "net/http" - "time" - - "github.com/mongodb/grip" - "github.com/mongodb/grip/logging" - "github.com/mongodb/grip/message" - "github.com/urfave/negroni" -) - -// AppLogging provides a Negroni-compatible middleware to send all -// logging using the grip packages logging. This defaults to using -// systemd logging, but gracefully falls back to use go standard -// library logging, with some additional helpers and configurations to -// support configurable level-based logging. This particular -// middlewear resembles the basic tracking provided by Negroni's -// standard logging system. -type appLogging struct { - grip.Journaler -} - -// NewAppLogger creates an logging middlear instance suitable for use -// with Negroni. Sets the logging configuration to be the same as the -// default global grip logging object. -func NewAppLogger() negroni.Handler { return &appLogging{logging.MakeGrip(grip.GetSender())} } - -// Logs the request path, the beginning of every request as well as -// the duration upon completion and the status of the response. -func (l *appLogging) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - start := time.Now() - id := getNumber() - - l.Info(message.Fields{ - "action": "started", - "method": r.Method, - "remote": r.RemoteAddr, - "request": id, - "path": r.URL.Path, - }) - - next(rw, r) - - res := rw.(negroni.ResponseWriter) - l.Info(message.Fields{ - "method": r.Method, - "remote": r.RemoteAddr, - "request": id, - "path": r.URL.Path, - "duration": time.Since(start), - "action": "completed", - "status": res.Status(), - "outcome": http.StatusText(res.Status()), - "span": time.Since(start).String(), - }) -} diff --git a/vendor/github.com/tychoish/gimlet/middleware_grip_test.go b/vendor/github.com/tychoish/gimlet/middleware_grip_test.go deleted file mode 100644 index 636f4821..00000000 --- a/vendor/github.com/tychoish/gimlet/middleware_grip_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package gimlet - -import ( - "net/http" - "net/url" - "testing" - - "github.com/mongodb/grip" - "github.com/mongodb/grip/logging" - "github.com/mongodb/grip/send" - "github.com/stretchr/testify/assert" - "github.com/urfave/negroni" -) - -func TestReqestLogger(t *testing.T) { - assert := assert.New(t) - - sender, err := send.NewInternalLogger("test", grip.GetSender().Level()) - assert.NoError(err) - middlewear := &AppLogging{ - Journaler: logging.MakeGrip(sender), - } - - next := func(w http.ResponseWriter, r *http.Request) { - middlewear.Journaler.Info("hello") - } - assert.False(sender.HasMessage()) - req := &http.Request{ - URL: &url.URL{}, - } - rw := negroni.NewResponseWriter(nil) - - startAt := getNumber() - middlewear.ServeHTTP(rw, req, next) - assert.Equal(startAt+2, getNumber()) - assert.True(sender.HasMessage()) - assert.Equal(sender.Len(), 3) -}