mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
Add option to opt out of saving device command history. (#640)
This commit is contained in:
@@ -25,7 +25,8 @@ const (
|
||||
|
||||
type Store struct {
|
||||
*bolt.DB
|
||||
logger log.Logger
|
||||
logger log.Logger
|
||||
withoutHistory bool
|
||||
}
|
||||
|
||||
type Option func(*Store)
|
||||
@@ -36,6 +37,12 @@ func WithLogger(logger log.Logger) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithoutHistory() Option {
|
||||
return func(s *Store) {
|
||||
s.withoutHistory = true
|
||||
}
|
||||
}
|
||||
|
||||
func (db *Store) Next(ctx context.Context, resp mdm.Response) ([]byte, error) {
|
||||
cmd, err := db.nextCommand(ctx, resp)
|
||||
if err != nil {
|
||||
@@ -87,8 +94,11 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
|
||||
if x == nil {
|
||||
break
|
||||
}
|
||||
x.Acknowledged = time.Now().UTC()
|
||||
dc.Completed = append(dc.Completed, *x)
|
||||
if !db.withoutHistory {
|
||||
x.Acknowledged = time.Now().UTC()
|
||||
dc.Completed = append(dc.Completed, *x)
|
||||
}
|
||||
|
||||
case "Error":
|
||||
// move to failed, send next
|
||||
x, a := cut(dc.Commands, resp.CommandUUID)
|
||||
@@ -96,7 +106,9 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
|
||||
if x == nil { // must've already bin ackd
|
||||
break
|
||||
}
|
||||
dc.Failed = append(dc.Failed, *x)
|
||||
if !db.withoutHistory {
|
||||
dc.Failed = append(dc.Failed, *x)
|
||||
}
|
||||
|
||||
case "CommandFormatError":
|
||||
// move to failed
|
||||
@@ -105,7 +117,9 @@ func (db *Store) nextCommand(ctx context.Context, resp mdm.Response) (*Command,
|
||||
if x == nil {
|
||||
break
|
||||
}
|
||||
dc.Failed = append(dc.Failed, *x)
|
||||
if !db.withoutHistory {
|
||||
dc.Failed = append(dc.Failed, *x)
|
||||
}
|
||||
|
||||
case "Idle":
|
||||
|
||||
|
||||
Reference in New Issue
Block a user