fleet/server/service.go

61 lines
1.5 KiB
Go
Raw Normal View History

// package server holds the implementation of the kolide service interface and the HTTP endpoints
// for the API
package server
2016-08-28 03:59:17 +00:00
import (
"io"
kitlog "github.com/go-kit/kit/log"
"github.com/kolide/kolide-ose/config"
"github.com/kolide/kolide-ose/kolide"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
2016-08-28 03:59:17 +00:00
// configuration defaults
// TODO move to main?
2016-08-28 03:59:17 +00:00
const (
defaultBcryptCost int = 12
defaultSaltKeySize int = 24
defaultCookieName string = "KolideSession"
defaultEnrollSecret string = "xxx change me"
defaultNodeKeySize int = 24
defaultSMTPTokenKeySize int = 24
2016-08-28 03:59:17 +00:00
)
// NewService creates a new service from the config struct
func NewService(ds kolide.Datastore, logger kitlog.Logger, kolideConfig config.KolideConfig, mailService kolide.MailService) (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,
logger: logger,
config: kolideConfig,
osqueryStatusLogWriter: logFile(kolideConfig.Osquery.StatusLogFile),
osqueryResultsLogWriter: logFile(kolideConfig.Osquery.ResultLogFile),
mailService: mailService,
2016-08-28 03:59:17 +00:00
}
svc = validationMiddleware{svc}
return svc, nil
}
type service struct {
ds kolide.Datastore
logger kitlog.Logger
config config.KolideConfig
osqueryStatusLogWriter io.Writer
osqueryResultsLogWriter io.Writer
mailService kolide.MailService
}