2017-01-10 04:40:21 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2017-01-10 04:40:21 +00:00
|
|
|
"time"
|
|
|
|
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2017-01-10 04:40:21 +00:00
|
|
|
)
|
|
|
|
|
2018-06-18 17:09:08 +00:00
|
|
|
func (mw loggingMiddleware) NewLabel(ctx context.Context, p kolide.LabelPayload) (*kolide.Label, error) {
|
|
|
|
var (
|
|
|
|
label *kolide.Label
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "NewLabel",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
label, err = mw.Service.NewLabel(ctx, p)
|
|
|
|
return label, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) ModifyLabel(ctx context.Context, id uint, p kolide.ModifyLabelPayload) (*kolide.Label, error) {
|
|
|
|
var (
|
|
|
|
label *kolide.Label
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
mw.logger.Log(
|
|
|
|
"method", "ModifyLabel",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
label, err = mw.Service.ModifyLabel(ctx, id, p)
|
|
|
|
return label, err
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:40:21 +00:00
|
|
|
func (mw loggingMiddleware) ListLabels(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Label, error) {
|
|
|
|
var (
|
|
|
|
labels []*kolide.Label
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "ListLabels",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
labels, err = mw.Service.ListLabels(ctx, opt)
|
|
|
|
return labels, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) GetLabel(ctx context.Context, id uint) (*kolide.Label, error) {
|
|
|
|
var (
|
|
|
|
label *kolide.Label
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "GetLabel",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
label, err = mw.Service.GetLabel(ctx, id)
|
|
|
|
return label, err
|
|
|
|
}
|
|
|
|
|
2018-05-04 18:05:55 +00:00
|
|
|
func (mw loggingMiddleware) DeleteLabel(ctx context.Context, name string) error {
|
2017-01-10 04:40:21 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "DeleteLabel",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
2018-05-04 18:05:55 +00:00
|
|
|
err = mw.Service.DeleteLabel(ctx, name)
|
2017-01-10 04:40:21 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-05-09 18:00:48 +00:00
|
|
|
|
|
|
|
func (mw loggingMiddleware) GetLabelSpec(ctx context.Context, name string) (spec *kolide.LabelSpec, err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
mw.logger.Log(
|
|
|
|
"method", "GetLabelSpec",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
spec, err = mw.Service.GetLabelSpec(ctx, name)
|
|
|
|
return spec, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) GetLabelSpecs(ctx context.Context) (specs []*kolide.LabelSpec, err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
mw.logger.Log(
|
|
|
|
"method", "GetLabelSpecs",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
specs, err = mw.Service.GetLabelSpecs(ctx)
|
|
|
|
return specs, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) ApplyLabelSpecs(ctx context.Context, specs []*kolide.LabelSpec) (err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
mw.logger.Log(
|
|
|
|
"method", "ApplyLabelSpecs",
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
err = mw.Service.ApplyLabelSpecs(ctx, specs)
|
|
|
|
return err
|
|
|
|
}
|