2021-09-14 13:58:48 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
)
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// List
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type listSoftwareRequest struct {
|
2021-10-20 21:01:20 +00:00
|
|
|
fleet.SoftwareListOptions
|
2021-09-14 13:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type listSoftwareResponse struct {
|
|
|
|
Software []fleet.Software `json:"software,omitempty"`
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r listSoftwareResponse) error() error { return r.Err }
|
|
|
|
|
|
|
|
func listSoftwareEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (interface{}, error) {
|
|
|
|
req := request.(*listSoftwareRequest)
|
2021-10-20 21:01:20 +00:00
|
|
|
resp, err := svc.ListSoftware(ctx, req.SoftwareListOptions)
|
2021-09-14 13:58:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return listSoftwareResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
return listSoftwareResponse{Software: resp}, nil
|
|
|
|
}
|
|
|
|
|
2021-10-20 21:01:20 +00:00
|
|
|
func (svc Service) ListSoftware(ctx context.Context, opt fleet.SoftwareListOptions) ([]fleet.Software, error) {
|
2021-09-14 13:58:48 +00:00
|
|
|
if err := svc.authz.Authorize(ctx, &fleet.Software{}, fleet.ActionRead); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-10-20 21:01:20 +00:00
|
|
|
return svc.ds.ListSoftware(ctx, opt)
|
2021-09-14 13:58:48 +00:00
|
|
|
}
|