2016-09-26 18:48:55 +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"
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/config"
|
|
|
|
"github.com/kolide/kolide-ose/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-09-21 03:08:11 +00:00
|
|
|
func NewService(ds kolide.Datastore, 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-09-14 16:11:06 +00:00
|
|
|
ds: ds,
|
|
|
|
logger: logger,
|
|
|
|
config: kolideConfig,
|
2016-09-21 03:08:11 +00:00
|
|
|
clock: c,
|
2016-09-14 16:11:06 +00:00
|
|
|
|
|
|
|
osqueryStatusLogWriter: logFile(kolideConfig.Osquery.StatusLogFile),
|
|
|
|
osqueryResultsLogWriter: logFile(kolideConfig.Osquery.ResultLogFile),
|
2016-09-15 14:52:17 +00:00
|
|
|
mailService: mailService,
|
2016-08-28 03:59:17 +00:00
|
|
|
}
|
|
|
|
svc = validationMiddleware{svc}
|
|
|
|
return svc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type service struct {
|
2016-09-01 04:51:38 +00:00
|
|
|
ds kolide.Datastore
|
|
|
|
logger kitlog.Logger
|
2016-09-14 16:11:06 +00:00
|
|
|
config config.KolideConfig
|
2016-09-21 03:08:11 +00:00
|
|
|
clock clock.Clock
|
2016-09-01 04:51:38 +00:00
|
|
|
|
2016-09-04 05:13:42 +00:00
|
|
|
osqueryStatusLogWriter io.Writer
|
|
|
|
osqueryResultsLogWriter io.Writer
|
2016-09-15 14:52:17 +00:00
|
|
|
|
|
|
|
mailService kolide.MailService
|
2016-09-01 04:51:38 +00:00
|
|
|
}
|