fleet/server/service/trigger.go

33 lines
654 B
Go
Raw Normal View History

2022-11-28 19:28:06 +00:00
package service
import (
"context"
"github.com/fleetdm/fleet/v4/server/fleet"
)
type triggerRequest struct {
2022-12-06 15:56:54 +00:00
Name string `query:"name,optional"`
2022-11-28 19:28:06 +00:00
}
type triggerResponse struct {
2022-11-28 19:28:06 +00:00
Err error `json:"error,omitempty"`
}
func (r triggerResponse) error() error { return r.Err }
2022-11-28 19:28:06 +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 {
return triggerResponse{Err: err}, nil
2022-11-28 19:28:06 +00:00
}
req := request.(*triggerRequest)
2022-11-28 19:28:06 +00:00
err = svc.TriggerCronSchedule(ctx, req.Name)
if err != nil {
return triggerResponse{Err: err}, nil
2022-11-28 19:28:06 +00:00
}
return triggerResponse{}, nil
2022-11-28 19:28:06 +00:00
}