2022-11-28 19:28:06 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
)
|
|
|
|
|
2022-11-30 17:57:42 +00:00
|
|
|
type triggerRequest struct {
|
2022-12-06 15:56:54 +00:00
|
|
|
Name string `query:"name,optional"`
|
2022-11-28 19:28:06 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:57:42 +00:00
|
|
|
type triggerResponse struct {
|
2022-11-28 19:28:06 +00:00
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
2022-11-30 17:57:42 +00:00
|
|
|
func (r triggerResponse) error() error { return r.Err }
|
2022-11-28 19:28:06 +00:00
|
|
|
|
2022-12-27 14:26:59 +00:00
|
|
|
func triggerEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
|
2022-11-28 19:28:06 +00:00
|
|
|
_, err := svc.AuthenticatedUser(ctx)
|
|
|
|
if err != nil {
|
2022-11-30 17:57:42 +00:00
|
|
|
return triggerResponse{Err: err}, nil
|
2022-11-28 19:28:06 +00:00
|
|
|
}
|
2022-11-30 17:57:42 +00:00
|
|
|
req := request.(*triggerRequest)
|
2022-11-28 19:28:06 +00:00
|
|
|
|
|
|
|
err = svc.TriggerCronSchedule(ctx, req.Name)
|
|
|
|
if err != nil {
|
2022-11-30 17:57:42 +00:00
|
|
|
return triggerResponse{Err: err}, nil
|
2022-11-28 19:28:06 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:57:42 +00:00
|
|
|
return triggerResponse{}, nil
|
2022-11-28 19:28:06 +00:00
|
|
|
}
|