2016-09-04 05:13:42 +00:00
|
|
|
package kolide
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QueryStore interface {
|
2016-12-06 18:22:28 +00:00
|
|
|
// NewQuery creates a new query object in thie datastore. The returned
|
|
|
|
// query should have the ID updated.
|
2016-09-30 01:19:51 +00:00
|
|
|
NewQuery(query *Query) (*Query, error)
|
2016-12-06 18:22:28 +00:00
|
|
|
// SaveQuery saves changes to an existing query object.
|
2016-09-04 05:13:42 +00:00
|
|
|
SaveQuery(query *Query) error
|
2016-12-06 18:22:28 +00:00
|
|
|
// DeleteQuery (soft) deletes an existing query object.
|
2017-01-04 18:18:21 +00:00
|
|
|
DeleteQuery(qid uint) error
|
2016-12-09 17:12:45 +00:00
|
|
|
// DeleteQueries (soft) deletes the existing query objects with the
|
|
|
|
// provided IDs. The number of deleted queries is returned along with
|
|
|
|
// any error.
|
|
|
|
DeleteQueries(ids []uint) (uint, error)
|
2016-12-06 18:22:28 +00:00
|
|
|
// Query returns the query associated with the provided ID. Associated
|
|
|
|
// packs should also be loaded.
|
2016-09-04 05:13:42 +00:00
|
|
|
Query(id uint) (*Query, error)
|
2016-12-06 18:22:28 +00:00
|
|
|
// ListQueries returns a list of queries with the provided sorting and
|
|
|
|
// paging options. Associated packs should also be loaded.
|
2016-10-14 15:59:27 +00:00
|
|
|
ListQueries(opt ListOptions) ([]*Query, error)
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryService interface {
|
2016-12-06 18:16:04 +00:00
|
|
|
// ListQueries returns a list of saved queries. Note only saved queries
|
|
|
|
// should be returned (those that are created for distributed queries
|
|
|
|
// but not saved should not be returned).
|
2016-10-13 18:21:47 +00:00
|
|
|
ListQueries(ctx context.Context, opt ListOptions) ([]*Query, error)
|
2016-09-04 05:13:42 +00:00
|
|
|
GetQuery(ctx context.Context, id uint) (*Query, error)
|
|
|
|
NewQuery(ctx context.Context, p QueryPayload) (*Query, error)
|
|
|
|
ModifyQuery(ctx context.Context, id uint, p QueryPayload) (*Query, error)
|
|
|
|
DeleteQuery(ctx context.Context, id uint) error
|
2016-12-09 17:12:45 +00:00
|
|
|
// DeleteQueries (soft) deletes the existing query objects with the
|
|
|
|
// provided IDs. The number of deleted queries is returned along with
|
|
|
|
// any error.
|
|
|
|
DeleteQueries(ctx context.Context, ids []uint) (uint, error)
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryPayload struct {
|
2016-12-13 22:22:05 +00:00
|
|
|
Name *string
|
|
|
|
Description *string
|
|
|
|
Query *string
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Query struct {
|
2016-11-16 13:47:49 +00:00
|
|
|
UpdateCreateTimestamps
|
|
|
|
DeleteFields
|
2016-12-13 22:22:05 +00:00
|
|
|
ID uint `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
Saved bool `json:"saved"`
|
|
|
|
AuthorID uint `json:"author_id" db:"author_id"`
|
2016-12-07 20:22:31 +00:00
|
|
|
// AuthorName is retrieved with a join to the users table in the MySQL
|
|
|
|
// backend (using AuthorID)
|
|
|
|
AuthorName string `json:"author_name" db:"author_name"`
|
2016-12-06 18:22:28 +00:00
|
|
|
// Packs is loaded when retrieving queries, but is stored in a join
|
|
|
|
// table in the MySQL backend.
|
|
|
|
Packs []Pack `json:"packs" db:"-"`
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DecoratorType int
|
|
|
|
|
|
|
|
const (
|
2016-10-03 03:14:35 +00:00
|
|
|
DecoratorLoad DecoratorType = iota
|
|
|
|
DecoratorAlways
|
|
|
|
DecoratorInterval
|
2016-09-04 05:13:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Decorator struct {
|
2016-11-16 13:47:49 +00:00
|
|
|
ID uint
|
2016-09-04 05:13:42 +00:00
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
2016-11-16 13:47:49 +00:00
|
|
|
Type DecoratorType
|
2016-09-04 05:13:42 +00:00
|
|
|
Interval int
|
|
|
|
Query string
|
|
|
|
}
|