sync

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package sync provides services to sync devices and assign profile UUIDs using the Apple DEP APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assigner

type Assigner struct {
	// contains filtered or unexported fields
}

Assigner assigns devices synced from the Apple DEP APIs to a profile UUID.

func NewAssigner

func NewAssigner(client *godep.Client, name string, store AssignerProfileRetriever, opts ...AssignerOption) *Assigner

NewAssigner creates a new Assigner from client and uses store to lookup assigner profile UUIDs. DEP name is specified with name.

func (*Assigner) ProcessDeviceResponse

func (a *Assigner) ProcessDeviceResponse(ctx context.Context, resp *godep.DeviceResponse) error

ProcessDeviceResponse processes the device response from the device sync DEP API endpoints and assigns the profile UUID associated with the DEP client DEP name.

type AssignerOption

type AssignerOption func(*Assigner)

func WithAssignerDebug added in v0.2.0

func WithAssignerDebug() AssignerOption

WithAssignerDebug enables additional assigner-specific debug logging for troubleshooting.

func WithAssignerLogger

func WithAssignerLogger(logger log.Logger) AssignerOption

WithAssignerLogger configures logger for the assigner.

type AssignerProfileRetriever

type AssignerProfileRetriever interface {
	RetrieveAssignerProfile(ctx context.Context, name string) (profileUUID string, modTime time.Time, err error)
}

type CursorStorage

type CursorStorage interface {
	RetrieveCursor(ctx context.Context, name string) (string, error)
	StoreCursor(ctx context.Context, name string, cursor string) error
}

CursorStorage is where the device fetch and sync cursor can be stored and retrieved for a given DEP name.

type DeviceResponseCallback

type DeviceResponseCallback func(context.Context, bool, *godep.DeviceResponse) error

DeviceResponseCallback is called every time a fetch or sync operation completes.

type Syncer

type Syncer struct {
	// contains filtered or unexported fields
}

Syncer performs the fetch and sync cursor operations to sync devices from the Apple DEP service. Depending on the options supplied it can perform the sync continuously on a duration or just once. See the various SyncerOptions for configuring the behavior of the syncer.

func NewSyncer

func NewSyncer(client *godep.Client, name string, store CursorStorage, opts ...SyncerOption) *Syncer

NewSyncer creates a new Syncer using client and uses store for cursor storage. DEP name is specified with name.

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context) error

Run starts a device fetch and sync loop. Errors from the DEP API are generally ignored so that the sync can continue on (i.e. we assume API errors are transient). However if a cursor storage error or other "hard" error occurs then the loop will end. The loop will end if the context gets cancelled. The loop will also exit early if there is no duration option set (i.e. is in "run once" mode).

type SyncerOption

type SyncerOption func(*Syncer)

func WithCallback

func WithCallback(cb DeviceResponseCallback) SyncerOption

WithCallback sets the callback function to call for each fetch and sync.

func WithDebug

func WithDebug() SyncerOption

WithDebug enables additional syncer-specific debug logging for troubleshooting.

func WithDuration

func WithDuration(duration time.Duration) SyncerOption

WithDuration sets the "mode" of operation. If not set or set to 0 then the mode is "run once" and if a duration is provided then the syncer operates in "continuous" mode and will start a ticker for duration to wait beween sync cycles.

func WithLimit

func WithLimit(limit int) SyncerOption

WithLimit sets the device sync limit for each fetch and sync.

func WithLogger

func WithLogger(logger log.Logger) SyncerOption

WithLogger configures logger for the syncer.

func WithSyncNow

func WithSyncNow(syncNow <-chan struct{}) SyncerOption

WithSyncNow specifies the channel to select on which will advise the syncer to end its sync wait and perform the next immediate sync.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL