Skip to content

Commit

Permalink
Fix timestamp issue and schema update.
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed Dec 30, 2024
1 parent c6131b9 commit e944daa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

func init() {
MigrationClient.AddMigration(Up_20241223115925, Down_20241223115925)
MigrationClient.AddMigration(Up_20241230000000, Down_20241230000000)
}

func Up_20241223115925(tx *sql.Tx) error {
func Up_20241230000000(tx *sql.Tx) error {
// Using DATETIME instead of TIMESTAMP for secrets_updated_at to avoid future Y2K38 issues,
// since this date is used to detect if profile needs to be updated.

Expand Down Expand Up @@ -49,6 +49,6 @@ func Up_20241223115925(tx *sql.Tx) error {
return nil
}

func Down_20241223115925(_ *sql.Tx) error {
func Down_20241230000000(_ *sql.Tx) error {
return nil
}
19 changes: 12 additions & 7 deletions server/datastore/mysql/schema.sql

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions server/fleet/apple_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,9 @@ type MDMAppleDDMTokensResponse struct {
//
// https://developer.apple.com/documentation/devicemanagement/synchronizationtokens
type MDMAppleDDMDeclarationsToken struct {
DeclarationsToken string `db:"token"`
Timestamp time.Time `db:"latest_created_timestamp"`
DeclarationsToken string `db:"token"`
// Timestamp must JSON marshal to format YYYY-mm-ddTHH:MM:SSZ
Timestamp time.Time `db:"latest_created_timestamp"`
}

// MDMAppleDDMDeclarationItemsResponse is the response from the DDM declaration items endpoint.
Expand Down
3 changes: 3 additions & 0 deletions server/service/apple_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4183,6 +4183,9 @@ func (svc *MDMAppleDDMService) handleTokens(ctx context.Context, hostUUID string
return nil, ctxerr.Wrap(ctx, err, "getting synchronization tokens")
}

// Important: Timestamp must use format YYYY-mm-ddTHH:MM:SSZ (no milliseconds)
// Source: https://developer.apple.com/documentation/devicemanagement/synchronizationtokens?language=objc
tok.Timestamp = tok.Timestamp.Truncate(time.Second)
b, err := json.Marshal(fleet.MDMAppleDDMTokensResponse{
SyncTokens: *tok,
})
Expand Down

0 comments on commit e944daa

Please sign in to comment.