fleet/kolide/queries.go
Mike Arpaia 53a1fe8d84 queries and packs services via go-kit (#102)
* osquery services via go-kit

* Visual Studio Code configurations

* create query and pack endpoints

* organizing files more scalably

* modify query and pack endpoints

* delete query and pack endpoints

* get query and pack endpoints

* get all queries and packs endpoints

* add and remove queries from packs

* test stubs

* removing some indirection

* query service tests

* service pack tests

* transport tests

* adding config file flag back

* organizing package kolide

* get queries in pack endpoint

* run tests on 1.7?

* no 1.7 image :(

* typo in circle.yml
2016-09-04 01:13:42 -04:00

152 lines
3.4 KiB
Go

package kolide
import (
"time"
"golang.org/x/net/context"
)
type QueryStore interface {
// Query methods
NewQuery(query *Query) error
SaveQuery(query *Query) error
DeleteQuery(query *Query) error
Query(id uint) (*Query, error)
Queries() ([]*Query, error)
}
type QueryService interface {
GetAllQueries(ctx context.Context) ([]*Query, error)
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
}
type QueryPayload struct {
Name *string
Query *string
Interval *uint
Snapshot *bool
Differential *bool
Platform *string
Version *string
}
type PackPayload struct {
Name *string
Platform *string
}
type Query struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
Name string `gorm:"not null;unique_index:idx_query_unique_name"`
Query string `gorm:"not null"`
Interval uint
Snapshot bool
Differential bool
Platform string
Version string
}
type Label struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
Name string `gorm:"not null;unique_index:idx_label_unique_name"`
QueryID uint
}
type LabelQueryExecution struct {
ID uint `gorm:"primary_key"`
UpdatedAt time.Time
Matches bool
LabelID uint // Note we manually specify a unique index on these
HostID uint // fields in gormDB.Migrate
}
type TargetType int
const (
TargetLabel TargetType = iota
TargetHost TargetType = iota
)
type Target struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
Type TargetType
TargetID uint
QueryID uint
}
type DistributedQueryStatus int
const (
QueryRunning DistributedQueryStatus = iota
QueryComplete DistributedQueryStatus = iota
QueryError DistributedQueryStatus = iota
)
type DistributedQueryCampaign struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
QueryID uint
MaxDuration time.Duration
Status DistributedQueryStatus
UserID uint
}
type DistributedQueryCampaignTarget struct {
ID uint `gorm:"primary_key"`
DistributedQueryCampaignID uint
TargetID uint
}
type DistributedQueryExecutionStatus int
const (
ExecutionWaiting DistributedQueryExecutionStatus = iota
ExecutionRequested DistributedQueryExecutionStatus = iota
ExecutionSucceeded DistributedQueryExecutionStatus = iota
ExecutionFailed DistributedQueryExecutionStatus = iota
)
type DistributedQueryExecution struct {
HostID uint
DistributedQueryID uint
Status DistributedQueryExecutionStatus
Error string `gorm:"size:1024"`
ExecutionDuration time.Duration
}
type Option struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
Key string `gorm:"not null;unique_index:idx_option_unique_key"`
Value string `gorm:"not null"`
Platform string
}
type DecoratorType int
const (
DecoratorLoad DecoratorType = iota
DecoratorAlways DecoratorType = iota
DecoratorInterval DecoratorType = iota
)
type Decorator struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
Type DecoratorType `gorm:"not null"`
Interval int
Query string
}