mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-06 17:53:14 +08:00
Add endpoint for inspecting the MDM command queue (#895)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
Reference in New Issue
Block a user