-
Notifications
You must be signed in to change notification settings - Fork 7
/
UpdateMacOSConfigurationProfileByName.go
81 lines (69 loc) · 5.04 KB
/
UpdateMacOSConfigurationProfileByName.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"log"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)
func main() {
// Define the path to the JSON configuration file
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
// Load the client OAuth credentials from the configuration file
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
if err != nil {
log.Fatalf("Failed to load client OAuth configuration: %v", err)
}
// Instantiate the default logger and set the desired log level
logger := http_client.NewDefaultLogger()
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
// Configuration for the jamfpro
config := jamfpro.Config{
InstanceName: authConfig.InstanceName,
OverrideBaseDomain: authConfig.OverrideBaseDomain,
LogLevel: logLevel,
Logger: logger,
ClientID: authConfig.ClientID,
ClientSecret: authConfig.ClientSecret,
}
// Create a new jamfpro client instance
client, err := jamfpro.NewClient(config)
if err != nil {
log.Fatalf("Failed to create Jamf Pro client: %v", err)
}
// embedded xml of configuration profile
payloads := `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1"><dict><key>PayloadUUID</key><string>3665BB04-2B24-4CF6-A3FB-BF1B2221CBA5</string><key>PayloadType</key><string>Configuration</string><key>PayloadOrganization</key><string>Jamf</string><key>PayloadIdentifier</key><string>3665BB04-2B24-4CF6-A3FB-BF1B2221CBA5</string><key>PayloadDisplayName</key><string>WiFi Test</string><key>PayloadDescription</key><string/><key>PayloadVersion</key><integer>1</integer><key>PayloadEnabled</key><true/><key>PayloadRemovalDisallowed</key><true/><key>PayloadScope</key><string>System</string><key>PayloadContent</key><array><dict><key>PayloadUUID</key><string>646F7DC3-54EF-42AF-92BA-6626DA39E28F</string><key>PayloadType</key><string>com.apple.wifi.managed</string><key>PayloadOrganization</key><string>Jamf</string><key>PayloadIdentifier</key><string>646F7DC3-54EF-42AF-92BA-6626DA39E28F</string><key>PayloadDisplayName</key><string>WiFi</string><key>PayloadDescription</key><string/><key>PayloadVersion</key><integer>1</integer><key>PayloadEnabled</key><true/><key>HIDDEN_NETWORK</key><false/><key>Password</key><string>jamf</string><key>EncryptionType</key><string>WPA</string><key>AutoJoin</key><true/><key>CaptiveBypass</key><false/><key>ProxyType</key><string>None</string><key>SetupModes</key><array/><key>SSID_STR</key><string>jamf</string><key>Interface</key><string>BuiltInWireless</string></dict></array></dict></plist>`
// General profile data
// Define the macOS Configuration Profile as per the given XML structure
profile := jamfpro.ResponseMacOSConfigurationProfiles{
General: jamfpro.MacOSConfigurationProfilesDataSubsetGeneral{
Name: "WiFi Test",
Description: "",
Site: jamfpro.MacOSConfigurationProfilesDataSubsetSite{ID: -1, Name: "None"}, // Optional, the Create fuction will set default values if no site is set
Category: jamfpro.MacOSConfigurationProfilesDataSubsetCategory{ID: -1, Name: "No category assigned"}, // Optional, the Create fuction will set default values if no category is set
DistributionMethod: "Install Automatically",
UserRemovable: false,
Level: "computer",
RedeployOnUpdate: "Newly Assigned",
Payloads: payloads,
},
Scope: jamfpro.MacOSConfigurationProfilesDataSubsetScope{
AllComputers: false,
AllJSSUsers: false,
},
SelfService: jamfpro.MacOSConfigurationProfilesDataSubsetSelfService{
InstallButtonText: "Install",
SelfServiceDescription: "null",
ForceUsersToViewDescription: false,
// Add other fields as per the XML example
},
}
// The name of the macOS Configuration Profile you want to update
name := "WiFi Test"
// Call the UpdateMacOSConfigurationProfileByName function
updatedProfileID, err := client.UpdateMacOSConfigurationProfileByName(name, &profile)
if err != nil {
log.Fatalf("Failed to update macOS Configuration Profile: %v", err)
}
fmt.Printf("Profile updated successfully. Updated Profile ID: %d\n", updatedProfileID)
}