mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-10 03:16:07 +08:00
Closes #302 This package still needs a lot of work, but I feel like this is a good stopping point. In a follow up, I plan on writing some tests, and refactoring some of the ways the sync.Watcher goroutines are managed.
41 lines
845 B
Go
41 lines
845 B
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type Service interface {
|
|
SyncNow(context.Context) error
|
|
ApplyAutoAssigner(context.Context, *AutoAssigner) error
|
|
GetAutoAssigners(context.Context) ([]AutoAssigner, error)
|
|
RemoveAutoAssigner(context.Context, string) error
|
|
}
|
|
|
|
type DB interface {
|
|
SaveAutoAssigner(a *AutoAssigner) error
|
|
LoadAutoAssigners() ([]AutoAssigner, error)
|
|
DeleteAutoAssigner(filter string) error
|
|
}
|
|
|
|
type DEPSyncService struct {
|
|
db DB
|
|
syncer Syncer
|
|
}
|
|
|
|
type Cursor struct {
|
|
Value string `json:"value"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// A cursor is valid for a week.
|
|
func (c Cursor) Valid() bool {
|
|
expiration := time.Now().Add(cursorValidDuration)
|
|
return c.CreatedAt.Before(expiration)
|
|
}
|
|
|
|
type AutoAssigner struct {
|
|
Filter string `json:"filter"`
|
|
ProfileUUID string `json:"profile_uuid"`
|
|
}
|