mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
2d553db2aa
* Add Global Schedule * Uncomment tests * Uncomment integration tests * Add targets for global schedule * Add host label * Simplify implementation * wip * Fix mock * Add missing test * Further simplify the implementation * Forgot to remove test name * Update names
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/ptr"
|
|
)
|
|
|
|
func (svc *Service) GlobalScheduleQuery(ctx context.Context, sq *fleet.ScheduledQuery) (*fleet.ScheduledQuery, error) {
|
|
if err := svc.authz.Authorize(ctx, &fleet.Pack{}, fleet.ActionRead); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gp, err := svc.ds.EnsureGlobalPack()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
sq.PackID = gp.ID
|
|
|
|
return svc.ScheduleQuery(ctx, sq)
|
|
}
|
|
|
|
func (svc *Service) GetGlobalScheduledQueries(ctx context.Context, opts fleet.ListOptions) ([]*fleet.ScheduledQuery, error) {
|
|
if err := svc.authz.Authorize(ctx, &fleet.Pack{}, fleet.ActionRead); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gp, err := svc.ds.EnsureGlobalPack()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return svc.ds.ListScheduledQueriesInPack(gp.ID, opts)
|
|
}
|
|
|
|
func (svc *Service) ModifyGlobalScheduledQueries(
|
|
ctx context.Context,
|
|
id uint,
|
|
query fleet.ScheduledQueryPayload,
|
|
) (*fleet.ScheduledQuery, error) {
|
|
if err := svc.authz.Authorize(ctx, &fleet.Pack{}, fleet.ActionWrite); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gp, err := svc.ds.EnsureGlobalPack()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
query.PackID = ptr.Uint(gp.ID)
|
|
|
|
return svc.ModifyScheduledQuery(ctx, id, query)
|
|
}
|
|
|
|
func (svc *Service) DeleteGlobalScheduledQueries(ctx context.Context, id uint) error {
|
|
if err := svc.authz.Authorize(ctx, &fleet.Pack{}, fleet.ActionWrite); err != nil {
|
|
return err
|
|
}
|
|
|
|
return svc.DeleteScheduledQuery(ctx, id)
|
|
}
|