2016-09-05 20:03:58 +00:00
|
|
|
// package server 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-05 20:03:58 +00:00
|
|
|
package server
|
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-01 04:51:38 +00:00
|
|
|
kitlog "github.com/go-kit/kit/log"
|
2016-09-14 16:11:06 +00:00
|
|
|
"github.com/kolide/kolide-ose/config"
|
2016-09-01 04:51:38 +00:00
|
|
|
"github.com/kolide/kolide-ose/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
|
|
|
|
|
|
|
// configuration defaults
|
2016-09-01 04:51:38 +00:00
|
|
|
// TODO move to main?
|
2016-08-28 03:59:17 +00:00
|
|
|
const (
|
2016-09-15 14:52:17 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
// NewService creates a new service from the config struct
|
2016-09-15 14:52:17 +00:00
|
|
|
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
|
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,
|
|
|
|
|
|
|
|
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-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
|
|
|
}
|