Skip to content

Commit

Permalink
Add MDM software update enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
np5 committed Nov 29, 2023
1 parent e06d384 commit 2b7e5eb
Show file tree
Hide file tree
Showing 5 changed files with 587 additions and 76 deletions.
18 changes: 10 additions & 8 deletions goztl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
libraryVersion = "0.1.42"
libraryVersion = "0.1.43"
userAgent = "goztl/" + libraryVersion
mediaType = "application/json"
)
Expand All @@ -38,13 +38,14 @@ type Client struct {
Tags TagsService
Taxonomies TaxonomiesService
// MDM
MDMArtifacts MDMArtifactsService
MDMBlueprints MDMBlueprintsService
MDMBlueprintArtifacts MDMBlueprintArtifactsService
MDMEnterpriseApps MDMEnterpriseAppsService
MDMFileVaultConfigs MDMFileVaultConfigsService
MDMProfiles MDMProfilesService
MDMRecoveryPasswordConfigs MDMRecoveryPasswordConfigsService
MDMArtifacts MDMArtifactsService
MDMBlueprints MDMBlueprintsService
MDMBlueprintArtifacts MDMBlueprintArtifactsService
MDMEnterpriseApps MDMEnterpriseAppsService
MDMFileVaultConfigs MDMFileVaultConfigsService
MDMProfiles MDMProfilesService
MDMRecoveryPasswordConfigs MDMRecoveryPasswordConfigsService
MDMSoftwareUpdateEnforcements MDMSoftwareUpdateEnforcementsService
// Monolith
MonolithCatalogs MonolithCatalogsService
MonolithConditions MonolithConditionsService
Expand Down Expand Up @@ -165,6 +166,7 @@ func NewClient(httpClient *http.Client, bu string, token string, opts ...ClientO
c.MDMFileVaultConfigs = &MDMFileVaultConfigsServiceOp{client: c}
c.MDMProfiles = &MDMProfilesServiceOp{client: c}
c.MDMRecoveryPasswordConfigs = &MDMRecoveryPasswordConfigsServiceOp{client: c}
c.MDMSoftwareUpdateEnforcements = &MDMSoftwareUpdateEnforcementsServiceOp{client: c}
// Monolith
c.MonolithCatalogs = &MonolithCatalogsServiceOp{client: c}
c.MonolithConditions = &MonolithConditionsServiceOp{client: c}
Expand Down
36 changes: 19 additions & 17 deletions mdm_blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ var _ MDMBlueprintsService = &MDMBlueprintsServiceOp{}

// MDMBlueprint represents a Zentral MDM blueprint
type MDMBlueprint struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
InventoryInterval int `json:"inventory_interval"`
CollectApps int `json:"collect_apps"`
CollectCertificates int `json:"collect_certificates"`
CollectProfiles int `json:"collect_profiles"`
FileVaultConfigID *int `json:"filevault_config"`
RecoveryPasswordConfigID *int `json:"recovery_password_config"`
Created Timestamp `json:"created_at,omitempty"`
Updated Timestamp `json:"updated_at,omitempty"`
ID int `json:"id,omitempty"`
Name string `json:"name"`
InventoryInterval int `json:"inventory_interval"`
CollectApps int `json:"collect_apps"`
CollectCertificates int `json:"collect_certificates"`
CollectProfiles int `json:"collect_profiles"`
FileVaultConfigID *int `json:"filevault_config"`
RecoveryPasswordConfigID *int `json:"recovery_password_config"`
SoftwareUpdateEnforcementIDs []int `json:"software_update_enforcements"`
Created Timestamp `json:"created_at,omitempty"`
Updated Timestamp `json:"updated_at,omitempty"`
}

func (mb MDMBlueprint) String() string {
Expand All @@ -47,13 +48,14 @@ func (mb MDMBlueprint) String() string {

// MDMBlueprintRequest represents a request to create or update a MDM blueprint
type MDMBlueprintRequest struct {
Name string `json:"name"`
InventoryInterval int `json:"inventory_interval"`
CollectApps int `json:"collect_apps"`
CollectCertificates int `json:"collect_certificates"`
CollectProfiles int `json:"collect_profiles"`
FileVaultConfigID *int `json:"filevault_config"`
RecoveryPasswordConfigID *int `json:"recovery_password_config"`
Name string `json:"name"`
InventoryInterval int `json:"inventory_interval"`
CollectApps int `json:"collect_apps"`
CollectCertificates int `json:"collect_certificates"`
CollectProfiles int `json:"collect_profiles"`
FileVaultConfigID *int `json:"filevault_config"`
RecoveryPasswordConfigID *int `json:"recovery_password_config"`
SoftwareUpdateEnforcementIDs []int `json:"software_update_enforcements"`
}

type listMBOptions struct {
Expand Down
112 changes: 61 additions & 51 deletions mdm_blueprints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var mbListJSONResponse = `
"collect_profiles": 2,
"filevault_config": null,
"recovery_password_config": null,
"software_update_enforcements": [],
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
Expand All @@ -38,6 +39,7 @@ var mbGetJSONResponse = `
"collect_profiles": 2,
"filevault_config": 3,
"recovery_password_config": 4,
"software_update_enforcements": [5],
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
Expand All @@ -51,6 +53,7 @@ var mbCreateJSONResponse = `
"collect_apps": 0,
"collect_certificates": 1,
"collect_profiles": 2,
"software_update_enforcements": [],
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
Expand All @@ -66,6 +69,7 @@ var mbUpdateJSONResponse = `
"collect_profiles": 2,
"filevault_config": 3,
"recovery_password_config": 4,
"software_update_enforcements": [5],
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
Expand All @@ -89,14 +93,15 @@ func TestMDMBlueprintsService_List(t *testing.T) {

want := []MDMBlueprint{
{
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
SoftwareUpdateEnforcementIDs: []int{},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
},
}
if !cmp.Equal(got, want) {
Expand All @@ -121,16 +126,17 @@ func TestMDMBlueprintsService_GetByID(t *testing.T) {
}

want := &MDMBlueprint{
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
SoftwareUpdateEnforcementIDs: []int{5},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMBlueprints.GetByID returned %+v, want %+v", got, want)
Expand All @@ -155,14 +161,15 @@ func TestMDMBlueprintsService_GetByName(t *testing.T) {
}

want := &MDMBlueprint{
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
SoftwareUpdateEnforcementIDs: []int{},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMBlueprints.GetByName returned %+v, want %+v", got, want)
Expand Down Expand Up @@ -202,14 +209,15 @@ func TestMDMBlueprintsService_Create(t *testing.T) {
}

want := &MDMBlueprint{
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
SoftwareUpdateEnforcementIDs: []int{},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMBlueprints.Create returned %+v, want %+v", got, want)
Expand All @@ -221,13 +229,14 @@ func TestMDMBlueprintsService_Update(t *testing.T) {
defer teardown()

updateRequest := &MDMBlueprintRequest{
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
SoftwareUpdateEnforcementIDs: []int{5},
}

mux.HandleFunc("/mdm/blueprints/4/", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -250,16 +259,17 @@ func TestMDMBlueprintsService_Update(t *testing.T) {
}

want := &MDMBlueprint{
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
ID: 4,
Name: "Default",
InventoryInterval: 77777,
CollectApps: 0,
CollectCertificates: 1,
CollectProfiles: 2,
FileVaultConfigID: Int(3),
RecoveryPasswordConfigID: Int(4),
SoftwareUpdateEnforcementIDs: []int{5},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMBlueprints.Update returned %+v, want %+v", got, want)
Expand Down
Loading

0 comments on commit 2b7e5eb

Please sign in to comment.