mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
152 lines
3.1 KiB
Go
152 lines
3.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/kolide/fleet/server/kolide"
|
|
)
|
|
|
|
func (mw loggingMiddleware) ListPacks(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Pack, error) {
|
|
var (
|
|
packs []*kolide.Pack
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "ListPacks",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
packs, err = mw.Service.ListPacks(ctx, opt)
|
|
return packs, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) GetPack(ctx context.Context, id uint) (*kolide.Pack, error) {
|
|
var (
|
|
pack *kolide.Pack
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "GetPack",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
pack, err = mw.Service.GetPack(ctx, id)
|
|
return pack, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) DeletePack(ctx context.Context, name string) error {
|
|
var (
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "DeletePack",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
err = mw.Service.DeletePack(ctx, name)
|
|
return err
|
|
}
|
|
|
|
func (mw loggingMiddleware) ListLabelsForPack(ctx context.Context, pid uint) ([]*kolide.Label, error) {
|
|
var (
|
|
labels []*kolide.Label
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "ListLabelsForPack",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
labels, err = mw.Service.ListLabelsForPack(ctx, pid)
|
|
return labels, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) ListPacksForHost(ctx context.Context, hid uint) ([]*kolide.Pack, error) {
|
|
var (
|
|
packs []*kolide.Pack
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "ListPacksForHost",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
packs, err = mw.Service.ListPacksForHost(ctx, hid)
|
|
return packs, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) ListHostsInPack(ctx context.Context, pid uint, opt kolide.ListOptions) ([]uint, error) {
|
|
var (
|
|
hosts []uint
|
|
err error
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
_ = mw.logger.Log(
|
|
"method", "ListHostsInPack",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
|
|
hosts, err = mw.Service.ListHostsInPack(ctx, pid, opt)
|
|
return hosts, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) GetPackSpec(ctx context.Context, name string) (spec *kolide.PackSpec, err error) {
|
|
defer func(begin time.Time) {
|
|
mw.logger.Log(
|
|
"method", "GetPackSpec",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
spec, err = mw.Service.GetPackSpec(ctx, name)
|
|
return spec, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) GetPackSpecs(ctx context.Context) (specs []*kolide.PackSpec, err error) {
|
|
defer func(begin time.Time) {
|
|
mw.logger.Log(
|
|
"method", "GetPackSpecs",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
specs, err = mw.Service.GetPackSpecs(ctx)
|
|
return specs, err
|
|
}
|
|
|
|
func (mw loggingMiddleware) ApplyPackSpecs(ctx context.Context, specs []*kolide.PackSpec) (err error) {
|
|
defer func(begin time.Time) {
|
|
mw.logger.Log(
|
|
"method", "ApplyPackSpecs",
|
|
"err", err,
|
|
"took", time.Since(begin),
|
|
)
|
|
}(time.Now())
|
|
err = mw.Service.ApplyPackSpecs(ctx, specs)
|
|
return err
|
|
}
|