Allow scheduled query shard to be set to empty in frontend (#2093)

Fixes #1452
This commit is contained in:
Zachary Wasserman 2019-08-13 09:42:02 -07:00 committed by GitHub
parent bdeea59c73
commit 363b6157c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 11 deletions

9
Gopkg.lock generated
View File

@ -270,6 +270,14 @@
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"
[[projects]]
digest = "1:a4b04b5314d49a67ad022fa7693453ee2b823ab99314f52fa3930ed31085dfef"
name = "github.com/guregu/null"
packages = ["."]
pruneopts = "UT"
revision = "80515d440932108546bcade467bb7d6968e812e2"
version = "v3.4.0"
[[projects]]
digest = "1:67474f760e9ac3799f740db2c489e6423a4cde45520673ec123ac831ad849cb8"
name = "github.com/hashicorp/golang-lru"
@ -858,6 +866,7 @@
"github.com/gomodule/redigo/redis",
"github.com/gorilla/mux",
"github.com/gorilla/websocket",
"github.com/guregu/null",
"github.com/igm/sockjs-go/sockjs",
"github.com/jmoiron/sqlx",
"github.com/jmoiron/sqlx/reflectx",

View File

@ -125,3 +125,7 @@
[[constraint]]
name = "cloud.google.com/go"
version = "0.37.4"
[[constraint]]
name = "github.com/guregu/null"
version = "3.4.0"

View File

@ -2,6 +2,8 @@ package kolide
import (
"context"
"github.com/guregu/null"
)
type ScheduledQueryStore interface {
@ -39,12 +41,12 @@ type ScheduledQuery struct {
}
type ScheduledQueryPayload struct {
PackID *uint `json:"pack_id"`
QueryID *uint `json:"query_id"`
Interval *uint `json:"interval"`
Snapshot *bool `json:"snapshot"`
Removed *bool `json:"removed"`
Platform *string `json:"platform"`
Version *string `json:"version"`
Shard *uint `json:"shard"`
PackID *uint `json:"pack_id"`
QueryID *uint `json:"query_id"`
Interval *uint `json:"interval"`
Snapshot *bool `json:"snapshot"`
Removed *bool `json:"removed"`
Platform *string `json:"platform"`
Version *string `json:"version"`
Shard *null.Int `json:"shard"`
}

View File

@ -64,7 +64,12 @@ func (svc service) ModifyScheduledQuery(ctx context.Context, id uint, p kolide.S
}
if p.Shard != nil {
sq.Shard = p.Shard
if p.Shard.Valid {
val := uint(p.Shard.Int64)
sq.Shard = &val
} else {
sq.Shard = nil
}
}
return svc.ds.SaveScheduledQuery(sq)

View File

@ -67,12 +67,13 @@ func TestDecodeModifyScheduledQueryRequest(t *testing.T) {
assert.Equal(t, uint(6), *params.payload.QueryID)
assert.Equal(t, true, *params.payload.Removed)
assert.Equal(t, uint(60), *params.payload.Interval)
assert.Equal(t, uint(1), *params.payload.Shard)
assert.Equal(t, true, params.payload.Shard.Valid)
assert.Equal(t, int64(1), params.payload.Shard.Int64)
}).Methods("PATCH")
var body bytes.Buffer
body.Write([]byte(`{
"pack_id": 5,
"pack_id": 5,
"query_id": 6,
"removed": true,
"interval": 60,