fleet/server/service/trigger.go
Lucas Manuel Rodriguez 19ad7cc637
Set interface for response types (#9121)
* Set interface for response types

* Fix TestEndpointer test
2022-12-27 11:26:59 -03:00

33 lines
654 B
Go

package service
import (
"context"
"github.com/fleetdm/fleet/v4/server/fleet"
)
type triggerRequest struct {
Name string `query:"name,optional"`
}
type triggerResponse struct {
Err error `json:"error,omitempty"`
}
func (r triggerResponse) error() error { return r.Err }
func triggerEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
_, err := svc.AuthenticatedUser(ctx)
if err != nil {
return triggerResponse{Err: err}, nil
}
req := request.(*triggerRequest)
err = svc.TriggerCronSchedule(ctx, req.Name)
if err != nil {
return triggerResponse{Err: err}, nil
}
return triggerResponse{}, nil
}