mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Serializable config types (#141)
This commit is contained in:
parent
2f8db0d184
commit
428351d3a8
@ -367,7 +367,7 @@ func testLabelQueries(t *testing.T, db kolide.Datastore) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Use a 10 minute interval, so the query we just added should show up
|
||||
queries, err = kolide.LabelQueriesForHost(db, host, 10*time.Minute)
|
||||
queries, err = db.LabelQueriesForHost(host, time.Now().Add(-(10 * time.Minute)))
|
||||
assert.NoError(t, err)
|
||||
delete(expectQueries, "1")
|
||||
assert.Equal(t, expectQueries, queries)
|
||||
@ -375,7 +375,7 @@ func testLabelQueries(t *testing.T, db kolide.Datastore) {
|
||||
// Record an old query execution -- Shouldn't change the return
|
||||
err = db.RecordLabelQueryExecutions(host, map[string]bool{"2": true}, baseTime.Add(-1*time.Hour))
|
||||
assert.NoError(t, err)
|
||||
queries, err = kolide.LabelQueriesForHost(db, host, 10*time.Minute)
|
||||
queries, err = db.LabelQueriesForHost(host, time.Now().Add(-(10 * time.Minute)))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectQueries, queries)
|
||||
|
||||
@ -386,7 +386,7 @@ func testLabelQueries(t *testing.T, db kolide.Datastore) {
|
||||
// Now these should no longer show up in the necessary to run queries
|
||||
delete(expectQueries, "2")
|
||||
delete(expectQueries, "3")
|
||||
queries, err = kolide.LabelQueriesForHost(db, host, 10*time.Minute)
|
||||
queries, err = db.LabelQueriesForHost(host, time.Now().Add(-(10 * time.Minute)))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectQueries, queries)
|
||||
|
||||
|
@ -15,7 +15,7 @@ type OsqueryStore interface {
|
||||
|
||||
type OsqueryService interface {
|
||||
EnrollAgent(ctx context.Context, enrollSecret, hostIdentifier string) (string, error)
|
||||
GetClientConfig(ctx context.Context, action string, data json.RawMessage) (OsqueryConfig, error)
|
||||
GetClientConfig(ctx context.Context, action string, data json.RawMessage) (*OsqueryConfig, error)
|
||||
GetDistributedQueries(ctx context.Context) (map[string]string, error)
|
||||
SubmitDistributedQueryResults(ctx context.Context, results OsqueryDistributedQueryResults) error
|
||||
SubmitStatusLogs(ctx context.Context, logs []OsqueryResultLog) error
|
||||
@ -24,9 +24,44 @@ type OsqueryService interface {
|
||||
|
||||
type OsqueryDistributedQueryResults map[string][]map[string]string
|
||||
|
||||
type QueryContent struct {
|
||||
Query string `json:"query"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Interval uint `json:"interval"`
|
||||
Platform string `json:"platform,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Snapshot bool `json:"snapshot,omitempty"`
|
||||
Removed bool `json:"removed,omitempty"`
|
||||
Shard uint `json:"shard,omitempty"`
|
||||
}
|
||||
|
||||
type Queries map[string]QueryContent
|
||||
|
||||
type PackContent struct {
|
||||
Platform string `json:"platform,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Shard uint `json:"shard,omitempty"`
|
||||
Discovery []string `json:"discovery,omitempty"`
|
||||
Queries Queries `json:"queries"`
|
||||
}
|
||||
|
||||
type Packs map[string]PackContent
|
||||
|
||||
type Options struct {
|
||||
PackDelimiter string `json:"pack_delimiter,omitempty"`
|
||||
DisableDistributed bool `json:"disable_distributed"`
|
||||
}
|
||||
|
||||
type Decorators struct {
|
||||
Load []string `json:"load,omitempty"`
|
||||
Always []string `json:"always,omitempty"`
|
||||
Interval map[string][]string `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
type OsqueryConfig struct {
|
||||
Packs []Pack
|
||||
Schedule []Query
|
||||
Options Options `json:"options,omitempty"`
|
||||
Decorators Decorators `json:"decorators,omitempty"`
|
||||
Packs Packs `json:"packs,omitempty"`
|
||||
}
|
||||
|
||||
type OsqueryResultLog struct {
|
||||
@ -46,12 +81,3 @@ type OsqueryStatusLog struct {
|
||||
Version string `json:"version"`
|
||||
Decorations map[string]string `json:"decorations"`
|
||||
}
|
||||
|
||||
// TODO: move this to just use LabelQueriesForHot
|
||||
// LabelQueriesForHost calculates the appropriate update cutoff (given
|
||||
// interval) and uses the datastore to retrieve the label queries for the
|
||||
// provided host.
|
||||
func LabelQueriesForHost(store OsqueryStore, host *Host, interval time.Duration) (map[string]string, error) {
|
||||
cutoff := time.Now().Add(-interval)
|
||||
return store.LabelQueriesForHost(host, cutoff)
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ func (svc service) EnrollAgent(ctx context.Context, enrollSecret, hostIdentifier
|
||||
return host.NodeKey, nil
|
||||
}
|
||||
|
||||
func (svc service) GetClientConfig(ctx context.Context, action string, data json.RawMessage) (kolide.OsqueryConfig, error) {
|
||||
func (svc service) GetClientConfig(ctx context.Context, action string, data json.RawMessage) (*kolide.OsqueryConfig, error) {
|
||||
var config kolide.OsqueryConfig
|
||||
return config, nil
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func (svc service) SubmitStatusLogs(ctx context.Context, logs []kolide.OsqueryResultLog) error {
|
||||
|
Loading…
Reference in New Issue
Block a user