Clear a UDID's command queue during Authenticate Check-in (enrollment) (#692)

This commit is contained in:
Jesse Peterson
2020-07-20 22:25:06 -07:00
committed by GitHub
parent 39f595bb27
commit e01ef8a382
3 changed files with 29 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -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 {

View File

@@ -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.