mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Remove existing bulk functionality (#641)
This commit is contained in:
parent
56b3799457
commit
1ada011f37
@ -79,12 +79,12 @@ func makeGetScheduledQueriesInPackEndpoint(svc kolide.Service) endpoint.Endpoint
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Schedule Queries
|
||||
// Schedule Query
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type scheduleQuerySubmission struct {
|
||||
type scheduleQueryRequest struct {
|
||||
PackID uint `json:"pack_id"`
|
||||
QueryIDs []uint `json:"query_ids"`
|
||||
QueryID uint `json:"query_id"`
|
||||
Interval uint `json:"interval"`
|
||||
Snapshot *bool `json:"snapshot"`
|
||||
Removed *bool `json:"removed"`
|
||||
@ -93,44 +93,31 @@ type scheduleQuerySubmission struct {
|
||||
Shard *uint `json:"shard"`
|
||||
}
|
||||
|
||||
type scheduleQueriesRequest struct {
|
||||
Options []scheduleQuerySubmission `json:"options"`
|
||||
type scheduleQueryResponse struct {
|
||||
Scheduled scheduledQueryResponse `json:"scheduled"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type scheduleQueriesResponse struct {
|
||||
Scheduled []scheduledQueryResponse `json:"scheduled"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r scheduleQueriesResponse) error() error { return r.Err }
|
||||
|
||||
func makeScheduleQueriesEndpoint(svc kolide.Service) endpoint.Endpoint {
|
||||
func makeScheduleQueryEndpoint(svc kolide.Service) endpoint.Endpoint {
|
||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
||||
req := request.(scheduleQueriesRequest)
|
||||
resp := getScheduledQueriesInPackResponse{Scheduled: []scheduledQueryResponse{}}
|
||||
req := request.(scheduleQueryRequest)
|
||||
|
||||
for _, submission := range req.Options {
|
||||
for _, queryID := range submission.QueryIDs {
|
||||
scheduled, err := svc.ScheduleQuery(ctx, &kolide.ScheduledQuery{
|
||||
PackID: submission.PackID,
|
||||
QueryID: queryID,
|
||||
Interval: submission.Interval,
|
||||
Snapshot: submission.Snapshot,
|
||||
Removed: submission.Removed,
|
||||
Platform: submission.Platform,
|
||||
Version: submission.Version,
|
||||
Shard: submission.Shard,
|
||||
})
|
||||
if err != nil {
|
||||
return scheduleQueriesResponse{Err: err}, nil
|
||||
}
|
||||
resp.Scheduled = append(resp.Scheduled, scheduledQueryResponse{
|
||||
ScheduledQuery: *scheduled,
|
||||
})
|
||||
}
|
||||
scheduled, err := svc.ScheduleQuery(ctx, &kolide.ScheduledQuery{
|
||||
PackID: req.PackID,
|
||||
QueryID: req.QueryID,
|
||||
Interval: req.Interval,
|
||||
Snapshot: req.Snapshot,
|
||||
Removed: req.Removed,
|
||||
Platform: req.Platform,
|
||||
Version: req.Version,
|
||||
Shard: req.Shard,
|
||||
})
|
||||
if err != nil {
|
||||
return scheduleQueryResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
return scheduleQueryResponse{Scheduled: scheduledQueryResponse{
|
||||
ScheduledQuery: *scheduled,
|
||||
}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ type KolideEndpoints struct {
|
||||
CreatePack endpoint.Endpoint
|
||||
ModifyPack endpoint.Endpoint
|
||||
DeletePack endpoint.Endpoint
|
||||
ScheduleQueries endpoint.Endpoint
|
||||
ScheduleQuery endpoint.Endpoint
|
||||
GetScheduledQueriesInPack endpoint.Endpoint
|
||||
GetScheduledQuery endpoint.Endpoint
|
||||
ModifyScheduledQuery endpoint.Endpoint
|
||||
@ -110,7 +110,7 @@ func MakeKolideServerEndpoints(svc kolide.Service, jwtKey string) KolideEndpoint
|
||||
CreatePack: authenticatedUser(jwtKey, svc, makeCreatePackEndpoint(svc)),
|
||||
ModifyPack: authenticatedUser(jwtKey, svc, makeModifyPackEndpoint(svc)),
|
||||
DeletePack: authenticatedUser(jwtKey, svc, makeDeletePackEndpoint(svc)),
|
||||
ScheduleQueries: authenticatedUser(jwtKey, svc, makeScheduleQueriesEndpoint(svc)),
|
||||
ScheduleQuery: authenticatedUser(jwtKey, svc, makeScheduleQueryEndpoint(svc)),
|
||||
GetScheduledQueriesInPack: authenticatedUser(jwtKey, svc, makeGetScheduledQueriesInPackEndpoint(svc)),
|
||||
GetScheduledQuery: authenticatedUser(jwtKey, svc, makeGetScheduledQueryEndpoint(svc)),
|
||||
ModifyScheduledQuery: authenticatedUser(jwtKey, svc, makeModifyScheduledQueryEndpoint(svc)),
|
||||
@ -168,7 +168,7 @@ type kolideHandlers struct {
|
||||
CreatePack *kithttp.Server
|
||||
ModifyPack *kithttp.Server
|
||||
DeletePack *kithttp.Server
|
||||
ScheduleQueries *kithttp.Server
|
||||
ScheduleQuery *kithttp.Server
|
||||
GetScheduledQueriesInPack *kithttp.Server
|
||||
GetScheduledQuery *kithttp.Server
|
||||
ModifyScheduledQuery *kithttp.Server
|
||||
@ -227,7 +227,7 @@ func makeKolideKitHandlers(ctx context.Context, e KolideEndpoints, opts []kithtt
|
||||
CreatePack: newServer(e.CreatePack, decodeCreatePackRequest),
|
||||
ModifyPack: newServer(e.ModifyPack, decodeModifyPackRequest),
|
||||
DeletePack: newServer(e.DeletePack, decodeDeletePackRequest),
|
||||
ScheduleQueries: newServer(e.ScheduleQueries, decodeScheduleQueriesRequest),
|
||||
ScheduleQuery: newServer(e.ScheduleQuery, decodeScheduleQueryRequest),
|
||||
GetScheduledQueriesInPack: newServer(e.GetScheduledQueriesInPack, decodeGetScheduledQueriesInPackRequest),
|
||||
GetScheduledQuery: newServer(e.GetScheduledQuery, decodeGetScheduledQueryRequest),
|
||||
ModifyScheduledQuery: newServer(e.ModifyScheduledQuery, decodeModifyScheduledQueryRequest),
|
||||
@ -314,7 +314,7 @@ func attachKolideAPIRoutes(r *mux.Router, h kolideHandlers) {
|
||||
r.Handle("/api/v1/kolide/packs/{id}", h.ModifyPack).Methods("PATCH")
|
||||
r.Handle("/api/v1/kolide/packs/{id}", h.DeletePack).Methods("DELETE")
|
||||
r.Handle("/api/v1/kolide/packs/{id}/scheduled", h.GetScheduledQueriesInPack).Methods("GET")
|
||||
r.Handle("/api/v1/kolide/schedule", h.ScheduleQueries).Methods("POST")
|
||||
r.Handle("/api/v1/kolide/schedule", h.ScheduleQuery).Methods("POST")
|
||||
r.Handle("/api/v1/kolide/schedule/{id}", h.GetScheduledQuery).Methods("GET")
|
||||
r.Handle("/api/v1/kolide/schedule/{id}", h.ModifyScheduledQuery).Methods("PATCH")
|
||||
r.Handle("/api/v1/kolide/schedule/{id}", h.DeleteScheduledQuery).Methods("DELETE")
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func decodeScheduleQueriesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
||||
var req scheduleQueriesRequest
|
||||
func decodeScheduleQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
||||
var req scheduleQueryRequest
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
return nil, err
|
||||
|
@ -13,62 +13,25 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestDecodeScheduleQueriesRequest(t *testing.T) {
|
||||
func TestDecodeScheduleQueryRequest(t *testing.T) {
|
||||
router := mux.NewRouter()
|
||||
router.HandleFunc("/api/v1/kolide/schedule", func(writer http.ResponseWriter, request *http.Request) {
|
||||
r, err := decodeScheduleQueriesRequest(context.Background(), request)
|
||||
r, err := decodeScheduleQueryRequest(context.Background(), request)
|
||||
require.Nil(t, err)
|
||||
|
||||
params := r.(scheduleQueriesRequest)
|
||||
require.Len(t, params.Options, 2)
|
||||
|
||||
accessed := struct {
|
||||
Five bool
|
||||
Six bool
|
||||
}{}
|
||||
|
||||
for _, q := range params.Options {
|
||||
switch q.PackID {
|
||||
case uint(5):
|
||||
accessed.Five = true
|
||||
assert.Equal(t, uint(60), q.Interval)
|
||||
assert.Equal(t, true, *q.Snapshot)
|
||||
assert.Nil(t, q.Removed)
|
||||
assert.Len(t, q.QueryIDs, 1)
|
||||
assert.Equal(t, q.QueryIDs[0], uint(1))
|
||||
case uint(6):
|
||||
accessed.Six = true
|
||||
assert.Equal(t, uint(120), q.Interval)
|
||||
assert.Nil(t, q.Removed)
|
||||
assert.Nil(t, q.Snapshot)
|
||||
assert.Len(t, q.QueryIDs, 3)
|
||||
default:
|
||||
t.Errorf("Found an unexpected pack_id: %d", q.PackID)
|
||||
}
|
||||
}
|
||||
|
||||
if !accessed.Five {
|
||||
t.Error("Create scheduled query for pack 5 not read")
|
||||
}
|
||||
|
||||
if !accessed.Six {
|
||||
t.Error("Create scheduled query for pack 6 not read")
|
||||
}
|
||||
|
||||
params := r.(scheduleQueryRequest)
|
||||
assert.Equal(t, uint(5), params.PackID)
|
||||
assert.Equal(t, uint(1), params.QueryID)
|
||||
assert.Equal(t, uint(60), params.Interval)
|
||||
assert.Equal(t, true, *params.Snapshot)
|
||||
}).Methods("POST")
|
||||
|
||||
var body bytes.Buffer
|
||||
body.Write([]byte(`{
|
||||
"options": [{
|
||||
"pack_id": 5,
|
||||
"interval": 60,
|
||||
"snapshot": true,
|
||||
"query_ids": [1]
|
||||
},{
|
||||
"pack_id": 6,
|
||||
"interval": 120,
|
||||
"query_ids": [1, 2, 3]
|
||||
}]
|
||||
"pack_id": 5,
|
||||
"query_id": 1,
|
||||
"interval": 60,
|
||||
"snapshot": true
|
||||
}`))
|
||||
|
||||
router.ServeHTTP(
|
||||
|
Loading…
Reference in New Issue
Block a user