-
Notifications
You must be signed in to change notification settings - Fork 7
/
CreateMacOSConfigurationProfileWithFileUpload.go
97 lines (83 loc) · 2.95 KB
/
CreateMacOSConfigurationProfileWithFileUpload.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)
const (
maxConcurrentRequestsAllowed = 5 // Maximum allowed concurrent requests.
defaultTokenLifespan = 30 * time.Minute
defaultBufferPeriod = 5 * time.Minute
)
// Helper function to get a pointer from a string
func stringPtr(s string) *string {
return &s
}
// readPayloadFromFile loads config profile for upload
func readPayloadFromFile(filePath string) (string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
return string(data), nil
}
func main() {
// Define the path to the JSON configuration file inside the main function
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
// Load the client OAuth credentials from the configuration file
authConfig, err := http_client.LoadClientAuthConfig(configFilePath)
if err != nil {
log.Fatalf("Failed to load client OAuth configuration: %v", err)
}
// Configuration for the jamfpro
config := jamfpro.Config{
InstanceName: authConfig.InstanceName,
DebugMode: true,
Logger: jamfpro.NewDefaultLogger(),
ClientID: authConfig.ClientID,
ClientSecret: authConfig.ClientSecret,
}
// Create a new jamfpro client instanceclient,
client, err := jamfpro.NewClient(config)
if err != nil {
log.Fatalf("Failed to create Jamf Pro client: %v", err)
}
// Set OAuth credentials for the client's HTTP client using the helper function
creds := map[string]string{
"clientID": authConfig.ClientID,
"clientSecret": authConfig.ClientSecret,
}
client.HTTP.SetAuthenticationCredentials(creds)
// Read the payload from a file
payloadFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/examples/support_files/api-test.mobileconfig"
payload, err := readPayloadFromFile(payloadFilePath)
if err != nil {
log.Fatalf("Error reading payload from file: %v", err)
}
// Define a sample macOS Configuration Profile
profile := &jamfpro.ResponseMacOSConfigurationProfile{
General: jamfpro.GeneralConfig{
Name: "WiFi Test",
Site: jamfpro.SiteInfo{Name: "None"},
Category: jamfpro.CategoryInfo{Name: "No category assigned"},
DistributionMethod: "Install Automatically",
Level: "computer",
RedeployOnUpdate: "Newly Assigned",
Payloads: payload,
},
Scope: jamfpro.ScopeConfig{},
SelfService: jamfpro.SelfServiceConfig{
InstallButtonText: "Install",
},
}
// Call CreateMacOSConfigurationProfile function
createdProfile, err := client.CreateMacOSConfigurationProfile(profile)
if err != nil {
log.Fatalf("Error creating macOS Configuration Profile: %v", err)
}
// Print the created profile details
fmt.Printf("Created macOS Configuration Profile with ID %d and Name %s\n", createdProfile.General.ID, createdProfile.General.Name)
}