mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/kolide/fleet/server/kolide"
|
|
)
|
|
|
|
type optionsResponse struct {
|
|
Options []kolide.Option `json:"options,omitempty"`
|
|
Err error `json:"error,omitempty"`
|
|
}
|
|
|
|
func (or optionsResponse) error() error { return or.Err }
|
|
|
|
func makeGetOptionsEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
options, err := svc.GetOptions(ctx)
|
|
if err != nil {
|
|
return optionsResponse{Err: err}, nil
|
|
}
|
|
return optionsResponse{Options: options}, nil
|
|
}
|
|
}
|
|
|
|
func makeModifyOptionsEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
payload := request.(kolide.OptionRequest)
|
|
opts, err := svc.ModifyOptions(ctx, payload)
|
|
if err != nil {
|
|
return optionsResponse{Err: err}, nil
|
|
}
|
|
return optionsResponse{Options: opts}, nil
|
|
}
|
|
}
|
|
|
|
func makeResetOptionsEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
options, err := svc.ResetOptions(ctx)
|
|
if err != nil {
|
|
return optionsResponse{Err: err}, nil
|
|
}
|
|
return optionsResponse{Options: options}, nil
|
|
}
|
|
}
|