mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-07 10:05:48 +08:00
reorganize MDM service into a single package. (#423)
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/groob/plist"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/micromdm/mdm"
|
||||
"github.com/micromdm/micromdm/mdm"
|
||||
"github.com/micromdm/micromdm/platform/command"
|
||||
"github.com/micromdm/micromdm/platform/pubsub"
|
||||
)
|
||||
@@ -24,7 +24,18 @@ type Store struct {
|
||||
*bolt.DB
|
||||
}
|
||||
|
||||
func (db *Store) Next(ctx context.Context, resp mdm.Response) (*Command, error) {
|
||||
func (db *Store) Next(ctx context.Context, resp mdm.Response) ([]byte, error) {
|
||||
cmd, err := db.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cmd == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return cmd.Payload, nil
|
||||
}
|
||||
|
||||
func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command, error) {
|
||||
udid := resp.UDID
|
||||
if resp.UserID != nil {
|
||||
// use the user id for user level commands
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/micromdm/mdm"
|
||||
"github.com/micromdm/micromdm/mdm"
|
||||
)
|
||||
|
||||
func TestNext_Error(t *testing.T) {
|
||||
@@ -29,7 +29,7 @@ func TestNext_Error(t *testing.T) {
|
||||
Status: "Error",
|
||||
}
|
||||
for range dc.Commands {
|
||||
cmd, err := store.Next(ctx, resp)
|
||||
cmd, err := store.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
t.Fatalf("expected nil, but got err: %s", err)
|
||||
}
|
||||
@@ -57,16 +57,15 @@ func TestNext_NotNow(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tf := func(t *testing.T) {
|
||||
|
||||
|
||||
resp := mdm.Response{
|
||||
UDID: dc.DeviceUDID,
|
||||
CommandUUID: "yCmd",
|
||||
Status: "NotNow",
|
||||
}
|
||||
cmd, err := store.Next(ctx, resp)
|
||||
cmd, err := store.nextCommand(ctx, resp)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("expected nil, but got err: %s", err)
|
||||
t.Fatalf("expected nil, but got err: %s", err)
|
||||
}
|
||||
|
||||
resp = mdm.Response{
|
||||
@@ -75,7 +74,7 @@ func TestNext_NotNow(t *testing.T) {
|
||||
Status: "NotNow",
|
||||
}
|
||||
|
||||
cmd, err = store.Next(ctx, resp)
|
||||
cmd, err = store.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
t.Fatalf("expected nil, but got err: %s", err)
|
||||
}
|
||||
@@ -111,7 +110,7 @@ func TestNext_Idle(t *testing.T) {
|
||||
Status: "Idle",
|
||||
}
|
||||
for i, _ := range dc.Commands {
|
||||
cmd, err := store.Next(ctx, resp)
|
||||
cmd, err := store.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
t.Fatalf("expected nil, but got err: %s", err)
|
||||
}
|
||||
@@ -143,7 +142,7 @@ func TestNext_zeroCommands(t *testing.T) {
|
||||
for _, s := range allStatuses {
|
||||
t.Run(s, func(t *testing.T) {
|
||||
resp := mdm.Response{CommandUUID: s, Status: s}
|
||||
cmd, err := store.Next(ctx, resp)
|
||||
cmd, err := store.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
t.Errorf("expected nil, but got err: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user