2016-08-19 18:24:59 +00:00
|
|
|
package kolide
|
2016-10-03 03:14:35 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-10-03 03:14:35 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LabelStore interface {
|
|
|
|
// Label methods
|
|
|
|
NewLabel(Label *Label) (*Label, error)
|
|
|
|
DeleteLabel(lid uint) error
|
|
|
|
Label(lid uint) (*Label, error)
|
2016-10-14 15:59:27 +00:00
|
|
|
ListLabels(opt ListOptions) ([]*Label, error)
|
2016-10-03 03:14:35 +00:00
|
|
|
|
|
|
|
// LabelQueriesForHost returns the label queries that should be executed
|
|
|
|
// for the given host. The cutoff is the minimum timestamp a query
|
|
|
|
// execution should have to be considered "fresh". Executions that are
|
|
|
|
// not fresh will be repeated. Results are returned in a map of label
|
|
|
|
// id -> query
|
|
|
|
LabelQueriesForHost(host *Host, cutoff time.Time) (map[string]string, error)
|
|
|
|
|
|
|
|
// RecordLabelQueryExecutions saves the results of label queries. The
|
|
|
|
// results map is a map of label id -> whether or not the label
|
|
|
|
// matches. The time parameter is the timestamp to save with the query
|
|
|
|
// execution.
|
2017-01-17 06:03:51 +00:00
|
|
|
RecordLabelQueryExecutions(host *Host, results map[uint]bool, t time.Time) error
|
2016-10-03 03:14:35 +00:00
|
|
|
|
|
|
|
// LabelsForHost returns the labels that the given host is in.
|
2016-10-14 15:59:27 +00:00
|
|
|
ListLabelsForHost(hid uint) ([]Label, error)
|
2016-11-02 14:59:53 +00:00
|
|
|
|
2017-02-17 19:19:27 +00:00
|
|
|
// ListHostsInLabel returns a slice of hosts in the label with the
|
|
|
|
// given ID.
|
2016-11-02 14:59:53 +00:00
|
|
|
ListHostsInLabel(lid uint) ([]Host, error)
|
2017-02-17 19:19:27 +00:00
|
|
|
|
|
|
|
// ListUniqueHostsInLabels returns a slice of all of the hosts in the
|
|
|
|
// given label IDs. A host will only appear once in the results even if
|
|
|
|
// it is in multiple of the provided labels.
|
2016-11-02 14:59:53 +00:00
|
|
|
ListUniqueHostsInLabels(labels []uint) ([]Host, error)
|
|
|
|
|
2016-11-16 13:47:49 +00:00
|
|
|
SearchLabels(query string, omit ...uint) ([]Label, error)
|
2017-02-12 04:27:43 +00:00
|
|
|
|
|
|
|
// SaveLabel allows modification of a label's name and/or description
|
|
|
|
SaveLabel(label *Label) (*Label, error)
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LabelService interface {
|
2017-01-10 04:40:21 +00:00
|
|
|
ListLabels(ctx context.Context, opt ListOptions) (labels []*Label, err error)
|
|
|
|
GetLabel(ctx context.Context, id uint) (label *Label, err error)
|
|
|
|
NewLabel(ctx context.Context, p LabelPayload) (label *Label, err error)
|
|
|
|
DeleteLabel(ctx context.Context, id uint) (err error)
|
2017-02-12 04:27:43 +00:00
|
|
|
|
|
|
|
// ModifyLabel is used to change editable fields belonging to a Label
|
|
|
|
ModifyLabel(ctx context.Context, id uint, payload ModifyLabelPayload) (*Label, error)
|
|
|
|
|
2017-01-16 22:57:05 +00:00
|
|
|
// HostIDsForLabel returns ids of hosts that belong to the label identified
|
|
|
|
// by lid
|
|
|
|
HostIDsForLabel(lid uint) ([]uint, error)
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 04:27:43 +00:00
|
|
|
// ModifyLabelPayload is used to change editable fields for a Label
|
|
|
|
type ModifyLabelPayload struct {
|
|
|
|
Name *string `json:"name"`
|
|
|
|
Description *string `json:"description"`
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
type LabelPayload struct {
|
2016-11-18 00:51:30 +00:00
|
|
|
Name *string `json:"name"`
|
2016-11-03 01:17:23 +00:00
|
|
|
Query *string `json:"query"`
|
|
|
|
Platform *string `json:"platform"`
|
|
|
|
Description *string `json:"description"`
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-25 18:08:22 +00:00
|
|
|
// LabelType is used to catagorize the kind of label
|
|
|
|
type LabelType uint
|
|
|
|
|
|
|
|
const (
|
2017-01-09 20:02:21 +00:00
|
|
|
// LabelTypeRegular is for user created labels that can be modified.
|
|
|
|
LabelTypeRegular LabelType = iota
|
|
|
|
// LabelTypeBuiltIn is for labels built into Kolide that cannot be
|
|
|
|
// modified by users.
|
2016-11-25 18:08:22 +00:00
|
|
|
LabelTypeBuiltIn
|
|
|
|
)
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
type Label struct {
|
2016-11-16 13:47:49 +00:00
|
|
|
UpdateCreateTimestamps
|
|
|
|
DeleteFields
|
2016-11-25 18:08:22 +00:00
|
|
|
ID uint `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
Platform string `json:"platform"`
|
|
|
|
LabelType LabelType `json:"label_type" db:"label_type"`
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LabelQueryExecution struct {
|
2016-11-16 13:47:49 +00:00
|
|
|
ID uint
|
2016-10-03 03:14:35 +00:00
|
|
|
UpdatedAt time.Time
|
|
|
|
Matches bool
|
2016-11-16 13:47:49 +00:00
|
|
|
LabelID uint
|
|
|
|
HostID uint
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|