Files
micromdm/connect/middleware.go
Mosen 15b5ec5cef Add service middleware for Connect service to record last_checkin each time a device contacts the MDM
Add method UpdateDeviceCheckinByUDID to device.Datastore which updates the current checkin timestamp for a given device.
Middleware set up in main.go
2016-06-22 19:10:38 +10:00

29 lines
716 B
Go

package connect
import (
"github.com/micromdm/micromdm/device"
"golang.org/x/net/context"
)
type lastCheckinMiddleware struct {
devices device.Datastore
next Service
}
func NewMiddleware(datastore device.Datastore, next Service) (*lastCheckinMiddleware) {
return &lastCheckinMiddleware{
datastore,
next,
}
}
func (mw lastCheckinMiddleware) Acknowledge(ctx context.Context, req mdmConnectRequest) (int, error) {
mw.devices.UpdateDeviceCheckinByUDID(req.UDID)
return mw.next.Acknowledge(ctx, req)
}
func (mw lastCheckinMiddleware) NextCommand(ctx context.Context, req mdmConnectRequest) ([]byte, int, error) {
mw.devices.UpdateDeviceCheckinByUDID(req.UDID)
return mw.next.NextCommand(ctx, req)
}