package service import ( "context" "github.com/fleetdm/fleet/v4/server/fleet" ) //////////////////////////////////////////////////////////////////////////////// // Get activities //////////////////////////////////////////////////////////////////////////////// type listActivitiesRequest struct { ListOptions fleet.ListOptions `url:"list_options"` } type listActivitiesResponse struct { Meta *fleet.PaginationMetadata `json:"meta"` Activities []*fleet.Activity `json:"activities"` Err error `json:"error,omitempty"` } func (r listActivitiesResponse) error() error { return r.Err } func listActivitiesEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) { req := request.(*listActivitiesRequest) activities, metadata, err := svc.ListActivities(ctx, fleet.ListActivitiesOptions{ ListOptions: req.ListOptions, }) if err != nil { return listActivitiesResponse{Err: err}, nil } return listActivitiesResponse{Meta: metadata, Activities: activities}, nil } // ListActivities returns a slice of activities for the whole organization func (svc *Service) ListActivities(ctx context.Context, opt fleet.ListActivitiesOptions) ([]*fleet.Activity, *fleet.PaginationMetadata, error) { if err := svc.authz.Authorize(ctx, &fleet.Activity{}, fleet.ActionRead); err != nil { return nil, nil, err } return svc.ds.ListActivities(ctx, opt) } func (svc *Service) NewActivity(ctx context.Context, user *fleet.User, activity fleet.ActivityDetails) error { return svc.ds.NewActivity(ctx, user, activity) }