Add macos custom profiles support via fleetctl apply (#9824)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/pkg/spec"
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
@@ -68,7 +69,8 @@ func applyCommand() *cli.Command {
|
||||
Force: flForce,
|
||||
DryRun: flDryRun,
|
||||
}
|
||||
err = fleetClient.ApplyGroup(c.Context, specs, logf, opts)
|
||||
baseDir := filepath.Dir(flFilename)
|
||||
err = fleetClient.ApplyGroup(c.Context, specs, baseDir, logf, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/pkg/spec"
|
||||
"github.com/fleetdm/fleet/v4/server/config"
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/fleetdm/fleet/v4/server/ptr"
|
||||
"github.com/fleetdm/fleet/v4/server/service"
|
||||
@@ -182,6 +183,8 @@ spec:
|
||||
macos_updates:
|
||||
minimum_version: ""
|
||||
deadline: ""
|
||||
macos_settings:
|
||||
custom_settings:
|
||||
name: team1
|
||||
---
|
||||
apiVersion: v1
|
||||
@@ -204,10 +207,12 @@ spec:
|
||||
macos_updates:
|
||||
minimum_version: "12.3.1"
|
||||
deadline: "2021-12-14"
|
||||
macos_settings:
|
||||
custom_settings:
|
||||
name: team2
|
||||
`
|
||||
expectedJson := `{"kind":"team","apiVersion":"v1","spec":{"team":{"id":42,"created_at":"1999-03-10T02:45:06.371Z","name":"team1","description":"team1 description","webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":true,"enable_software_inventory":true},"mdm":{"macos_updates":{"minimum_version":"","deadline":""}},"user_count":99,"host_count":42}}}
|
||||
{"kind":"team","apiVersion":"v1","spec":{"team":{"id":43,"created_at":"1999-03-10T02:45:06.371Z","name":"team2","description":"team2 description","agent_options":{"config":{"foo":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override"}}}},"webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":false,"enable_software_inventory":false,"additional_queries":{"foo":"bar"}},"mdm":{"macos_updates":{"minimum_version":"12.3.1","deadline":"2021-12-14"}},"user_count":87,"host_count":43}}}
|
||||
expectedJson := `{"kind":"team","apiVersion":"v1","spec":{"team":{"id":42,"created_at":"1999-03-10T02:45:06.371Z","name":"team1","description":"team1 description","webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":true,"enable_software_inventory":true},"mdm":{"macos_updates":{"minimum_version":"","deadline":""}},"macos_settings":{"custom_settings":null},"user_count":99,"host_count":42}}}
|
||||
{"kind":"team","apiVersion":"v1","spec":{"team":{"id":43,"created_at":"1999-03-10T02:45:06.371Z","name":"team2","description":"team2 description","agent_options":{"config":{"foo":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override"}}}},"webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":false,"enable_software_inventory":false,"additional_queries":{"foo":"bar"}},"mdm":{"macos_updates":{"minimum_version":"12.3.1","deadline":"2021-12-14"}},"macos_settings":{"custom_settings":null},"user_count":87,"host_count":43}}}
|
||||
`
|
||||
|
||||
if tt.shouldHaveExpiredBanner {
|
||||
@@ -476,6 +481,8 @@ spec:
|
||||
macos_updates:
|
||||
minimum_version: ""
|
||||
deadline: ""
|
||||
macos_settings:
|
||||
custom_settings:
|
||||
org_info:
|
||||
org_logo_url: ""
|
||||
org_name: ""
|
||||
@@ -562,6 +569,9 @@ spec:
|
||||
"enable_host_users": true,
|
||||
"enable_software_inventory": false
|
||||
},
|
||||
"macos_settings": {
|
||||
"custom_settings": null
|
||||
},
|
||||
"mdm": {
|
||||
"macos_updates": {
|
||||
"minimum_version": "",
|
||||
@@ -636,6 +646,8 @@ spec:
|
||||
integrations:
|
||||
jira: null
|
||||
zendesk: null
|
||||
macos_settings:
|
||||
custom_settings:
|
||||
mdm:
|
||||
apple_bm_default_team: ""
|
||||
apple_bm_terms_expired: false
|
||||
@@ -775,6 +787,9 @@ spec:
|
||||
"enable_host_users": true,
|
||||
"enable_software_inventory": false
|
||||
},
|
||||
"macos_settings": {
|
||||
"custom_settings": null
|
||||
},
|
||||
"mdm": {
|
||||
"macos_updates": {
|
||||
"minimum_version": "",
|
||||
@@ -1651,8 +1666,11 @@ func TestGetCarveWithError(t *testing.T) {
|
||||
// TestGetTeamsYAMLAndApply checks that the output of `get teams --yaml` can be applied
|
||||
// via the `apply` command.
|
||||
func TestGetTeamsYAMLAndApply(t *testing.T) {
|
||||
cfg := config.TestConfig()
|
||||
cfg.MDMApple.Enable = true
|
||||
_, ds := runServerWithMockedDS(t, &service.TestServerOpts{
|
||||
License: &fleet.LicenseInfo{Tier: fleet.TierPremium, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
License: &fleet.LicenseInfo{Tier: fleet.TierPremium, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
FleetConfig: &cfg,
|
||||
})
|
||||
|
||||
created_at, err := time.Parse(time.RFC3339, "1999-03-10T02:45:06.371Z")
|
||||
@@ -1730,6 +1748,9 @@ func TestGetTeamsYAMLAndApply(t *testing.T) {
|
||||
}
|
||||
return nil, fmt.Errorf("team not found: %s", name)
|
||||
}
|
||||
ds.BatchSetMDMAppleProfilesFunc = func(ctx context.Context, teamID *uint, profiles []*fleet.MDMAppleConfigProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
actualYaml := runAppForTest(t, []string{"get", "teams", "--yaml"})
|
||||
yamlFilePath := writeTmpYml(t, actualYaml)
|
||||
|
||||
@@ -308,7 +308,9 @@ Use the stop and reset subcommands to manage the server and dependencies once st
|
||||
logf := func(format string, a ...interface{}) {
|
||||
fmt.Fprintf(c.App.Writer, format, a...)
|
||||
}
|
||||
err = client.ApplyGroup(c.Context, specs, logf, fleet.ApplySpecOptions{})
|
||||
// this only applies standard queries, the base directory is not used,
|
||||
// so pass in the current working directory.
|
||||
err = client.ApplyGroup(c.Context, specs, ".", logf, fleet.ApplySpecOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user