2016-09-29 02:44:05 +00:00
|
|
|
// Package service holds the implementation of the kolide service interface and the HTTP endpoints
|
2016-09-01 04:51:38 +00:00
|
|
|
// for the API
|
2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-08-28 03:59:17 +00:00
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
import (
|
2016-09-04 05:13:42 +00:00
|
|
|
"io"
|
|
|
|
|
2016-09-21 03:08:11 +00:00
|
|
|
"github.com/WatchBeam/clock"
|
2016-09-01 04:51:38 +00:00
|
|
|
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"
|
2016-09-04 05:13:42 +00:00
|
|
|
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
2016-09-01 04:51:38 +00:00
|
|
|
)
|
2016-08-28 03:59:17 +00:00
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
// NewService creates a new service from the config struct
|
2016-11-14 18:22:54 +00:00
|
|
|
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
|
2016-09-04 05:13:42 +00:00
|
|
|
|
|
|
|
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{
|
2016-11-14 18:22:54 +00:00
|
|
|
ds: ds,
|
|
|
|
resultStore: resultStore,
|
|
|
|
logger: logger,
|
|
|
|
config: kolideConfig,
|
|
|
|
clock: c,
|
2016-09-14 16:11:06 +00:00
|
|
|
|
2016-10-01 02:18:27 +00:00
|
|
|
osqueryStatusLogWriter: logFile(kolideConfig.Osquery.StatusLogFile),
|
|
|
|
osqueryResultLogWriter: logFile(kolideConfig.Osquery.ResultLogFile),
|
|
|
|
mailService: mailService,
|
2016-08-28 03:59:17 +00:00
|
|
|
}
|
2017-01-13 18:35:25 +00:00
|
|
|
svc = validationMiddleware{svc, ds}
|
2016-08-28 03:59:17 +00:00
|
|
|
return svc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type service struct {
|
2016-11-14 18:22:54 +00:00
|
|
|
ds kolide.Datastore
|
|
|
|
resultStore kolide.QueryResultStore
|
|
|
|
logger kitlog.Logger
|
|
|
|
config config.KolideConfig
|
|
|
|
clock clock.Clock
|
2016-09-01 04:51:38 +00:00
|
|
|
|
2016-10-01 02:18:27 +00:00
|
|
|
osqueryStatusLogWriter io.Writer
|
|
|
|
osqueryResultLogWriter io.Writer
|
2016-09-15 14:52:17 +00:00
|
|
|
|
|
|
|
mailService kolide.MailService
|
2016-09-01 04:51:38 +00:00
|
|
|
}
|
2016-12-20 21:54:30 +00:00
|
|
|
|
|
|
|
func (s service) SendEmail(mail kolide.Email) error {
|
|
|
|
return s.mailService.SendEmail(mail)
|
|
|
|
}
|
2017-01-04 21:16:17 +00:00
|
|
|
|
|
|
|
func (s service) Clock() clock.Clock {
|
|
|
|
return s.clock
|
|
|
|
}
|