mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
f109b14f9d
* Moving query attributes from the query object to the pack-query relationship * some additional tests * http request parsing test * QueryOptions in new test_util code * initial scaffolding of new request structures * service and datastore * test outline * l2 merge conflict scrub * service tests for scheduled query service * service and datastore tests * most endpoints and transports * order of values are not deterministic with inmem * transport tests * rename PackQuery to ScheduledQuery * removing existing implementation of adding queries to packs * accounting for the new argument to NewQuery * fix alignment in sql query * removing underscore * add removed to the datastore * removed differential from the schema
87 lines
1.6 KiB
Go
87 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/kolide/kolide-ose/server/contexts/viewer"
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (svc service) ListQueries(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Query, error) {
|
|
return svc.ds.ListQueries(opt)
|
|
}
|
|
|
|
func (svc service) GetQuery(ctx context.Context, id uint) (*kolide.Query, error) {
|
|
return svc.ds.Query(id)
|
|
}
|
|
|
|
func (svc service) NewQuery(ctx context.Context, p kolide.QueryPayload) (*kolide.Query, error) {
|
|
query := &kolide.Query{Saved: true}
|
|
|
|
if p.Name != nil {
|
|
query.Name = *p.Name
|
|
}
|
|
|
|
if p.Description != nil {
|
|
query.Description = *p.Description
|
|
}
|
|
|
|
if p.Query != nil {
|
|
query.Query = *p.Query
|
|
}
|
|
|
|
vc, ok := viewer.FromContext(ctx)
|
|
if ok {
|
|
query.AuthorID = vc.UserID()
|
|
}
|
|
|
|
query, err := svc.ds.NewQuery(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return query, nil
|
|
}
|
|
|
|
func (svc service) ModifyQuery(ctx context.Context, id uint, p kolide.QueryPayload) (*kolide.Query, error) {
|
|
query, err := svc.ds.Query(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if p.Name != nil {
|
|
query.Name = *p.Name
|
|
}
|
|
|
|
if p.Description != nil {
|
|
query.Description = *p.Description
|
|
}
|
|
|
|
if p.Query != nil {
|
|
query.Query = *p.Query
|
|
}
|
|
|
|
err = svc.ds.SaveQuery(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return query, nil
|
|
}
|
|
|
|
func (svc service) DeleteQuery(ctx context.Context, id uint) error {
|
|
query, err := svc.ds.Query(id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = svc.ds.DeleteQuery(query)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (svc service) DeleteQueries(ctx context.Context, ids []uint) (uint, error) {
|
|
return svc.ds.DeleteQueries(ids)
|
|
}
|