mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-04 16:26:23 +08:00
Clear a UDID's command queue during Authenticate Check-in (enrollment) (#692)
This commit is contained in:
@@ -27,6 +27,12 @@ func (svc *MDMService) Checkin(ctx context.Context, event CheckinEvent) error {
|
||||
return errors.Wrap(err, "get checkin topic from message")
|
||||
}
|
||||
|
||||
if topic == AuthenticateTopic {
|
||||
if err := svc.queue.Clear(ctx, event); err != nil {
|
||||
return errors.Wrap(err, "clearing queue on enrollment attempt")
|
||||
}
|
||||
}
|
||||
|
||||
err = svc.pub.Publish(ctx, topic, msg)
|
||||
return errors.Wrapf(err, "publish checkin on topic: %s", topic)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ const (
|
||||
// Queue is an MDM Command Queue.
|
||||
type Queue interface {
|
||||
Next(context.Context, Response) ([]byte, error)
|
||||
Clear(context.Context, CheckinEvent) error
|
||||
}
|
||||
|
||||
type MDMService struct {
|
||||
|
||||
@@ -54,6 +54,28 @@ func (db *Store) Next(ctx context.Context, resp mdm.Response) ([]byte, error) {
|
||||
return cmd.Payload, nil
|
||||
}
|
||||
|
||||
func (db *Store) Clear(ctx context.Context, event mdm.CheckinEvent) 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
|
||||
} else if err != nil {
|
||||
return errors.Wrapf(err, "get device to clear queue, udid: %s", udid)
|
||||
}
|
||||
|
||||
dc.Commands = nil
|
||||
dc.NotNow = nil
|
||||
|
||||
return db.Save(dc)
|
||||
}
|
||||
|
||||
func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command, error) {
|
||||
// The UDID is the primary key for the queue.
|
||||
// Depending on the enrollment type, replace the UDID with a different ID type.
|
||||
|
||||
Reference in New Issue
Block a user