fleet/server/service/service_labels.go
Mike Arpaia 97de2bc5aa Label API Updates (#413)
close #403
close #404
close #412
2016-11-02 21:17:23 -04:00

47 lines
1.0 KiB
Go

package service
import (
"github.com/kolide/kolide-ose/server/kolide"
"golang.org/x/net/context"
)
func (svc service) ListLabels(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Label, error) {
return svc.ds.ListLabels(opt)
}
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
if p.Query == nil {
return nil, newInvalidArgumentError("query", "missing required argument")
}
label.Query = *p.Query
if p.Platform != nil {
label.Platform = *p.Platform
}
if p.Description != nil {
label.Description = *p.Description
}
label, err := svc.ds.NewLabel(label)
if err != nil {
return nil, err
}
return label, nil
}
func (svc service) DeleteLabel(ctx context.Context, id uint) error {
return svc.ds.DeleteLabel(id)
}