fleet/server/service/service.go

63 lines
1.6 KiB
Go
Raw Normal View History

// Package service holds the implementation of the kolide service interface and the HTTP endpoints
// for the API
2016-09-26 18:48:55 +00:00
package service
2016-08-28 03:59:17 +00:00
import (
"io"
"github.com/WatchBeam/clock"
kitlog "github.com/go-kit/kit/log"
2017-02-01 17:20:50 +00:00
"github.com/kolide/kolide/server/config"
"github.com/kolide/kolide/server/kolide"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
2016-08-28 03:59:17 +00:00
// NewService creates a new service from the config struct
func NewService(ds kolide.Datastore, resultStore kolide.QueryResultStore, logger kitlog.Logger, kolideConfig config.KolideConfig, mailService kolide.MailService, c clock.Clock) (kolide.Service, error) {
2016-08-28 03:59:17 +00:00
var svc kolide.Service
logFile := func(path string) io.Writer {
return &lumberjack.Logger{
Filename: path,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
}
}
2016-08-28 03:59:17 +00:00
svc = service{
ds: ds,
resultStore: resultStore,
logger: logger,
config: kolideConfig,
clock: c,
osqueryStatusLogWriter: logFile(kolideConfig.Osquery.StatusLogFile),
osqueryResultLogWriter: logFile(kolideConfig.Osquery.ResultLogFile),
mailService: mailService,
2016-08-28 03:59:17 +00:00
}
svc = validationMiddleware{svc, ds}
2016-08-28 03:59:17 +00:00
return svc, nil
}
type service struct {
ds kolide.Datastore
resultStore kolide.QueryResultStore
logger kitlog.Logger
config config.KolideConfig
clock clock.Clock
osqueryStatusLogWriter io.Writer
osqueryResultLogWriter io.Writer
mailService kolide.MailService
}
func (s service) SendEmail(mail kolide.Email) error {
return s.mailService.SendEmail(mail)
}
func (s service) Clock() clock.Clock {
return s.clock
}