mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
Insert "verified" to mdm_apple_delivery_status
table (#12033)
This commit is contained in:
parent
f711e60de4
commit
e2243d24bf
2
go.mod
2
go.mod
@ -247,6 +247,7 @@ require (
|
||||
github.com/jonboulle/clockwork v0.2.2 // indirect
|
||||
github.com/kevinburke/ssh_config v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.15.11 // indirect
|
||||
github.com/lib/pq v1.10.6 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
@ -296,6 +297,7 @@ require (
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
github.com/yashtewari/glob-intersection v0.1.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
github.com/ziutek/mymysql v1.5.4 // indirect
|
||||
go.elastic.co/apm v1.15.0 // indirect
|
||||
go.elastic.co/apm/module/apmhttp/v2 v2.3.0 // indirect
|
||||
go.elastic.co/fastjson v1.1.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -900,6 +900,7 @@ github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
|
||||
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/macadmins/osquery-extension v0.0.14 h1:GhTdqp5fEfD9AsIng1r9jIsYpmahelXwxVVd8by5NEk=
|
||||
@ -1269,6 +1270,7 @@ github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPR
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||
github.com/zwass/kit v0.0.0-20210625184505-ec5b5c5cce9c h1:TWQ2UvXPkhPxI2KmApKBOCaV6yD2N4mlvqFQ/DlPtpQ=
|
||||
github.com/zwass/kit v0.0.0-20210625184505-ec5b5c5cce9c/go.mod h1:OYYulo9tUqRadRLwB0+LE914sa1ui2yL7OrcU3Q/1XY=
|
||||
|
@ -0,0 +1,24 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
MigrationClient.AddMigration(Up_20230530122103, Down_20230530122103)
|
||||
}
|
||||
|
||||
func Up_20230530122103(tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`INSERT INTO mdm_apple_delivery_status (status) VALUES(?)`, "verified")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "insert verified mdm_apple_delivery_status")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Down_20230530122103(tx *sql.Tx) error {
|
||||
return nil
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package tables
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUp_20230530122103(t *testing.T) {
|
||||
db := applyUpToPrev(t)
|
||||
|
||||
var statuses []string
|
||||
err := db.Select(&statuses, "SELECT status FROM mdm_apple_delivery_status")
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, []string{"failed", "verifying", "pending"}, statuses)
|
||||
|
||||
// Insert some data.
|
||||
stmt := `
|
||||
INSERT INTO host_mdm_apple_profiles (
|
||||
profile_id,
|
||||
profile_identifier,
|
||||
profile_name,
|
||||
host_uuid,
|
||||
status,
|
||||
operation_type,
|
||||
command_uuid,
|
||||
checksum
|
||||
)
|
||||
VALUES (?,?,?,?,?,?,?,?)`
|
||||
|
||||
_, err = db.Exec(stmt, 1, "com.example.test", "Test Profile", "huuid1", "verifying", "install", "cuuid1", "csum1")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.Exec(stmt, 2, "com.example.test", "Test Profile 2", "huuid1", "pending", "install", "cuuid2", "csum2")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.Exec(stmt, 3, "com.example.test", "Test Profile 3", "huuid2", "failed", "install", "cuuid3", "csum3")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Apply current migration.
|
||||
applyNext(t, db)
|
||||
|
||||
// Check that the data was updated.
|
||||
statuses = []string{}
|
||||
err = db.Select(&statuses, "SELECT status FROM mdm_apple_delivery_status")
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, []string{"failed", "verifying", "pending", "verified"}, statuses)
|
||||
|
||||
// Check that existing data was unchanged.
|
||||
var status string
|
||||
err = db.QueryRow("SELECT status FROM host_mdm_apple_profiles WHERE profile_id = 1").Scan(&status)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "verifying", status)
|
||||
|
||||
err = db.QueryRow("SELECT status FROM host_mdm_apple_profiles WHERE profile_id = 2").Scan(&status)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "pending", status)
|
||||
|
||||
err = db.QueryRow("SELECT status FROM host_mdm_apple_profiles WHERE profile_id = 3").Scan(&status)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "failed", status)
|
||||
|
||||
// Insert some data with the new verified status.
|
||||
_, err = db.Exec(stmt, 4, "com.example.test", "Test Profile 4", "huuid4", "verified", "install", "cuuid4", "csum4")
|
||||
require.NoError(t, err)
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -59,6 +59,9 @@ type MDMAppleDeliveryStatus string
|
||||
// the timestamps, e.g. time since created_at, if we added them to
|
||||
// host_mdm_apple_profiles).
|
||||
//
|
||||
// - verified: the MDM command was successfully applied, and Fleet has
|
||||
// independently verified the status. This is a terminal state.
|
||||
//
|
||||
// - verifying: the MDM command was successfully applied, but Fleet has not
|
||||
// independently verified the status. This is an intermediate state,
|
||||
// it may transition to failed, pending, or NULL.
|
||||
@ -82,6 +85,7 @@ type MDMAppleDeliveryStatus string
|
||||
// Pending status.
|
||||
var (
|
||||
MDMAppleDeliveryFailed MDMAppleDeliveryStatus = "failed"
|
||||
MDMAppleDeliveryVerified MDMAppleDeliveryStatus = "verified"
|
||||
MDMAppleDeliveryVerifying MDMAppleDeliveryStatus = "verifying"
|
||||
MDMAppleDeliveryPending MDMAppleDeliveryStatus = "pending"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user