mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
19ad7cc637
* Set interface for response types * Fix TestEndpointer test
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Status Result Store
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type statusResponse struct {
|
|
Err error `json:"error,omitempty"`
|
|
}
|
|
|
|
func (m statusResponse) error() error { return m.Err }
|
|
|
|
func statusResultStoreEndpoint(ctx context.Context, req interface{}, svc fleet.Service) (errorer, error) {
|
|
var resp statusResponse
|
|
if err := svc.StatusResultStore(ctx); err != nil {
|
|
resp.Err = err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (svc *Service) StatusResultStore(ctx context.Context) error {
|
|
if err := svc.authz.Authorize(ctx, &fleet.AppConfig{}, fleet.ActionRead); err != nil {
|
|
return err
|
|
}
|
|
|
|
return svc.resultStore.HealthCheck()
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Status Live Query
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
func statusLiveQueryEndpoint(ctx context.Context, req interface{}, svc fleet.Service) (errorer, error) {
|
|
var resp statusResponse
|
|
if err := svc.StatusLiveQuery(ctx); err != nil {
|
|
resp.Err = err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (svc *Service) StatusLiveQuery(ctx context.Context) error {
|
|
if err := svc.authz.Authorize(ctx, &fleet.AppConfig{}, fleet.ActionRead); err != nil {
|
|
return err
|
|
}
|
|
|
|
cfg, err := svc.ds.AppConfig(ctx)
|
|
if err != nil {
|
|
return ctxerr.Wrap(ctx, err, "retrieve app config")
|
|
}
|
|
|
|
if cfg.ServerSettings.LiveQueryDisabled {
|
|
return ctxerr.New(ctx, "disabled by administrator")
|
|
}
|
|
|
|
return svc.StatusResultStore(ctx)
|
|
}
|