fleet/server/service/service.go

91 lines
2.4 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 (
"html/template"
"net/http"
"strings"
"time"
"github.com/WatchBeam/clock"
kitlog "github.com/go-kit/kit/log"
2017-06-22 19:50:45 +00:00
"github.com/kolide/fleet/server/config"
"github.com/kolide/fleet/server/kolide"
"github.com/kolide/fleet/server/logging"
2017-06-22 19:50:45 +00:00
"github.com/kolide/fleet/server/sso"
"github.com/kolide/kit/version"
"github.com/pkg/errors"
)
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, config config.KolideConfig, mailService kolide.MailService,
c clock.Clock, sso sso.SessionStore, lq kolide.LiveQueryStore) (kolide.Service, error) {
2016-08-28 03:59:17 +00:00
var svc kolide.Service
osqueryLogger, err := logging.New(config, logger)
if err != nil {
return nil, errors.Wrap(err, "initializing osquery logging")
}
2016-08-28 03:59:17 +00:00
svc = service{
ds: ds,
resultStore: resultStore,
liveQueryStore: lq,
logger: logger,
config: config,
clock: c,
osqueryLogWriter: osqueryLogger,
mailService: mailService,
ssoSessionStore: sso,
metaDataClient: &http.Client{
Timeout: 5 * time.Second,
},
2016-08-28 03:59:17 +00:00
}
svc = validationMiddleware{svc, ds, sso}
2016-08-28 03:59:17 +00:00
return svc, nil
}
type service struct {
ds kolide.Datastore
resultStore kolide.QueryResultStore
liveQueryStore kolide.LiveQueryStore
logger kitlog.Logger
config config.KolideConfig
clock clock.Clock
osqueryLogWriter *logging.OsqueryLogger
mailService kolide.MailService
ssoSessionStore sso.SessionStore
metaDataClient *http.Client
}
func (s service) SendEmail(mail kolide.Email) error {
return s.mailService.SendEmail(mail)
}
func (s service) Clock() clock.Clock {
return s.clock
}
type validationMiddleware struct {
kolide.Service
ds kolide.Datastore
ssoSessionStore sso.SessionStore
}
// getAssetURL gets the URL prefix used for retrieving assets from Github. This
// function will determine the appropriate version to use, and create a URL
// prefix for retrieving assets from that tag.
func getAssetURL() template.URL {
v := version.Version().Version
tag := strings.Split(v, "-")[0]
if tag == "unknown" {
tag = "master"
}
return template.URL("https://github.com/kolide/fleet/blob/" + tag)
}