2016-10-03 03:14:35 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2016-10-03 03:14:35 +00:00
|
|
|
)
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
func (svc service) ListLabels(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Label, error) {
|
2016-10-14 15:59:27 +00:00
|
|
|
return svc.ds.ListLabels(opt)
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) GetLabel(ctx context.Context, id uint) (*kolide.Label, error) {
|
|
|
|
return svc.ds.Label(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) NewLabel(ctx context.Context, p kolide.LabelPayload) (*kolide.Label, error) {
|
|
|
|
label := &kolide.Label{}
|
|
|
|
|
|
|
|
if p.Name == nil {
|
|
|
|
return nil, newInvalidArgumentError("name", "missing required argument")
|
|
|
|
}
|
|
|
|
label.Name = *p.Name
|
|
|
|
|
2016-11-03 01:17:23 +00:00
|
|
|
if p.Query == nil {
|
|
|
|
return nil, newInvalidArgumentError("query", "missing required argument")
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
2016-11-03 01:17:23 +00:00
|
|
|
label.Query = *p.Query
|
2016-10-03 03:14:35 +00:00
|
|
|
|
2016-11-03 01:17:23 +00:00
|
|
|
if p.Platform != nil {
|
|
|
|
label.Platform = *p.Platform
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 01:17:23 +00:00
|
|
|
if p.Description != nil {
|
|
|
|
label.Description = *p.Description
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 01:17:23 +00:00
|
|
|
label, err := svc.ds.NewLabel(label)
|
2016-10-03 03:14:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return label, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc service) DeleteLabel(ctx context.Context, id uint) error {
|
|
|
|
return svc.ds.DeleteLabel(id)
|
|
|
|
}
|
2017-01-16 22:57:05 +00:00
|
|
|
|
|
|
|
func (svc service) HostIDsForLabel(lid uint) ([]uint, error) {
|
|
|
|
hosts, err := svc.ds.ListHostsInLabel(lid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var ids []uint
|
|
|
|
for _, h := range hosts {
|
|
|
|
ids = append(ids, h.ID)
|
|
|
|
}
|
|
|
|
return ids, nil
|
|
|
|
}
|
2017-02-12 04:27:43 +00:00
|
|
|
|
|
|
|
func (svc service) ModifyLabel(ctx context.Context, id uint, payload kolide.ModifyLabelPayload) (*kolide.Label, error) {
|
|
|
|
label, err := svc.ds.Label(id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if payload.Name != nil {
|
|
|
|
label.Name = *payload.Name
|
|
|
|
}
|
|
|
|
if payload.Description != nil {
|
|
|
|
label.Description = *payload.Description
|
|
|
|
}
|
|
|
|
return svc.ds.SaveLabel(label)
|
|
|
|
}
|