diff --git a/cli/serve.go b/cli/serve.go index 1da317243..052f65016 100644 --- a/cli/serve.go +++ b/cli/serve.go @@ -45,7 +45,6 @@ binary (which you're executing right now). Use the options below to customize the way that the kolide server works. `, Run: func(cmd *cobra.Command, args []string) { - ctx := context.Background() config := configManager.LoadConfig() var logger kitlog.Logger @@ -56,7 +55,7 @@ the way that the kolide server works. } else { logger = kitlog.NewLogfmtLogger(output) } - logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC) + logger = kitlog.With(logger, "ts", kitlog.DefaultTimestampUTC) } var ds kolide.Datastore @@ -143,16 +142,16 @@ the way that the kolide server works. Help: "Total duration of requests in microseconds.", }, fieldKeys) - svcLogger := kitlog.NewContext(logger).With("component", "service") + svcLogger := kitlog.With(logger, "component", "service") svc = service.NewLoggingService(svc, svcLogger) svc = service.NewMetricsService(svc, requestCount, requestLatency) - httpLogger := kitlog.NewContext(logger).With("component", "http") + httpLogger := kitlog.With(logger, "component", "http") var apiHandler, frontendHandler http.Handler { frontendHandler = prometheus.InstrumentHandler("get_frontend", service.ServeFrontend(httpLogger)) - apiHandler = service.MakeHandler(ctx, svc, config.Auth.JwtKey, httpLogger) + apiHandler = service.MakeHandler(svc, config.Auth.JwtKey, httpLogger) setupRequired, err := service.RequireSetup(svc) if err != nil { @@ -229,7 +228,7 @@ the way that the kolide server works. sig := make(chan os.Signal) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) <-sig //block on signal - ctx, _ = context.WithTimeout(context.Background(), 30*time.Second) + ctx, _ := context.WithTimeout(context.Background(), 30*time.Second) errs <- srv.Shutdown(ctx) }() diff --git a/glide.lock b/glide.lock index 64783c2bf..4285dc34e 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: c1bacfac1e43a7b6cb050afc246e21a426e9781fac4146df1d5571d5c28c4d90 -updated: 2017-03-08T09:05:13.458507954-08:00 +hash: f3cd6c2e30f6c19975df5373a3fd6132d5672273718275c6ecf4dfbe4993b149 +updated: 2017-03-14T10:36:42.833374871-07:00 imports: - name: github.com/alecthomas/template version: a0175ee3bccc567396460bf5acd36800cb10c49c @@ -27,7 +27,7 @@ imports: - internal - redis - name: github.com/go-kit/kit - version: f66b0e13579bfc5a48b9e2a94b1209c107ea1f41 + version: fadad6fffe0466b19df9efd9acde5c9a52df5fa4 subpackages: - endpoint - log diff --git a/glide.yaml b/glide.yaml index 34cb949a3..4e68428e0 100644 --- a/glide.yaml +++ b/glide.yaml @@ -64,7 +64,7 @@ import: - package: github.com/VividCortex/mysqlerr version: master - package: github.com/go-kit/kit - version: ~0.3.0 + version: ~0.4.0 - package: github.com/go-yaml/yaml - package: github.com/ryanuber/go-license - package: github.com/igm/sockjs-go diff --git a/server/contexts/host/host.go b/server/contexts/host/host.go index 048d2bb37..4e5f11ad7 100644 --- a/server/contexts/host/host.go +++ b/server/contexts/host/host.go @@ -3,8 +3,9 @@ package host import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type key int diff --git a/server/contexts/token/token.go b/server/contexts/token/token.go index 1725501e9..e778caa1a 100644 --- a/server/contexts/token/token.go +++ b/server/contexts/token/token.go @@ -3,10 +3,9 @@ package token import ( + "context" "net/http" "strings" - - "golang.org/x/net/context" ) type key int diff --git a/server/contexts/viewer/viewer.go b/server/contexts/viewer/viewer.go index 637e3bf24..dc35ca8ce 100644 --- a/server/contexts/viewer/viewer.go +++ b/server/contexts/viewer/viewer.go @@ -3,8 +3,9 @@ package viewer import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type key int diff --git a/server/kolide/app.go b/server/kolide/app.go index 07b8d2d4b..7c5655352 100644 --- a/server/kolide/app.go +++ b/server/kolide/app.go @@ -1,7 +1,7 @@ package kolide import ( - "golang.org/x/net/context" + "context" ) // AppConfigStore contains method for saving and retrieving diff --git a/server/kolide/campaigns.go b/server/kolide/campaigns.go index a1b0a33dd..be5b4693d 100644 --- a/server/kolide/campaigns.go +++ b/server/kolide/campaigns.go @@ -1,10 +1,10 @@ package kolide import ( + "context" "time" "github.com/kolide/kolide/server/websocket" - "golang.org/x/net/context" ) // CampaignStore defines the distributed query campaign related datastore diff --git a/server/kolide/hosts.go b/server/kolide/hosts.go index a42f75585..5aa8d724f 100644 --- a/server/kolide/hosts.go +++ b/server/kolide/hosts.go @@ -1,11 +1,10 @@ package kolide import ( + "context" "crypto/rand" "encoding/base64" "time" - - "golang.org/x/net/context" ) const ( diff --git a/server/kolide/import_config.go b/server/kolide/import_config.go index 3b551cb8c..34a3ba8e7 100644 --- a/server/kolide/import_config.go +++ b/server/kolide/import_config.go @@ -1,11 +1,10 @@ package kolide import ( + "context" "errors" "fmt" "strings" - - "golang.org/x/net/context" ) type ImportConfigService interface { diff --git a/server/kolide/invites.go b/server/kolide/invites.go index 7aaac2227..eada1f1d9 100644 --- a/server/kolide/invites.go +++ b/server/kolide/invites.go @@ -2,9 +2,8 @@ package kolide import ( "bytes" + "context" "html/template" - - "golang.org/x/net/context" ) // InviteStore contains the methods for diff --git a/server/kolide/labels.go b/server/kolide/labels.go index 00a2727ab..5052033b2 100644 --- a/server/kolide/labels.go +++ b/server/kolide/labels.go @@ -1,9 +1,8 @@ package kolide import ( + "context" "time" - - "golang.org/x/net/context" ) type LabelStore interface { diff --git a/server/kolide/licenses.go b/server/kolide/licenses.go index 95e558c1e..bf627df4f 100644 --- a/server/kolide/licenses.go +++ b/server/kolide/licenses.go @@ -1,12 +1,12 @@ package kolide import ( + "context" "fmt" "time" "github.com/dgrijalva/jwt-go" "github.com/pkg/errors" - "golang.org/x/net/context" ) const ( diff --git a/server/kolide/options.go b/server/kolide/options.go index 6f6eb1ccf..bd12bfba2 100644 --- a/server/kolide/options.go +++ b/server/kolide/options.go @@ -1,13 +1,12 @@ package kolide import ( + "context" "database/sql/driver" "encoding/json" "fmt" "strings" "time" - - "golang.org/x/net/context" ) // OptionStore interface describes methods to access datastore diff --git a/server/kolide/osquery.go b/server/kolide/osquery.go index e26b2c25c..7d6802ec4 100644 --- a/server/kolide/osquery.go +++ b/server/kolide/osquery.go @@ -1,6 +1,8 @@ package kolide -import "golang.org/x/net/context" +import ( + "context" +) type OsqueryService interface { EnrollAgent(ctx context.Context, enrollSecret, hostIdentifier string) (nodeKey string, err error) diff --git a/server/kolide/packs.go b/server/kolide/packs.go index 8d41b361a..532806286 100644 --- a/server/kolide/packs.go +++ b/server/kolide/packs.go @@ -1,7 +1,7 @@ package kolide import ( - "golang.org/x/net/context" + "context" ) // PackStore is the datastore interface for managing query packs. diff --git a/server/kolide/queries.go b/server/kolide/queries.go index cd3082a25..db35bc354 100644 --- a/server/kolide/queries.go +++ b/server/kolide/queries.go @@ -1,6 +1,8 @@ package kolide -import "golang.org/x/net/context" +import ( + "context" +) type QueryStore interface { // NewQuery creates a new query object in thie datastore. The returned diff --git a/server/kolide/query_results.go b/server/kolide/query_results.go index 163d042f7..f4afc44b7 100644 --- a/server/kolide/query_results.go +++ b/server/kolide/query_results.go @@ -1,6 +1,8 @@ package kolide -import "golang.org/x/net/context" +import ( + "context" +) // QueryResultStore defines functions for sending and receiving distributed // query results over a pub/sub system. It is implemented by structs in package diff --git a/server/kolide/scheduled_queries.go b/server/kolide/scheduled_queries.go index cc876f1aa..282559cde 100644 --- a/server/kolide/scheduled_queries.go +++ b/server/kolide/scheduled_queries.go @@ -1,7 +1,7 @@ package kolide import ( - "golang.org/x/net/context" + "context" ) type ScheduledQueryStore interface { diff --git a/server/kolide/sessions.go b/server/kolide/sessions.go index 88a3cd33d..ef1c50afc 100644 --- a/server/kolide/sessions.go +++ b/server/kolide/sessions.go @@ -1,9 +1,8 @@ package kolide import ( + "context" "time" - - "golang.org/x/net/context" ) // SessionStore is the abstract interface that all session backends must diff --git a/server/kolide/targets.go b/server/kolide/targets.go index 2594c647f..3af2ce064 100644 --- a/server/kolide/targets.go +++ b/server/kolide/targets.go @@ -1,7 +1,7 @@ package kolide import ( - "golang.org/x/net/context" + "context" ) type TargetSearchResults struct { diff --git a/server/kolide/users.go b/server/kolide/users.go index 256d966e2..ae6572fc7 100644 --- a/server/kolide/users.go +++ b/server/kolide/users.go @@ -2,13 +2,13 @@ package kolide import ( "bytes" + "context" "crypto/rand" "encoding/base64" "fmt" "html/template" "golang.org/x/crypto/bcrypt" - "golang.org/x/net/context" ) // UserStore contains methods for managing users in a datastore diff --git a/server/license/checker.go b/server/license/checker.go index 29abc21f5..f1d139567 100644 --- a/server/license/checker.go +++ b/server/license/checker.go @@ -1,6 +1,7 @@ package license import ( + "context" "encoding/json" "fmt" "net/http" @@ -13,7 +14,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/kolide/kolide/server/version" "github.com/pkg/errors" - "golang.org/x/net/context" ) const ( @@ -99,7 +99,7 @@ func NewChecker(ds kolide.Datastore, licenseEndpointURL string, opts ...Option) o(response) } - response.logger = log.NewContext(response.logger).With("component", "license-checker") + response.logger = log.With(response.logger, "component", "license-checker") return response } diff --git a/server/license/checker_test.go b/server/license/checker_test.go index 82c0880e1..7ee6a5f0f 100644 --- a/server/license/checker_test.go +++ b/server/license/checker_test.go @@ -1,6 +1,7 @@ package license import ( + "context" "encoding/json" "fmt" "net/http" @@ -16,7 +17,6 @@ import ( "github.com/kolide/kolide/server/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) var tokenString = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjRkOmM1OmRlOmE1Oj" + diff --git a/server/pubsub/inmem_query_results.go b/server/pubsub/inmem_query_results.go index 0647fed41..985a940a7 100644 --- a/server/pubsub/inmem_query_results.go +++ b/server/pubsub/inmem_query_results.go @@ -1,11 +1,10 @@ package pubsub import ( + "context" "strconv" "sync" - "golang.org/x/net/context" - "github.com/kolide/kolide/server/kolide" ) diff --git a/server/pubsub/query_results_test.go b/server/pubsub/query_results_test.go index 15afffae9..c31e788d7 100644 --- a/server/pubsub/query_results_test.go +++ b/server/pubsub/query_results_test.go @@ -1,6 +1,7 @@ package pubsub import ( + "context" "fmt" "os" "reflect" @@ -13,7 +14,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) // waitTimeout waits for the waitgroup for the specified max timeout. diff --git a/server/pubsub/redis_query_results.go b/server/pubsub/redis_query_results.go index aadb11a3a..a35b5a70a 100644 --- a/server/pubsub/redis_query_results.go +++ b/server/pubsub/redis_query_results.go @@ -1,12 +1,11 @@ package pubsub import ( + "context" "encoding/json" "fmt" "time" - "golang.org/x/net/context" - "github.com/garyburd/redigo/redis" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" diff --git a/server/service/endpoint_appconfig.go b/server/service/endpoint_appconfig.go index 70b442aab..5463e63f6 100644 --- a/server/service/endpoint_appconfig.go +++ b/server/service/endpoint_appconfig.go @@ -1,12 +1,12 @@ package service import ( + "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type appConfigRequest struct { diff --git a/server/service/endpoint_campaigns.go b/server/service/endpoint_campaigns.go index 392343ada..17ebe8090 100644 --- a/server/service/endpoint_campaigns.go +++ b/server/service/endpoint_campaigns.go @@ -1,6 +1,7 @@ package service import ( + "context" "encoding/json" "net/http" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" "github.com/kolide/kolide/server/websocket" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_certificate.go b/server/service/endpoint_certificate.go index e204ca2b8..14e200cf7 100644 --- a/server/service/endpoint_certificate.go +++ b/server/service/endpoint_certificate.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type certificateResponse struct { diff --git a/server/service/endpoint_change_email.go b/server/service/endpoint_change_email.go index 8ee4442a8..dc98d1736 100644 --- a/server/service/endpoint_change_email.go +++ b/server/service/endpoint_change_email.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type changeEmailRequest struct { diff --git a/server/service/endpoint_hosts.go b/server/service/endpoint_hosts.go index daf1d8bd7..003bcd83d 100644 --- a/server/service/endpoint_hosts.go +++ b/server/service/endpoint_hosts.go @@ -1,12 +1,12 @@ package service import ( + "context" "time" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) type hostResponse struct { diff --git a/server/service/endpoint_import_config.go b/server/service/endpoint_import_config.go index 792c0922a..45d88a094 100644 --- a/server/service/endpoint_import_config.go +++ b/server/service/endpoint_import_config.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type importRequest struct { diff --git a/server/service/endpoint_invites.go b/server/service/endpoint_invites.go index 9f2830e49..68f44a620 100644 --- a/server/service/endpoint_invites.go +++ b/server/service/endpoint_invites.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type createInviteRequest struct { diff --git a/server/service/endpoint_labels.go b/server/service/endpoint_labels.go index a52d07150..953eaa0c9 100644 --- a/server/service/endpoint_labels.go +++ b/server/service/endpoint_labels.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type getLabelRequest struct { diff --git a/server/service/endpoint_licenses.go b/server/service/endpoint_licenses.go index 53a2bd970..f304d0bd8 100644 --- a/server/service/endpoint_licenses.go +++ b/server/service/endpoint_licenses.go @@ -1,11 +1,11 @@ package service import ( + "context" "time" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type licenseRequest struct { diff --git a/server/service/endpoint_middleware.go b/server/service/endpoint_middleware.go index dc4904be5..e7864a647 100644 --- a/server/service/endpoint_middleware.go +++ b/server/service/endpoint_middleware.go @@ -1,6 +1,7 @@ package service import ( + "context" "errors" "fmt" "reflect" @@ -12,7 +13,6 @@ import ( "github.com/kolide/kolide/server/contexts/token" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) var errNoContext = errors.New("context key not set") diff --git a/server/service/endpoint_middleware_test.go b/server/service/endpoint_middleware_test.go index ec3e61ffe..18de93e4b 100644 --- a/server/service/endpoint_middleware_test.go +++ b/server/service/endpoint_middleware_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/go-kit/kit/endpoint" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) // TestEndpointPermissions tests that diff --git a/server/service/endpoint_options.go b/server/service/endpoint_options.go index 087241b68..a18984948 100644 --- a/server/service/endpoint_options.go +++ b/server/service/endpoint_options.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type optionsResponse struct { diff --git a/server/service/endpoint_osquery.go b/server/service/endpoint_osquery.go index d6efe2e46..3a8b4ff4d 100644 --- a/server/service/endpoint_osquery.go +++ b/server/service/endpoint_osquery.go @@ -1,11 +1,11 @@ package service import ( + "context" "encoding/json" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_packs.go b/server/service/endpoint_packs.go index c5adb149e..37f8a8582 100644 --- a/server/service/endpoint_packs.go +++ b/server/service/endpoint_packs.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type packResponse struct { diff --git a/server/service/endpoint_queries.go b/server/service/endpoint_queries.go index b4e15e97c..296eec16b 100644 --- a/server/service/endpoint_queries.go +++ b/server/service/endpoint_queries.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_scheduled_queries.go b/server/service/endpoint_scheduled_queries.go index 4961174e3..281bcbaf3 100644 --- a/server/service/endpoint_scheduled_queries.go +++ b/server/service/endpoint_scheduled_queries.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_sessions.go b/server/service/endpoint_sessions.go index 31975d892..940298909 100644 --- a/server/service/endpoint_sessions.go +++ b/server/service/endpoint_sessions.go @@ -1,11 +1,11 @@ package service import ( + "context" "time" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_setup.go b/server/service/endpoint_setup.go index 75b08e2c0..eb337cfb2 100644 --- a/server/service/endpoint_setup.go +++ b/server/service/endpoint_setup.go @@ -1,7 +1,7 @@ package service import ( - "golang.org/x/net/context" + "context" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" diff --git a/server/service/endpoint_targets.go b/server/service/endpoint_targets.go index 9e09b5f36..3d2b1a895 100644 --- a/server/service/endpoint_targets.go +++ b/server/service/endpoint_targets.go @@ -1,12 +1,12 @@ package service import ( + "context" "time" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_test.go b/server/service/endpoint_test.go index 782110930..9eca2a882 100644 --- a/server/service/endpoint_test.go +++ b/server/service/endpoint_test.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "encoding/json" "net/http" "net/http/httptest" @@ -12,13 +13,10 @@ import ( "testing" kitlog "github.com/go-kit/kit/log" - kithttp "github.com/go-kit/kit/transport/http" - "github.com/gorilla/mux" "github.com/kolide/kolide/server/config" "github.com/kolide/kolide/server/datastore/inmem" "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) type testResource struct { @@ -57,21 +55,11 @@ func setupEndpointTest(t *testing.T) *testResource { svc = endpointService{svc} createTestUsers(t, test.ds) logger := kitlog.NewLogfmtLogger(os.Stdout) - jwtKey := "CHANGEME" - opts := []kithttp.ServerOption{ - kithttp.ServerBefore(setRequestsContexts(svc, jwtKey)), - kithttp.ServerErrorLogger(logger), - kithttp.ServerAfter(kithttp.SetContentType("application/json; charset=utf-8")), - } - router := mux.NewRouter() - ke := MakeKolideServerEndpoints(svc, jwtKey) - ctxt := context.Background() - kh := makeKolideKitHandlers(ctxt, ke, opts) - attachKolideAPIRoutes(router, kh) + routes := MakeHandler(svc, jwtKey, logger) - test.server = httptest.NewServer(router) + test.server = httptest.NewServer(routes) userParam := loginRequest{ Username: "admin1", diff --git a/server/service/endpoint_users.go b/server/service/endpoint_users.go index cda5260c8..763734fad 100644 --- a/server/service/endpoint_users.go +++ b/server/service/endpoint_users.go @@ -1,11 +1,11 @@ package service import ( + "context" "net/http" "github.com/go-kit/kit/endpoint" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) //////////////////////////////////////////////////////////////////////////////// diff --git a/server/service/endpoint_users_test.go b/server/service/endpoint_users_test.go index 6a4f54eb1..ad13e640e 100644 --- a/server/service/endpoint_users_test.go +++ b/server/service/endpoint_users_test.go @@ -39,6 +39,7 @@ func testNonAdminUserSetAdmin(t *testing.T, r *testResource) { user, err := r.ds.User("user1") require.Nil(t, err) assert.False(t, user.Admin) + inJson := `{"admin":true}` buff := bytes.NewBufferString(inJson) path := fmt.Sprintf("/api/v1/kolide/users/%d/admin", user.ID) @@ -49,9 +50,8 @@ func testNonAdminUserSetAdmin(t *testing.T, r *testResource) { client := &http.Client{} resp, err := client.Do(req) require.Nil(t, err) - assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode) - rb := make([]byte, 500) - resp.Body.Read(rb) + assert.Equal(t, http.StatusForbidden, resp.StatusCode) + user, err = r.ds.User("user1") require.Nil(t, err) assert.False(t, user.Admin) @@ -85,6 +85,7 @@ func testNonAdminUserSetEnabled(t *testing.T, r *testResource) { user, err := r.ds.User("user1") require.Nil(t, err) assert.True(t, user.Enabled) + inJson := `{"enabled":false}` buff := bytes.NewBufferString(inJson) path := fmt.Sprintf("/api/v1/kolide/users/%d/enable", user.ID) @@ -95,9 +96,8 @@ func testNonAdminUserSetEnabled(t *testing.T, r *testResource) { client := &http.Client{} resp, err := client.Do(req) require.Nil(t, err) - assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode) - rb := make([]byte, 500) - resp.Body.Read(rb) + assert.Equal(t, http.StatusForbidden, resp.StatusCode) + user, err = r.ds.User("user1") require.Nil(t, err) // shouldn't change diff --git a/server/service/handler.go b/server/service/handler.go index 31b928a48..2c95bac2f 100644 --- a/server/service/handler.go +++ b/server/service/handler.go @@ -1,6 +1,7 @@ package service import ( + "context" "net/http" "strings" @@ -10,7 +11,6 @@ import ( "github.com/gorilla/mux" "github.com/kolide/kolide/server/kolide" "github.com/prometheus/client_golang/prometheus" - "golang.org/x/net/context" ) // KolideEndpoints is a collection of RPC endpoints implemented by the Kolide API. @@ -227,9 +227,9 @@ type kolideHandlers struct { GetLicense http.Handler } -func makeKolideKitHandlers(ctx context.Context, e KolideEndpoints, opts []kithttp.ServerOption) *kolideHandlers { +func makeKolideKitHandlers(e KolideEndpoints, opts []kithttp.ServerOption) *kolideHandlers { newServer := func(e endpoint.Endpoint, decodeFn kithttp.DecodeRequestFunc) http.Handler { - return kithttp.NewServer(ctx, e, decodeFn, encodeResponse, opts...) + return kithttp.NewServer(e, decodeFn, encodeResponse, opts...) } return &kolideHandlers{ Login: newServer(e.Login, decodeLoginRequest), @@ -299,7 +299,7 @@ func makeKolideKitHandlers(ctx context.Context, e KolideEndpoints, opts []kithtt } // MakeHandler creates an HTTP handler for the Kolide server endpoints. -func MakeHandler(ctx context.Context, svc kolide.Service, jwtKey string, logger kitlog.Logger) http.Handler { +func MakeHandler(svc kolide.Service, jwtKey string, logger kitlog.Logger) http.Handler { kolideAPIOptions := []kithttp.ServerOption{ kithttp.ServerBefore( setRequestsContexts(svc, jwtKey), @@ -312,7 +312,7 @@ func MakeHandler(ctx context.Context, svc kolide.Service, jwtKey string, logger } kolideEndpoints := MakeKolideServerEndpoints(svc, jwtKey) - kolideHandlers := makeKolideKitHandlers(ctx, kolideEndpoints, kolideAPIOptions) + kolideHandlers := makeKolideKitHandlers(kolideEndpoints, kolideAPIOptions) r := mux.NewRouter() attachKolideAPIRoutes(r, kolideHandlers) @@ -420,13 +420,11 @@ func WithSetup(svc kolide.Service, logger kitlog.Logger, next http.Handler) http return func(w http.ResponseWriter, r *http.Request) { configRouter := http.NewServeMux() configRouter.Handle("/api/v1/setup", kithttp.NewServer( - context.Background(), makeSetupEndpoint(svc), decodeSetupRequest, encodeResponse, )) configRouter.Handle("/api/v1/license", kithttp.NewServer( - context.Background(), makeSetupLicenseEndpoint(svc), decodeLicenseRequest, encodeResponse, diff --git a/server/service/handler_test.go b/server/service/handler_test.go index d9c4b4387..7fd4ee850 100644 --- a/server/service/handler_test.go +++ b/server/service/handler_test.go @@ -9,7 +9,6 @@ import ( "github.com/kolide/kolide/server/config" "github.com/kolide/kolide/server/datastore/inmem" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestAPIRoutes(t *testing.T) { @@ -19,11 +18,9 @@ func TestAPIRoutes(t *testing.T) { svc, err := newTestService(ds, nil) assert.Nil(t, err) - ctx := context.Background() - r := mux.NewRouter() ke := MakeKolideServerEndpoints(svc, "CHANGEME") - kh := makeKolideKitHandlers(ctx, ke, nil) + kh := makeKolideKitHandlers(ke, nil) attachKolideAPIRoutes(r, kh) handler := mux.NewRouter() handler.PathPrefix("/").Handler(r) diff --git a/server/service/http_auth.go b/server/service/http_auth.go index ed29fbb0d..fb3c532d2 100644 --- a/server/service/http_auth.go +++ b/server/service/http_auth.go @@ -1,6 +1,7 @@ package service import ( + "context" "net/http" "strings" @@ -8,7 +9,6 @@ import ( "github.com/kolide/kolide/server/contexts/token" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) // setRequestsContexts updates the request with necessary context values for a request diff --git a/server/service/http_auth_test.go b/server/service/http_auth_test.go index 9bf48aaee..f4c1a7d46 100644 --- a/server/service/http_auth_test.go +++ b/server/service/http_auth_test.go @@ -20,7 +20,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestLogin(t *testing.T) { @@ -40,7 +39,7 @@ func TestLogin(t *testing.T) { } r := mux.NewRouter() ke := MakeKolideServerEndpoints(svc, "CHANGEME") - kh := makeKolideKitHandlers(context.Background(), ke, opts) + kh := makeKolideKitHandlers(ke, opts) attachKolideAPIRoutes(r, kh) r.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "index") diff --git a/server/service/logging_appconfig.go b/server/service/logging_appconfig.go index dc62da268..fee6cf901 100644 --- a/server/service/logging_appconfig.go +++ b/server/service/logging_appconfig.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) NewAppConfig(ctx context.Context, p kolide.AppConfigPayload) (*kolide.AppConfig, error) { diff --git a/server/service/logging_email_change.go b/server/service/logging_email_change.go index c8442739f..a5599aa51 100644 --- a/server/service/logging_email_change.go +++ b/server/service/logging_email_change.go @@ -1,9 +1,8 @@ package service import ( + "context" "time" - - "golang.org/x/net/context" ) func (mw loggingMiddleware) ChangeUserEmail(ctx context.Context, token string) (string, error) { diff --git a/server/service/logging_hosts.go b/server/service/logging_hosts.go index fb1dfd5dc..d64256345 100644 --- a/server/service/logging_hosts.go +++ b/server/service/logging_hosts.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) ListHosts(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Host, error) { diff --git a/server/service/logging_invites.go b/server/service/logging_invites.go index 1c4278069..aa7932af8 100644 --- a/server/service/logging_invites.go +++ b/server/service/logging_invites.go @@ -1,11 +1,11 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) { diff --git a/server/service/logging_labels.go b/server/service/logging_labels.go index 845ed671a..db330c4f0 100644 --- a/server/service/logging_labels.go +++ b/server/service/logging_labels.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) ModifyLabel(ctx context.Context, id uint, p kolide.ModifyLabelPayload) (*kolide.Label, error) { diff --git a/server/service/logging_licenses.go b/server/service/logging_licenses.go index 5a7b12a02..b72f351d9 100644 --- a/server/service/logging_licenses.go +++ b/server/service/logging_licenses.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) SaveLicense(ctx context.Context, jwtToken string) (*kolide.License, error) { diff --git a/server/service/logging_osquery.go b/server/service/logging_osquery.go index 1354a9e07..c1adf1825 100644 --- a/server/service/logging_osquery.go +++ b/server/service/logging_osquery.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) EnrollAgent(ctx context.Context, enrollSecret string, hostIdentifier string) (string, error) { diff --git a/server/service/logging_packs.go b/server/service/logging_packs.go index 30e8ab04a..96e4b16e0 100644 --- a/server/service/logging_packs.go +++ b/server/service/logging_packs.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) ListPacks(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Pack, error) { diff --git a/server/service/logging_scheduled_queries.go b/server/service/logging_scheduled_queries.go index fbf74e84e..8c016dad4 100644 --- a/server/service/logging_scheduled_queries.go +++ b/server/service/logging_scheduled_queries.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) GetScheduledQuery(ctx context.Context, id uint) (*kolide.ScheduledQuery, error) { diff --git a/server/service/logging_sessions.go b/server/service/logging_sessions.go index f22b5920e..d80ac90b1 100644 --- a/server/service/logging_sessions.go +++ b/server/service/logging_sessions.go @@ -1,10 +1,10 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) Login(ctx context.Context, username, password string) (user *kolide.User, token string, err error) { diff --git a/server/service/logging_users.go b/server/service/logging_users.go index 2d8d617bd..a25de830d 100644 --- a/server/service/logging_users.go +++ b/server/service/logging_users.go @@ -1,11 +1,11 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw loggingMiddleware) ChangeUserAdmin(ctx context.Context, id uint, isAdmin bool) (*kolide.User, error) { diff --git a/server/service/metrics_appconfig.go b/server/service/metrics_appconfig.go index 2bbc9528f..969454a30 100644 --- a/server/service/metrics_appconfig.go +++ b/server/service/metrics_appconfig.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) NewAppConfig(ctx context.Context, p kolide.AppConfigPayload) (*kolide.AppConfig, error) { diff --git a/server/service/metrics_change_email.go b/server/service/metrics_change_email.go index 7db806f05..c6764f4b1 100644 --- a/server/service/metrics_change_email.go +++ b/server/service/metrics_change_email.go @@ -1,10 +1,9 @@ package service import ( + "context" "fmt" "time" - - "golang.org/x/net/context" ) func (mw metricsMiddleware) ChangeUserEmail(ctx context.Context, token string) (string, error) { diff --git a/server/service/metrics_invites.go b/server/service/metrics_invites.go index 9adb34b9b..8a67c8682 100644 --- a/server/service/metrics_invites.go +++ b/server/service/metrics_invites.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) { diff --git a/server/service/metrics_labels.go b/server/service/metrics_labels.go index 698c7ead3..f32f5195d 100644 --- a/server/service/metrics_labels.go +++ b/server/service/metrics_labels.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) ModifyLabel(ctx context.Context, id uint, p kolide.ModifyLabelPayload) (*kolide.Label, error) { diff --git a/server/service/metrics_licenses.go b/server/service/metrics_licenses.go index 88ca3708a..2c7924c27 100644 --- a/server/service/metrics_licenses.go +++ b/server/service/metrics_licenses.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) SaveLicense(ctx context.Context, jwtToken string) (*kolide.License, error) { diff --git a/server/service/metrics_sessions.go b/server/service/metrics_sessions.go index 6d53c91f3..97a43428f 100644 --- a/server/service/metrics_sessions.go +++ b/server/service/metrics_sessions.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) Login(ctx context.Context, username string, password string) (*kolide.User, string, error) { diff --git a/server/service/metrics_users.go b/server/service/metrics_users.go index eb0370ff5..daa0b4a93 100644 --- a/server/service/metrics_users.go +++ b/server/service/metrics_users.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "time" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw metricsMiddleware) ChangeUserAdmin(ctx context.Context, id uint, isAdmin bool) (*kolide.User, error) { diff --git a/server/service/service.go b/server/service/service.go index 8437e554e..1597a6934 100644 --- a/server/service/service.go +++ b/server/service/service.go @@ -47,7 +47,7 @@ func osqueryLogFile(path string, appLogger kitlog.Logger) io.Writer { MaxBackups: 3, MaxAge: 28, //days } - appLogger = kitlog.NewContext(appLogger).With("component", "osqueryd-logger") + appLogger = kitlog.With(appLogger, "component", "osqueryd-logger") sig := make(chan os.Signal) signal.Notify(sig, syscall.SIGHUP) diff --git a/server/service/service_appconfig.go b/server/service/service_appconfig.go index 4b860295e..3f7653dca 100644 --- a/server/service/service_appconfig.go +++ b/server/service/service_appconfig.go @@ -1,13 +1,13 @@ package service import ( + "context" "fmt" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" "github.com/kolide/kolide/server/mail" "github.com/pkg/errors" - "golang.org/x/net/context" ) // mailError is set when an error performing mail operations diff --git a/server/service/service_appconfig_test.go b/server/service/service_appconfig_test.go index eb969cbfd..428c5da3c 100644 --- a/server/service/service_appconfig_test.go +++ b/server/service/service_appconfig_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/kolide/kolide/server/config" @@ -8,7 +9,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestCreateAppConfig(t *testing.T) { diff --git a/server/service/service_campaigns.go b/server/service/service_campaigns.go index ff93e9f32..b202ab9c2 100644 --- a/server/service/service_campaigns.go +++ b/server/service/service_campaigns.go @@ -1,6 +1,7 @@ package service import ( + "context" "fmt" "time" @@ -8,7 +9,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/kolide/kolide/server/websocket" "github.com/pkg/errors" - "golang.org/x/net/context" ) func (svc service) NewDistributedQueryCampaign(ctx context.Context, queryString string, hosts []uint, labels []uint) (*kolide.DistributedQueryCampaign, error) { diff --git a/server/service/service_certificate.go b/server/service/service_certificate.go index 1f47b4d31..e25d624b3 100644 --- a/server/service/service_certificate.go +++ b/server/service/service_certificate.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "crypto/tls" "crypto/x509" "encoding/pem" @@ -10,7 +11,6 @@ import ( "net/url" "github.com/pkg/errors" - "golang.org/x/net/context" ) // Certificate returns the PEM encoded certificate chain for osqueryd TLS termination. diff --git a/server/service/service_hosts.go b/server/service/service_hosts.go index 9d7b88fea..c4e6a5540 100644 --- a/server/service/service_hosts.go +++ b/server/service/service_hosts.go @@ -1,8 +1,9 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) ListHosts(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Host, error) { diff --git a/server/service/service_hosts_test.go b/server/service/service_hosts_test.go index 616b02624..6eaf6b42f 100644 --- a/server/service/service_hosts_test.go +++ b/server/service/service_hosts_test.go @@ -1,13 +1,13 @@ package service import ( + "context" "testing" "github.com/kolide/kolide/server/config" "github.com/kolide/kolide/server/datastore/inmem" "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestListHosts(t *testing.T) { diff --git a/server/service/service_import_config.go b/server/service/service_import_config.go index ada180424..a963160bc 100644 --- a/server/service/service_import_config.go +++ b/server/service/service_import_config.go @@ -1,13 +1,13 @@ package service import ( + "context" "errors" "strconv" "strings" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) ImportConfig(ctx context.Context, cfg *kolide.ImportConfig) (*kolide.ImportConfigResponse, error) { diff --git a/server/service/service_invites.go b/server/service/service_invites.go index 840ae4623..ce635fc6a 100644 --- a/server/service/service_invites.go +++ b/server/service/service_invites.go @@ -1,11 +1,11 @@ package service import ( + "context" "encoding/base64" "html/template" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) { diff --git a/server/service/service_invites_test.go b/server/service/service_invites_test.go index 8f2fadbcb..545d4fcd7 100644 --- a/server/service/service_invites_test.go +++ b/server/service/service_invites_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "time" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestInviteNewUserMock(t *testing.T) { diff --git a/server/service/service_labels.go b/server/service/service_labels.go index 7883b0d82..685b8ad29 100644 --- a/server/service/service_labels.go +++ b/server/service/service_labels.go @@ -1,8 +1,9 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) ListLabels(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Label, error) { diff --git a/server/service/service_labels_test.go b/server/service/service_labels_test.go index 18796f94a..1db3221ae 100644 --- a/server/service/service_labels_test.go +++ b/server/service/service_labels_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/kolide/kolide/server/config" @@ -9,7 +10,6 @@ import ( "github.com/kolide/kolide/server/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestModifyLabel(t *testing.T) { diff --git a/server/service/service_licenses.go b/server/service/service_licenses.go index 2b1748838..ebba65cbc 100644 --- a/server/service/service_licenses.go +++ b/server/service/service_licenses.go @@ -1,8 +1,9 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) License(ctx context.Context) (*kolide.License, error) { diff --git a/server/service/service_licenses_test.go b/server/service/service_licenses_test.go index 60b131ba6..7a09ae1d2 100644 --- a/server/service/service_licenses_test.go +++ b/server/service/service_licenses_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "time" @@ -9,7 +10,6 @@ import ( "github.com/kolide/kolide/server/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestLicenseService(t *testing.T) { diff --git a/server/service/service_options.go b/server/service/service_options.go index ea69ca806..77a58a842 100644 --- a/server/service/service_options.go +++ b/server/service/service_options.go @@ -1,11 +1,11 @@ package service import ( + "context" "time" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) const expectedCheckinIntervalMultiplier = 2 diff --git a/server/service/service_osquery.go b/server/service/service_osquery.go index 0a19c36f3..fc0fd5528 100644 --- a/server/service/service_osquery.go +++ b/server/service/service_osquery.go @@ -1,6 +1,7 @@ package service import ( + "context" "encoding/json" "fmt" "strconv" @@ -12,7 +13,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/kolide/kolide/server/pubsub" "github.com/pkg/errors" - "golang.org/x/net/context" ) type osqueryError struct { diff --git a/server/service/service_osquery_test.go b/server/service/service_osquery_test.go index d0089c2ef..f29b58e48 100644 --- a/server/service/service_osquery_test.go +++ b/server/service/service_osquery_test.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "encoding/json" "fmt" "strings" @@ -9,8 +10,6 @@ import ( "testing" "time" - "golang.org/x/net/context" - "github.com/WatchBeam/clock" "github.com/kolide/kolide/server/config" hostctx "github.com/kolide/kolide/server/contexts/host" diff --git a/server/service/service_packs.go b/server/service/service_packs.go index c6e432899..eac5f8058 100644 --- a/server/service/service_packs.go +++ b/server/service/service_packs.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) ListPacks(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Pack, error) { diff --git a/server/service/service_packs_test.go b/server/service/service_packs_test.go index b6e918de8..80b4621b8 100644 --- a/server/service/service_packs_test.go +++ b/server/service/service_packs_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/WatchBeam/clock" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestListPacks(t *testing.T) { diff --git a/server/service/service_queries.go b/server/service/service_queries.go index 1e5c130db..c2f071360 100644 --- a/server/service/service_queries.go +++ b/server/service/service_queries.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (svc service) ListQueries(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Query, error) { diff --git a/server/service/service_queries_test.go b/server/service/service_queries_test.go index ff45e5759..50bdbd7ff 100644 --- a/server/service/service_queries_test.go +++ b/server/service/service_queries_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/kolide/kolide/server/config" @@ -9,7 +10,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestListQueries(t *testing.T) { diff --git a/server/service/service_scheduled_queries.go b/server/service/service_scheduled_queries.go index 47c6d844b..d823473bf 100644 --- a/server/service/service_scheduled_queries.go +++ b/server/service/service_scheduled_queries.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) func (svc service) GetScheduledQuery(ctx context.Context, id uint) (*kolide.ScheduledQuery, error) { diff --git a/server/service/service_scheduled_queries_test.go b/server/service/service_scheduled_queries_test.go index 0fa55deaf..7f5a81bc7 100644 --- a/server/service/service_scheduled_queries_test.go +++ b/server/service/service_scheduled_queries_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "github.com/kolide/kolide/server/config" @@ -9,7 +10,6 @@ import ( "github.com/kolide/kolide/server/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestGetScheduledQueriesInPack(t *testing.T) { diff --git a/server/service/service_sessions.go b/server/service/service_sessions.go index 03035f060..62bc38934 100644 --- a/server/service/service_sessions.go +++ b/server/service/service_sessions.go @@ -1,6 +1,7 @@ package service import ( + "context" "crypto/rand" "encoding/base64" "strings" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) func (svc service) Login(ctx context.Context, username, password string) (*kolide.User, string, error) { diff --git a/server/service/service_sessions_test.go b/server/service/service_sessions_test.go index c959318ef..1b34066cd 100644 --- a/server/service/service_sessions_test.go +++ b/server/service/service_sessions_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "testing" "time" @@ -10,7 +11,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) const bcryptCost = 6 diff --git a/server/service/service_targets.go b/server/service/service_targets.go index 1300d7881..8aff28be6 100644 --- a/server/service/service_targets.go +++ b/server/service/service_targets.go @@ -1,9 +1,10 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) func (svc service) SearchTargets(ctx context.Context, query string, selectedHostIDs []uint, selectedLabelIDs []uint) (*kolide.TargetSearchResults, error) { diff --git a/server/service/service_targets_test.go b/server/service/service_targets_test.go index 5d94660db..3c9a43a35 100644 --- a/server/service/service_targets_test.go +++ b/server/service/service_targets_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "fmt" "testing" "time" @@ -11,7 +12,6 @@ import ( "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestSearchTargets(t *testing.T) { diff --git a/server/service/service_users.go b/server/service/service_users.go index fb24fb84a..d899cd5e0 100644 --- a/server/service/service_users.go +++ b/server/service/service_users.go @@ -1,6 +1,7 @@ package service import ( + "context" "crypto/rand" "encoding/base64" "html/template" @@ -9,7 +10,6 @@ import ( "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - "golang.org/x/net/context" ) func (svc service) NewUser(ctx context.Context, p kolide.UserPayload) (*kolide.User, error) { diff --git a/server/service/service_users_test.go b/server/service/service_users_test.go index c415724d5..469d04222 100644 --- a/server/service/service_users_test.go +++ b/server/service/service_users_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "errors" "testing" "time" @@ -15,7 +16,6 @@ import ( pkg_errors "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestAuthenticatedUser(t *testing.T) { diff --git a/server/service/transport.go b/server/service/transport.go index b504b1f03..ecff7a3cc 100644 --- a/server/service/transport.go +++ b/server/service/transport.go @@ -1,6 +1,7 @@ package service import ( + "context" "encoding/json" "errors" "net/http" @@ -8,7 +9,6 @@ import ( "github.com/gorilla/mux" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) var ( diff --git a/server/service/transport_appconfig.go b/server/service/transport_appconfig.go index 7ae1e3db9..dc954d38f 100644 --- a/server/service/transport_appconfig.go +++ b/server/service/transport_appconfig.go @@ -1,12 +1,11 @@ package service import ( + "context" "encoding/json" "net/http" "github.com/kolide/kolide/server/kolide" - - "golang.org/x/net/context" ) func decodeModifyAppConfigRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_campaigns.go b/server/service/transport_campaigns.go index eb5ee7b8d..e9f4efe09 100644 --- a/server/service/transport_campaigns.go +++ b/server/service/transport_campaigns.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeCreateDistributedQueryCampaignRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_change_email.go b/server/service/transport_change_email.go index a33b155b7..3599a64ff 100644 --- a/server/service/transport_change_email.go +++ b/server/service/transport_change_email.go @@ -1,10 +1,10 @@ package service import ( + "context" "net/http" "github.com/gorilla/mux" - "golang.org/x/net/context" ) func decodeChangeEmailRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_error.go b/server/service/transport_error.go index 21642fba2..b77875669 100644 --- a/server/service/transport_error.go +++ b/server/service/transport_error.go @@ -1,11 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - kithttp "github.com/go-kit/kit/transport/http" - "golang.org/x/net/context" ) // erroer interface is implemented by response structs to encode business logic errors @@ -38,13 +36,6 @@ func namedError(name string, err string) []map[string]string { // encode error and status header to the client func encodeError(ctx context.Context, err error, w http.ResponseWriter) { - // Unwrap Go-Kit Error - domain := "service" - if e, ok := err.(kithttp.Error); ok { - err = e.Err - domain = e.Domain - } - enc := json.NewEncoder(w) enc.SetIndent("", " ") @@ -166,15 +157,7 @@ func encodeError(ctx context.Context, err error, w http.ResponseWriter) { return } - // Other errors - switch domain { - case kithttp.DomainDecode: - w.WriteHeader(http.StatusBadRequest) - case kithttp.DomainDo: - w.WriteHeader(http.StatusServiceUnavailable) - default: - w.WriteHeader(http.StatusInternalServerError) - } + w.WriteHeader(http.StatusInternalServerError) je := jsonError{ Message: "Unknown Error", Errors: baseError(err.Error()), diff --git a/server/service/transport_hosts.go b/server/service/transport_hosts.go index 2855b33ee..03211e71c 100644 --- a/server/service/transport_hosts.go +++ b/server/service/transport_hosts.go @@ -1,9 +1,8 @@ package service import ( + "context" "net/http" - - "golang.org/x/net/context" ) func decodeGetHostRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_import_config.go b/server/service/transport_import_config.go index 2c9e31d80..d92d6730c 100644 --- a/server/service/transport_import_config.go +++ b/server/service/transport_import_config.go @@ -1,11 +1,11 @@ package service import ( + "context" "encoding/json" "net/http" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func decodeImportConfigRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_invites.go b/server/service/transport_invites.go index 0bbeb7901..e6c70b572 100644 --- a/server/service/transport_invites.go +++ b/server/service/transport_invites.go @@ -1,12 +1,12 @@ package service import ( + "context" "encoding/json" "net/http" "strings" "github.com/gorilla/mux" - "golang.org/x/net/context" ) func decodeCreateInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_invites_test.go b/server/service/transport_invites_test.go index 7789a5284..e2365a4b7 100644 --- a/server/service/transport_invites_test.go +++ b/server/service/transport_invites_test.go @@ -2,13 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestDecodeCreateInviteRequest(t *testing.T) { diff --git a/server/service/transport_labels.go b/server/service/transport_labels.go index 56209cf98..c4321d6e9 100644 --- a/server/service/transport_labels.go +++ b/server/service/transport_labels.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeCreateLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_labels_test.go b/server/service/transport_labels_test.go index 00f137844..e15b28343 100644 --- a/server/service/transport_labels_test.go +++ b/server/service/transport_labels_test.go @@ -2,14 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - - "golang.org/x/net/context" ) func TestDecodeCreateLabelRequest(t *testing.T) { diff --git a/server/service/transport_licenses.go b/server/service/transport_licenses.go index 143f81d4e..f2e0d49ea 100644 --- a/server/service/transport_licenses.go +++ b/server/service/transport_licenses.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeLicenseRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_options.go b/server/service/transport_options.go index 29fae8ec8..57fea9a71 100644 --- a/server/service/transport_options.go +++ b/server/service/transport_options.go @@ -1,11 +1,11 @@ package service import ( + "context" "encoding/json" "net/http" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func decodeModifyOptionsRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_osquery.go b/server/service/transport_osquery.go index 698fcd112..1fb0ec9db 100644 --- a/server/service/transport_osquery.go +++ b/server/service/transport_osquery.go @@ -2,13 +2,12 @@ package service import ( "compress/gzip" + "context" "encoding/json" "net/http" "github.com/kolide/kolide/server/kolide" "github.com/pkg/errors" - - "golang.org/x/net/context" ) func decodeEnrollAgentRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_osquery_test.go b/server/service/transport_osquery_test.go index 9aa3aa072..9dc3cfa01 100644 --- a/server/service/transport_osquery_test.go +++ b/server/service/transport_osquery_test.go @@ -3,12 +3,11 @@ package service import ( "bytes" "compress/gzip" + "context" "net/http" "net/http/httptest" "testing" - "golang.org/x/net/context" - "github.com/gorilla/mux" "github.com/kolide/kolide/server/kolide" "github.com/stretchr/testify/assert" diff --git a/server/service/transport_packs.go b/server/service/transport_packs.go index 832162de2..6ccc63b82 100644 --- a/server/service/transport_packs.go +++ b/server/service/transport_packs.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeCreatePackRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_packs_test.go b/server/service/transport_packs_test.go index c3169eef2..0806e4c5b 100644 --- a/server/service/transport_packs_test.go +++ b/server/service/transport_packs_test.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" @@ -9,7 +10,6 @@ import ( "github.com/gorilla/mux" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/net/context" ) func TestDecodeCreatePackRequest(t *testing.T) { diff --git a/server/service/transport_queries.go b/server/service/transport_queries.go index e0c093dc4..5f5cd53e8 100644 --- a/server/service/transport_queries.go +++ b/server/service/transport_queries.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeCreateQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_queries_test.go b/server/service/transport_queries_test.go index 3a4694d1c..393eb69de 100644 --- a/server/service/transport_queries_test.go +++ b/server/service/transport_queries_test.go @@ -2,14 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - - "golang.org/x/net/context" ) func TestDecodeCreateQueryRequest(t *testing.T) { diff --git a/server/service/transport_scheduled_queries.go b/server/service/transport_scheduled_queries.go index 298ba3e82..d3a9c002c 100644 --- a/server/service/transport_scheduled_queries.go +++ b/server/service/transport_scheduled_queries.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeScheduleQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_scheduled_queries_test.go b/server/service/transport_scheduled_queries_test.go index 8d48af78b..6e79d74c4 100644 --- a/server/service/transport_scheduled_queries_test.go +++ b/server/service/transport_scheduled_queries_test.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" @@ -9,8 +10,6 @@ import ( "github.com/gorilla/mux" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "golang.org/x/net/context" ) func TestDecodeScheduleQueryRequest(t *testing.T) { diff --git a/server/service/transport_sessions.go b/server/service/transport_sessions.go index 8875de781..62970f45d 100644 --- a/server/service/transport_sessions.go +++ b/server/service/transport_sessions.go @@ -1,11 +1,10 @@ package service import ( + "context" "encoding/json" "net/http" "strings" - - "golang.org/x/net/context" ) func decodeGetInfoAboutSessionRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_sessions_test.go b/server/service/transport_sessions_test.go index 5388fb2b9..1316d6b38 100644 --- a/server/service/transport_sessions_test.go +++ b/server/service/transport_sessions_test.go @@ -2,13 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestDecodeGetInfoAboutSessionRequest(t *testing.T) { diff --git a/server/service/transport_setup.go b/server/service/transport_setup.go index a287136d2..2b072d3ca 100644 --- a/server/service/transport_setup.go +++ b/server/service/transport_setup.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeSetupRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_targets.go b/server/service/transport_targets.go index 2f15923c0..f0d4eeb43 100644 --- a/server/service/transport_targets.go +++ b/server/service/transport_targets.go @@ -1,10 +1,9 @@ package service import ( + "context" "encoding/json" "net/http" - - "golang.org/x/net/context" ) func decodeSearchTargetsRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_targets_test.go b/server/service/transport_targets_test.go index 2337f153f..d96035a32 100644 --- a/server/service/transport_targets_test.go +++ b/server/service/transport_targets_test.go @@ -2,13 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestDecodeSearchTargetsRequest(t *testing.T) { diff --git a/server/service/transport_users.go b/server/service/transport_users.go index 526b12c19..2e740d41f 100644 --- a/server/service/transport_users.go +++ b/server/service/transport_users.go @@ -1,11 +1,11 @@ package service import ( + "context" "encoding/json" "net/http" "github.com/pkg/errors" - "golang.org/x/net/context" ) func decodeEnableUserRequest(ctx context.Context, r *http.Request) (interface{}, error) { diff --git a/server/service/transport_users_test.go b/server/service/transport_users_test.go index b35a9c28a..6910651e3 100644 --- a/server/service/transport_users_test.go +++ b/server/service/transport_users_test.go @@ -2,13 +2,13 @@ package service import ( "bytes" + "context" "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" - "golang.org/x/net/context" ) func TestDecodeCreateUserRequest(t *testing.T) { diff --git a/server/service/validation_import_config.go b/server/service/validation_import_config.go index 94092f289..53be38624 100644 --- a/server/service/validation_import_config.go +++ b/server/service/validation_import_config.go @@ -1,10 +1,10 @@ package service import ( + "context" "strconv" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (vm validationMiddleware) ImportConfig(ctx context.Context, cfg *kolide.ImportConfig) (*kolide.ImportConfigResponse, error) { diff --git a/server/service/validation_invites.go b/server/service/validation_invites.go index f322af62c..ab3503c1e 100644 --- a/server/service/validation_invites.go +++ b/server/service/validation_invites.go @@ -1,8 +1,9 @@ package service import ( + "context" + "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw validationMiddleware) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) { diff --git a/server/service/validation_options.go b/server/service/validation_options.go index 65f49c0e8..5c79024d3 100644 --- a/server/service/validation_options.go +++ b/server/service/validation_options.go @@ -1,10 +1,10 @@ package service import ( + "context" "errors" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw validationMiddleware) ModifyOptions(ctx context.Context, req kolide.OptionRequest) ([]kolide.Option, error) { diff --git a/server/service/validation_setup.go b/server/service/validation_setup.go index c4784e4cb..4737afc02 100644 --- a/server/service/validation_setup.go +++ b/server/service/validation_setup.go @@ -1,11 +1,11 @@ package service import ( + "context" "fmt" "net/url" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) func (mw validationMiddleware) NewAppConfig(ctx context.Context, payload kolide.AppConfigPayload) (*kolide.AppConfig, error) { diff --git a/server/service/validation_users.go b/server/service/validation_users.go index 01732167f..cb06386cd 100644 --- a/server/service/validation_users.go +++ b/server/service/validation_users.go @@ -1,13 +1,13 @@ package service import ( + "context" "errors" "strings" "unicode" "github.com/kolide/kolide/server/contexts/viewer" "github.com/kolide/kolide/server/kolide" - "golang.org/x/net/context" ) type validationMiddleware struct {