Add endpoint for inspecting the MDM command queue (#895)

This commit is contained in:
Graham Gilbert
2023-07-12 00:07:42 +01:00
committed by GitHub
parent 7a3715454a
commit c4a1cd97ef
9 changed files with 157 additions and 2 deletions

View File

@@ -121,6 +121,30 @@ func (q *QueueInMem) Clear(_ context.Context, event mdm.CheckinEvent) error {
return nil
}
// View returns the command queue for the device in event
func (q *QueueInMem) ViewQueue(_ context.Context, event mdm.CheckinEvent) ([]*mdm.Command, error) {
udid := event.Command.UDID
if event.Command.UserID != "" {
udid = event.Command.UserID
}
if event.Command.EnrollmentID != "" {
udid = event.Command.EnrollmentID
}
l := q.getList(udid)
cmds := make([]*mdm.Command, 0, l.Len())
for item := l.Front(); item != nil; item = item.Next() {
cmd := item.Value.(*queuedCommand)
cmds = append(cmds, &mdm.Command{
UUID: cmd.uuid,
Payload: cmd.payload,
})
}
return cmds, nil
}
func (q *QueueInMem) startPolling(pubsub pubsub.PublishSubscriber) error {
events, err := pubsub.Subscribe(context.TODO(), "command-queue", command.CommandTopic)
if err != nil {

View File

@@ -54,6 +54,33 @@ func (db *Store) Next(ctx context.Context, resp mdm.Response) ([]byte, error) {
return cmd.Payload, nil
}
func (db *Store) ViewQueue(ctx context.Context, event mdm.CheckinEvent) ([]*mdm.Command, error) {
udid := event.Command.UDID
if event.Command.UserID != "" {
udid = event.Command.UserID
}
if event.Command.EnrollmentID != "" {
udid = event.Command.EnrollmentID
}
dc, err := db.DeviceCommand(udid)
if isNotFound(err) {
return nil, nil
} else if err != nil {
return nil, errors.Wrapf(err, "get device commands, udid: %s", udid)
}
cmds := make([]*mdm.Command, len(dc.Commands))
for idx, cmd := range dc.Commands {
cmds[idx] = &mdm.Command{
UUID: cmd.UUID,
Payload: cmd.Payload,
}
}
return cmds, nil
}
func (db *Store) Clear(ctx context.Context, event mdm.CheckinEvent) error {
udid := event.Command.UDID
if event.Command.UserID != "" {