2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-04 05:13:42 +00:00
|
|
|
|
|
|
|
import (
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
2016-09-04 05:13:42 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
func (svc service) ListPacks(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Pack, error) {
|
2016-10-14 15:59:27 +00:00
|
|
|
return svc.ds.ListPacks(opt)
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) GetPack(ctx context.Context, id uint) (*kolide.Pack, error) {
|
|
|
|
return svc.ds.Pack(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) NewPack(ctx context.Context, p kolide.PackPayload) (*kolide.Pack, error) {
|
|
|
|
var pack kolide.Pack
|
|
|
|
|
|
|
|
if p.Name != nil {
|
|
|
|
pack.Name = *p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Platform != nil {
|
|
|
|
pack.Platform = *p.Platform
|
|
|
|
}
|
|
|
|
|
|
|
|
err := svc.ds.NewPack(&pack)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pack, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) ModifyPack(ctx context.Context, id uint, p kolide.PackPayload) (*kolide.Pack, error) {
|
|
|
|
pack, err := svc.ds.Pack(id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Name != nil {
|
|
|
|
pack.Name = *p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Platform != nil {
|
|
|
|
pack.Platform = *p.Platform
|
|
|
|
}
|
|
|
|
|
|
|
|
err = svc.ds.SavePack(pack)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return pack, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) DeletePack(ctx context.Context, id uint) error {
|
2016-10-03 03:14:35 +00:00
|
|
|
return svc.ds.DeletePack(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) AddQueryToPack(ctx context.Context, qid, pid uint) error {
|
|
|
|
return svc.ds.AddQueryToPack(qid, pid)
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
func (svc service) ListQueriesInPack(ctx context.Context, id uint) ([]*kolide.Query, error) {
|
2016-09-04 05:13:42 +00:00
|
|
|
pack, err := svc.ds.Pack(id)
|
|
|
|
if err != nil {
|
2016-10-03 03:14:35 +00:00
|
|
|
return nil, err
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
queries, err := svc.ds.ListQueriesInPack(pack)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
2016-10-03 03:14:35 +00:00
|
|
|
return nil, err
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
return queries, nil
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
func (svc service) RemoveQueryFromPack(ctx context.Context, qid, pid uint) error {
|
2016-09-04 05:13:42 +00:00
|
|
|
pack, err := svc.ds.Pack(pid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
query, err := svc.ds.Query(qid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
err = svc.ds.RemoveQueryFromPack(query, pack)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-10-03 03:14:35 +00:00
|
|
|
func (svc service) AddLabelToPack(ctx context.Context, lid, pid uint) error {
|
|
|
|
return svc.ds.AddLabelToPack(lid, pid)
|
|
|
|
}
|
2016-09-04 05:13:42 +00:00
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
func (svc service) ListLabelsForPack(ctx context.Context, pid uint) ([]*kolide.Label, error) {
|
2016-10-03 03:14:35 +00:00
|
|
|
pack, err := svc.ds.Pack(pid)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
labels, err := svc.ds.ListLabelsForPack(pack)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
return labels, nil
|
2016-09-04 05:13:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
func (svc service) RemoveLabelFromPack(ctx context.Context, lid, pid uint) error {
|
2016-09-04 05:13:42 +00:00
|
|
|
pack, err := svc.ds.Pack(pid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
label, err := svc.ds.Label(lid)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
err = svc.ds.RemoveLabelFromPack(label, pack)
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|