diff --git a/examples/cloud_idp/GetCloudIdentityProviderConfigurationByID/GetCloudIdentityProviderConfigurationByID.go b/examples/cloud_idp/GetCloudIdentityProviderConfigurationByID/GetCloudIdentityProviderConfigurationByID.go new file mode 100644 index 000000000..5ead0697e --- /dev/null +++ b/examples/cloud_idp/GetCloudIdentityProviderConfigurationByID/GetCloudIdentityProviderConfigurationByID.go @@ -0,0 +1,36 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the ID of the cloud identity provider to retrieve + cloudIdpID := "1001" + + // Call GetCloudIdentityProviderByID function + cloudIdp, err := client.GetCloudIdentityProviderConfigurationByID(cloudIdpID) + if err != nil { + log.Fatalf("Error fetching cloud identity provider: %v", err) + } + + // Pretty print the cloud identity provider in JSON + JSON, err := json.MarshalIndent(cloudIdp, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling cloud identity provider data: %v", err) + } + fmt.Printf("Cloud Identity Provider (ID: %s):\n%s\n", cloudIdpID, string(JSON)) +} diff --git a/examples/cloud_idp/GetCloudIdentityProviders/GetCloudIdentityProviders.go b/examples/cloud_idp/GetCloudIdentityProviders/GetCloudIdentityProviders.go new file mode 100644 index 000000000..9ffa9c637 --- /dev/null +++ b/examples/cloud_idp/GetCloudIdentityProviders/GetCloudIdentityProviders.go @@ -0,0 +1,36 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Optional: Define sort filter (e.g., "id:asc" or "displayName:desc") + sortFilter := "id:desc" + + // Call GetCloudIdentityProviders function + cloudIdps, err := client.GetCloudIdentityProviders(sortFilter) + if err != nil { + log.Fatalf("Error fetching cloud identity providers: %v", err) + } + + // Pretty print the cloud identity providers in JSON + JSON, err := json.MarshalIndent(cloudIdps, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling cloud identity providers data: %v", err) + } + fmt.Println("Cloud Identity Providers:\n", string(JSON)) +} diff --git a/examples/account_driven_user_enrollment_access_group/CreateAccountDrivenUserEnrollmentAccessGroup/CreateAccountDrivenUserEnrollmentAccessGroup.go b/examples/enrollment/CreateAccountDrivenUserEnrollmentAccessGroup/CreateAccountDrivenUserEnrollmentAccessGroup.go similarity index 100% rename from examples/account_driven_user_enrollment_access_group/CreateAccountDrivenUserEnrollmentAccessGroup/CreateAccountDrivenUserEnrollmentAccessGroup.go rename to examples/enrollment/CreateAccountDrivenUserEnrollmentAccessGroup/CreateAccountDrivenUserEnrollmentAccessGroup.go diff --git a/examples/enrollment/DeleteMultipleEnrollmentMessagesByLanguageIDs/DeleteMultipleEnrollmentMessagesByLanguageIDs.go b/examples/enrollment/DeleteMultipleEnrollmentMessagesByLanguageIDs/DeleteMultipleEnrollmentMessagesByLanguageIDs.go new file mode 100644 index 000000000..7bd19e2db --- /dev/null +++ b/examples/enrollment/DeleteMultipleEnrollmentMessagesByLanguageIDs/DeleteMultipleEnrollmentMessagesByLanguageIDs.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the language IDs to delete + languageIds := []string{"en", "fr", "es"} + + // Call DeleteMultipleEnrollmentMessagesByLanguageIDs function + err = client.DeleteMultipleEnrollmentMessagesByLanguageIDs(languageIds) + if err != nil { + log.Fatalf("Error deleting enrollment language messages: %v", err) + } + + fmt.Printf("Successfully deleted enrollment messages for languages: %v\n", languageIds) +} diff --git a/examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroupByID/GetAccountDrivenUserEnrollmentAccessGroupByID.go b/examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroupByID/GetAccountDrivenUserEnrollmentAccessGroupByID.go similarity index 100% rename from examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroupByID/GetAccountDrivenUserEnrollmentAccessGroupByID.go rename to examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroupByID/GetAccountDrivenUserEnrollmentAccessGroupByID.go diff --git a/examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroupByName/GetAccountDrivenUserEnrollmentAccessGroupByName.go b/examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroupByName/GetAccountDrivenUserEnrollmentAccessGroupByName.go similarity index 100% rename from examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroupByName/GetAccountDrivenUserEnrollmentAccessGroupByName.go rename to examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroupByName/GetAccountDrivenUserEnrollmentAccessGroupByName.go diff --git a/examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroups/GetAccountDrivenUserEnrollmentAccessGroups.go b/examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroups/GetAccountDrivenUserEnrollmentAccessGroups.go similarity index 100% rename from examples/account_driven_user_enrollment_access_group/GetAccountDrivenUserEnrollmentAccessGroups/GetAccountDrivenUserEnrollmentAccessGroups.go rename to examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroups/GetAccountDrivenUserEnrollmentAccessGroups.go diff --git a/examples/enrollment/GetEnrollment/GetEnrollment.go b/examples/enrollment/GetEnrollment/GetEnrollment.go new file mode 100644 index 000000000..fa9d852bd --- /dev/null +++ b/examples/enrollment/GetEnrollment/GetEnrollment.go @@ -0,0 +1,33 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Call GetEnrollment function + enrollment, err := client.GetEnrollment() + if err != nil { + log.Fatalf("Error getting enrollment configuration: %v", err) + } + + // Pretty print the enrollment configuration in JSON + JSON, err := json.MarshalIndent(enrollment, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling enrollment data: %v", err) + } + fmt.Println("Current Enrollment Configuration:\n", string(JSON)) +} diff --git a/examples/enrollment/GetEnrollmentLanguageCodes/GetEnrollmentLanguageCodes.go b/examples/enrollment/GetEnrollmentLanguageCodes/GetEnrollmentLanguageCodes.go new file mode 100644 index 000000000..4c18a7b58 --- /dev/null +++ b/examples/enrollment/GetEnrollmentLanguageCodes/GetEnrollmentLanguageCodes.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + languageCodes, err := client.GetEnrollmentLanguageCodes() + if err != nil { + log.Fatalf("Error getting enrollment language codes: %v", err) + } + + JSON, err := json.MarshalIndent(languageCodes, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling language codes data: %v", err) + } + fmt.Println("Available Language Codes:\n", string(JSON)) +} diff --git a/examples/enrollment/GetEnrollmentMessageByLanguageID/GetEnrollmentMessageByLanguageID.go b/examples/enrollment/GetEnrollmentMessageByLanguageID/GetEnrollmentMessageByLanguageID.go new file mode 100644 index 000000000..f2c4dd77a --- /dev/null +++ b/examples/enrollment/GetEnrollmentMessageByLanguageID/GetEnrollmentMessageByLanguageID.go @@ -0,0 +1,36 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Specify the language ID (ISO 639-1 code) + languageId := "en" + + // Call GetEnrollmentMessageByLanguageID function + languageMsg, err := client.GetEnrollmentMessageByLanguageID(languageId) + if err != nil { + log.Fatalf("Error getting enrollment language messaging: %v", err) + } + + // Pretty print the language messaging configuration in JSON + JSON, err := json.MarshalIndent(languageMsg, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling language messaging data: %v", err) + } + fmt.Println("Enrollment Language Messaging Configuration:\n", string(JSON)) +} diff --git a/examples/enrollment/UpdateAccountDrivenUserEnrollmentAccessGroupByID/UpdateAccountDrivenUserEnrollmentAccessGroupByID.go b/examples/enrollment/UpdateAccountDrivenUserEnrollmentAccessGroupByID/UpdateAccountDrivenUserEnrollmentAccessGroupByID.go new file mode 100644 index 000000000..9cfe3648f --- /dev/null +++ b/examples/enrollment/UpdateAccountDrivenUserEnrollmentAccessGroupByID/UpdateAccountDrivenUserEnrollmentAccessGroupByID.go @@ -0,0 +1,47 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the ID of the group to update + groupID := "1" + + groupUpdate := &jamfpro.ResourceAccountDrivenUserEnrollmentAccessGroup{ + ID: groupID, + GroupID: "12345", + LdapServerID: "1", + Name: "Updated ADUE Access Group", + SiteID: "-1", + EnterpriseEnrollmentEnabled: true, + PersonalEnrollmentEnabled: false, + AccountDrivenUserEnrollmentEnabled: true, + RequireEula: true, + } + + updatedGroup, err := client.UpdateAccountDrivenUserEnrollmentAccessGroupByID(groupID, groupUpdate) + if err != nil { + log.Fatalf("Error updating ADUE access group: %v", err) + } + + // Pretty print the updated group in JSON + JSON, err := json.MarshalIndent(updatedGroup, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling updated group data: %v", err) + } + fmt.Printf("Updated ADUE Access Group:\n%s\n", string(JSON)) +} diff --git a/examples/enrollment/UpdateEnrollment/UpdateEnrollment.go b/examples/enrollment/UpdateEnrollment/UpdateEnrollment.go new file mode 100644 index 000000000..cba2c0846 --- /dev/null +++ b/examples/enrollment/UpdateEnrollment/UpdateEnrollment.go @@ -0,0 +1,94 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Create an enrollment configuration with all available options + enrollmentConfig := &jamfpro.ResourceEnrollment{ + // Basic Configuration + InstallSingleProfile: false, + SigningMdmProfileEnabled: false, + + // MDM Signing Certificate Configuration + MdmSigningCertificate: &jamfpro.ResourceEnrollmentCertificate{ + Filename: "null", + KeystorePassword: "thing", + IdentityKeystore: "WlhoaGJYQnNaU0J2WmlCaElHSmhjMlUyTkNCbGJtTnZaR1ZrSUhaaGJHbGtJSEF4TWk0Z2EyVjVjM1J2Y21VZ1ptbHNaUT09", + }, + + // Enrollment Restrictions and Cleanup + RestrictReenrollment: false, + FlushLocationInformation: false, + FlushLocationHistoryInformation: false, + FlushPolicyHistory: false, + FlushExtensionAttributes: false, + FlushSoftwareUpdatePlans: false, + FlushMdmCommandsOnReenroll: "DELETE_EVERYTHING_EXCEPT_ACKNOWLEDGED", // Options: DELETE_NOTHING/DELETE_ERRORS/DELETE_EVERYTHING_EXCEPT_ACKNOWLEDGED/DELETE_EVERYTHING + + // macOS Management Configuration + MacOsEnterpriseEnrollmentEnabled: false, + ManagementUsername: "radmin", + CreateManagementAccount: true, + HideManagementAccount: false, + AllowSshOnlyManagementAccount: false, + EnsureSshRunning: true, + LaunchSelfService: false, + SignQuickAdd: false, + + // Developer Certificate Configuration + DeveloperCertificateIdentity: &jamfpro.ResourceEnrollmentCertificate{ + Filename: "null", + KeystorePassword: "", + IdentityKeystore: "", + }, + + // Certificate Details + DeveloperCertificateIdentityDetails: jamfpro.ResourceCertificateDetails{ + Subject: "", + SerialNumber: "", + }, + MdmSigningCertificateDetails: jamfpro.ResourceCertificateDetails{ + Subject: "", + SerialNumber: "", + }, + + // iOS/Mobile Device Enrollment Configuration + IosEnterpriseEnrollmentEnabled: true, + IosPersonalEnrollmentEnabled: false, + PersonalDeviceEnrollmentType: "PERSONALDEVICEPROFILES", // Options: PERSONALDEVICEPROFILES/USERENROLLMENT + + // Account Driven Enrollment Configuration + AccountDrivenUserEnrollmentEnabled: false, + AccountDrivenDeviceIosEnrollmentEnabled: false, + AccountDrivenDeviceMacosEnrollmentEnabled: false, + AccountDrivenUserVisionosEnrollmentEnabled: false, + AccountDrivenDeviceVisionosEnrollmentEnabled: false, + } + + updatedEnrollment, err := client.UpdateEnrollment(enrollmentConfig) + if err != nil { + log.Fatalf("Error updating enrollment configuration: %v", err) + } + + // Pretty print the updated enrollment configuration in JSON + JSON, err := json.MarshalIndent(updatedEnrollment, "", " ") + if err != nil { + log.Fatalf("Error marshaling enrollment data: %v", err) + } + fmt.Println("Updated Enrollment Configuration:\n", string(JSON)) +} diff --git a/examples/enrollment/UpdateEnrollmentMessageByLanguageID/UpdateEnrollmentMessageByLanguageID.go b/examples/enrollment/UpdateEnrollmentMessageByLanguageID/UpdateEnrollmentMessageByLanguageID.go new file mode 100644 index 000000000..d61797fc0 --- /dev/null +++ b/examples/enrollment/UpdateEnrollmentMessageByLanguageID/UpdateEnrollmentMessageByLanguageID.go @@ -0,0 +1,102 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Create enrollment message configuration with all available fields + enrollmentMessage := &jamfpro.ResourceEnrollmentLanguage{ + LanguageCode: "en", + Name: "English", + Title: "Enroll Your Device", + LoginDescription: "Log in to enroll your device.", + Username: "Username", + Password: "Password", + LoginButton: "Log in", + + // Device Class Settings + DeviceClassDescription: "Specify if this device is institutionally owned or personally owned.", + DeviceClassPersonal: "Personally Owned", + DeviceClassPersonalDescription: "For personally owned devices, IT administrators **can**:\n\n* Lock the device\n* Apply institutional settings\n* Install and remove institutional data\n* Install and remove institutional apps\n\n\nFor personally owned devices, IT administrators **cannot**:\n\n* Wipe all data and settings from your device\n* Track the location of your device\n* Remove anything they did not install\n* Add/remove configuration profiles\n* Add/remove provisioning profiles", + DeviceClassEnterprise: "Institutionally Owned", + DeviceClassEnterpriseDescription: "For institutionally owned devices, IT administrators **can**:\n\n* Wipe all data and settings from the device\n* Lock the device\n* Remove the passcode\n* Apply institutional settings\n* Install and remove institutional data\n* Install and remove institutional apps\n* Add/remove configuration profiles\n* Add/remove provisioning profiles\n\nFor institutionally owned devices, IT administrators **cannot**:\n\n* Remove anything they did not install\n* Track the location of the device", + DeviceClassButton: "Enroll", + + // EULA Settings + PersonalEula: "", + EnterpriseEula: "", + EulaButton: "Accept", + + // Site Settings + SiteDescription: "Select the site to use for enrolling this computer or mobile device.", + + // Certificate Settings + CertificateText: "To continue with enrollment, you need to install the CA certificate for your organization.", + CertificateButton: "Continue", + CertificateProfileName: "CA Certificate", + CertificateProfileDescription: "CA Certificate for mobile device management", + + // Personal Device Settings + PersonalText: "To continue with enrollment, you need to install the MDM profile.", + PersonalButton: "Continue", + PersonalProfileName: "MDM Profile", + PersonalProfileDescription: "MDM Profile for mobile device management", + + // User Enrollment Settings + UserEnrollmentText: "Enter your Managed Apple Id to install the MDM Profile.", + UserEnrollmentButton: "Continue", + UserEnrollmentProfileName: "MDM Profile", + UserEnrollmentProfileDescription: "MDM Profile for mobile device management", + + // Enterprise Settings + EnterpriseText: "To continue with enrollment, you need to install the MDM profile for your organization.", + EnterpriseButton: "Continue", + EnterpriseProfileName: "MDM Profile", + EnterpriseProfileDescription: "MDM Profile for mobile device management", + EnterprisePending: "To continue with enrollment, install the CA Certificate and MDM Profile that were downloaded to your computer.", + + // QuickAdd Settings + QuickAddText: "Download and install this package.", + QuickAddButton: "Download", + QuickAddName: "QuickAdd.pkg", + QuickAddPending: "Install the downloaded QuickAdd.pkg.", + + // Status Messages + CompleteMessage: "The enrollment process is complete.", + FailedMessage: "The enrollment process could not be completed. Contact your IT administrator.", + TryAgainButton: "Try Again", + CheckNowButton: "Proceed", + CheckEnrollmentMessage: "Tap \"Proceed\" to view the enrollment status for this device.", + LogoutButton: "Log Out", + } + + // Specify the language ID to update + languageId := "en" + + // Call UpdateEnrollmentMessageByLanguageID function + updatedMessage, err := client.UpdateEnrollmentMessageByLanguageID(languageId, enrollmentMessage) + if err != nil { + log.Fatalf("Error updating enrollment language messaging: %v", err) + } + + // Pretty print the updated configuration in JSON + JSON, err := json.MarshalIndent(updatedMessage, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling updated language messaging data: %v", err) + } + fmt.Println("Updated Enrollment Language Messaging Configuration:\n", string(JSON)) +} diff --git a/examples/account_driven_user_enrollment_access_group/_test/Create100AccountGroups/Create100AccountGroups.go b/examples/enrollment/_test/Create100AccountGroups/Create100AccountGroups.go similarity index 100% rename from examples/account_driven_user_enrollment_access_group/_test/Create100AccountGroups/Create100AccountGroups.go rename to examples/enrollment/_test/Create100AccountGroups/Create100AccountGroups.go diff --git a/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/UploadEnrollmentCustomizationsImage.go b/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/UploadEnrollmentCustomizationsImage.go new file mode 100644 index 000000000..b59623560 --- /dev/null +++ b/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/UploadEnrollmentCustomizationsImage.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the path to the icon file + imagePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/self_service.png" + + response, err := client.UploadEnrollmentCustomizationsImage(imagePath) + if err != nil { + fmt.Println("Error uploading icon:", err) + return + } + + // Pretty print the icon details + iconJSON, err := json.MarshalIndent(response, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling accounts data: %v", err) + } + fmt.Println("Fetched Icon:", string(iconJSON)) +} diff --git a/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/self_service.png b/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/self_service.png new file mode 100644 index 000000000..8098b94c1 Binary files /dev/null and b/examples/enrollment_customizations/UploadEnrollmentCustomizationsImage/self_service.png differ diff --git a/examples/adue_token_settings/GetADUESessionTokenSettings/GetADUESessionTokenSettings.go b/examples/enrollment_settings/GetADUESessionTokenSettings/GetADUESessionTokenSettings.go similarity index 100% rename from examples/adue_token_settings/GetADUESessionTokenSettings/GetADUESessionTokenSettings.go rename to examples/enrollment_settings/GetADUESessionTokenSettings/GetADUESessionTokenSettings.go diff --git a/examples/enrollment_settings/GetEnrollmentSettings/GetEnrollmentSettings.go b/examples/enrollment_settings/GetEnrollmentSettings/GetEnrollmentSettings.go new file mode 100644 index 000000000..fc5c712cb --- /dev/null +++ b/examples/enrollment_settings/GetEnrollmentSettings/GetEnrollmentSettings.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + resp, err := client.GetEnrollmentSettings() + if err != nil { + log.Fatalf("Error fetching Enrollment Settings: %v", err) + } + + jsonData, err := json.MarshalIndent(resp, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling data: %v", err) + } + fmt.Println("Fetched data:\n", string(jsonData)) + +} diff --git a/examples/adue_token_settings/UpdateADUESessionTokenSettings/UpdateADUESessionTokenSettings.go b/examples/enrollment_settings/UpdateADUESessionTokenSettings/UpdateADUESessionTokenSettings.go similarity index 100% rename from examples/adue_token_settings/UpdateADUESessionTokenSettings/UpdateADUESessionTokenSettings.go rename to examples/enrollment_settings/UpdateADUESessionTokenSettings/UpdateADUESessionTokenSettings.go diff --git a/examples/jamf_pro_system_initialization/InitializeDatabaseConnection/InitializeDatabaseConnection.go b/examples/jamf_pro_system_initialization/InitializeDatabaseConnection/InitializeDatabaseConnection.go new file mode 100644 index 000000000..c1e798daa --- /dev/null +++ b/examples/jamf_pro_system_initialization/InitializeDatabaseConnection/InitializeDatabaseConnection.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the database password + databasePassword := "your-secure-database-password" + + // Call InitializeDatabaseConnection function + err = client.InitializeDatabaseConnection(databasePassword) + if err != nil { + log.Fatalf("Error initializing database connection: %v", err) + } + + fmt.Println("Successfully initialized database connection.") +} diff --git a/examples/jamf_pro_system_initialization/InitializeJamfProServer/InitializeJamfProServer.go b/examples/jamf_pro_system_initialization/InitializeJamfProServer/InitializeJamfProServer.go new file mode 100644 index 000000000..1a8c903c9 --- /dev/null +++ b/examples/jamf_pro_system_initialization/InitializeJamfProServer/InitializeJamfProServer.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Create system initialization configuration + systemConfig := &jamfpro.ResourceSystemInitialize{ + ActivationCode: "XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX", + InstitutionName: "My Organization", + EulaAccepted: true, + Username: "admin", + Password: "password123", + Email: "admin@example.com", + JssUrl: "https://example.jamfcloud.com", + } + + // Call InitializeJamfProServer function + err = client.InitializeJamfProServer(systemConfig) + if err != nil { + log.Fatalf("Error initializing Jamf Pro server: %v", err) + } + + fmt.Println("Successfully initialized Jamf Pro server.") +} diff --git a/examples/policies/GetPolicyByID/GetPolicyByID.go b/examples/policies/GetPolicyByID/GetPolicyByID.go index d8b538ee9..44120691b 100644 --- a/examples/policies/GetPolicyByID/GetPolicyByID.go +++ b/examples/policies/GetPolicyByID/GetPolicyByID.go @@ -19,7 +19,7 @@ func main() { } // Define a policy ID for testing - policyID := "2424" // Replace with the actual policy ID you want to fetch + policyID := "2425" // Replace with the actual policy ID you want to fetch // Call GetPolicyByID function policy, err := client.GetPolicyByID(policyID) diff --git a/examples/self_service/UploadSelfServiceBrandingImage/UploadSelfServiceBrandingImage.go b/examples/self_service/UploadSelfServiceBrandingImage/UploadSelfServiceBrandingImage.go new file mode 100644 index 000000000..073f03df1 --- /dev/null +++ b/examples/self_service/UploadSelfServiceBrandingImage/UploadSelfServiceBrandingImage.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Define the path to the icon file + iconPath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/examples/self_service/UploadSelfServiceBrandingImage/self_service.png" + + response, err := client.UploadSelfServiceBrandingImage(iconPath) + if err != nil { + fmt.Println("Error uploading icon:", err) + return + } + + // Pretty print the icon details + iconJSON, err := json.MarshalIndent(response, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling accounts data: %v", err) + } + fmt.Println("Fetched Icon:", string(iconJSON)) +} diff --git a/examples/self_service/UploadSelfServiceBrandingImage/self_service.png b/examples/self_service/UploadSelfServiceBrandingImage/self_service.png new file mode 100644 index 000000000..8098b94c1 Binary files /dev/null and b/examples/self_service/UploadSelfServiceBrandingImage/self_service.png differ diff --git a/examples/startup_status/GetStartupStatus/GetStartupStatus.go b/examples/startup_status/GetStartupStatus/GetStartupStatus.go new file mode 100644 index 000000000..9481d68b4 --- /dev/null +++ b/examples/startup_status/GetStartupStatus/GetStartupStatus.go @@ -0,0 +1,33 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + + // Initialize the Jamf Pro client with the HTTP client configuration + client, err := jamfpro.BuildClientWithConfigFile(configFilePath) + if err != nil { + log.Fatalf("Failed to initialize Jamf Pro client: %v", err) + } + + // Call GetStartupStatus function + startupStatus, err := client.GetStartupStatus() + if err != nil { + log.Fatalf("Error fetching startup status: %v", err) + } + + // Pretty print the startup status in JSON + JSON, err := json.MarshalIndent(startupStatus, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling startup status data: %v", err) + } + fmt.Println("Jamf Pro Startup Status:\n", string(JSON)) +} diff --git a/sdk/jamfpro/jamfproapi_adue_access_group.go b/sdk/jamfpro/jamfproapi_adue_access_group.go deleted file mode 100644 index dfebe2800..000000000 --- a/sdk/jamfpro/jamfproapi_adue_access_group.go +++ /dev/null @@ -1,182 +0,0 @@ -// jamfproapi_adue_access_group.go -// Jamf Pro Api - Enrollment -// api reference: https://developer.jamf.com/jamf-pro/reference/get_v3-enrollment-access-groups -// Jamf Pro API requires the structs to support a JSON data structure. - -package jamfpro - -import ( - "fmt" - - "github.com/mitchellh/mapstructure" -) - -const uriAccountDrivenUserEnrollment = "/api/v3/enrollment" - -// List - -// ResponseAccountDrivenUserEnrollmentAccessGroups represents the structure of the response for a list of access groups - -type ResponseAccountDrivenUserEnrollmentAccessGroupsList struct { - TotalCount int `json:"totalCount"` - Results []ResourceAccountDrivenUserEnrollmentAccessGroup `json:"results"` -} - -type ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate struct { - ID string `json:"id"` - Href string `json:"href"` -} - -// Resource - -type ResourceAccountDrivenUserEnrollmentAccessGroup struct { - ID string `json:"id"` - GroupID string `json:"groupId"` - LdapServerID string `json:"ldapServerId"` - Name string `json:"name"` - SiteID string `json:"siteId"` - EnterpriseEnrollmentEnabled bool `json:"enterpriseEnrollmentEnabled"` - PersonalEnrollmentEnabled bool `json:"personalEnrollmentEnabled"` - AccountDrivenUserEnrollmentEnabled bool `json:"accountDrivenUserEnrollmentEnabled"` - RequireEula bool `json:"requireEula"` -} - -// CRUD - -// GetAccountDrivenUserEnrollmentAccessGroups fetches all ADUE access groups -func (c *Client) GetAccountDrivenUserEnrollmentAccessGroups(sort_filter string) (*ResponseAccountDrivenUserEnrollmentAccessGroupsList, error) { - endpoint := uriAccountDrivenUserEnrollment - resp, err := c.DoPaginatedGet(endpoint, standardPageSize, 0, sort_filter) - if err != nil { - return nil, fmt.Errorf(errMsgFailedPaginatedGet, "ADUE Access Group List", err) - } - - var OutStruct ResponseAccountDrivenUserEnrollmentAccessGroupsList - OutStruct.TotalCount = resp.Size - for _, value := range resp.Results { - var newObj ResourceAccountDrivenUserEnrollmentAccessGroup - err := mapstructure.Decode(value, &newObj) - if err != nil { - return nil, fmt.Errorf(errMsgFailedMapstruct, "ADUE Access Group List", err) - } - OutStruct.Results = append(OutStruct.Results, newObj) - } - - return &OutStruct, nil -} - -// Retrieves AccountDrivenUserEnrollmentAccessGroup from provided ID & returns ResourceAccountDrivenUserEnrollmentAccessGroup -func (c *Client) GetAccountDrivenUserEnrollmentAccessGroupByID(id string) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { - endpoint := fmt.Sprintf("%s/access-groups/%s", uriAccountDrivenUserEnrollment, id) - - var ADUEGroup ResourceAccountDrivenUserEnrollmentAccessGroup - resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &ADUEGroup) - - if err != nil { - return nil, fmt.Errorf(errMsgFailedGetByID, "ADUE Access Group", id, err) - } - - if resp != nil && resp.Body != nil { - defer resp.Body.Close() - } - - return &ADUEGroup, nil -} - -// GetAccountDrivenUserEnrollmentAccessGroupByName retrieves an Account Driven User Enrollment Access Group by its name -func (c *Client) GetAccountDrivenUserEnrollmentAccessGroupByName(name string) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { - accessGroupsList, err := c.GetAccountDrivenUserEnrollmentAccessGroups("") - if err != nil { - return nil, fmt.Errorf(errMsgFailedPaginatedGet, "ADUE access group", err) - } - - for _, group := range accessGroupsList.Results { - if group.Name == name { - return &group, nil - } - } - - return nil, fmt.Errorf(errMsgFailedGetByName, "ADUE access group", name, errMsgNoName) -} - -// Creates Account Driven User Enrollment Access Group from ResourceScript struct -func (c *Client) CreateAccountDrivenUserEnrollmentAccessGroup(script *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate, error) { - endpoint := uriScripts - var out ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate - - resp, err := c.HTTP.DoRequest("POST", endpoint, script, &out) - if err != nil { - return nil, fmt.Errorf(errMsgFailedCreate, "ADUE access group", err) - } - - if resp != nil { - defer resp.Body.Close() - } - - return &out, nil -} - -// UpdateAccountDrivenUserEnrollmentAccessGroupByID updates an ADUE access group by resource ID -func (c *Client) UpdateAccountDrivenUserEnrollmentAccessGroupByID(id string, groupUpdate *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { - endpoint := fmt.Sprintf("%s/access-groups/%s", uriAccountDrivenUserEnrollment, id) - var out ResourceAccountDrivenUserEnrollmentAccessGroup - - resp, err := c.HTTP.DoRequest("PUT", endpoint, groupUpdate, &out) - if err != nil { - return nil, fmt.Errorf(errMsgFailedUpdateByID, "ADUE Access Group", id, err) - } - - if resp != nil { - defer resp.Body.Close() - } - - return &out, nil -} - -// UpdateAccountDrivenUserEnrollmentAccessGroupByName updates an ADUE access group by resource name -func (c *Client) UpdateAccountDrivenUserEnrollmentAccessGroupByName(targetName string, groupUpdate *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { - target, err := c.GetAccountDrivenUserEnrollmentAccessGroupByName(targetName) - - if err != nil { - return nil, fmt.Errorf(errMsgFailedGetByName, "ADUE access group", targetName, err) - } - - resp, err := c.UpdateAccountDrivenUserEnrollmentAccessGroupByID(target.ID, groupUpdate) - if err != nil { - return nil, fmt.Errorf(errMsgFailedUpdateByName, "ADUE access group", targetName, err) - } - - return resp, nil -} - -// DeleteAccountDrivenUserEnrollmentAccessGroupByID deletes an ADUE access group with given id -func (c *Client) DeleteAccountDrivenUserEnrollmentAccessGroupByID(id string) error { - endpoint := fmt.Sprintf("%s/access-groups/%s", uriAccountDrivenUserEnrollment, id) - resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil) - - if err != nil || resp.StatusCode != 204 { - return fmt.Errorf(errMsgFailedDeleteByID, "ADUE access group", id, err) - } - - if resp != nil { - defer resp.Body.Close() - } - - return nil -} - -// DeleteAccountDrivenUserEnrollmentAccessGroupByName deletes an ADUE access group with given name, leverages GetAccountDrivenUserEnrollmentAccessGroupByName -func (c *Client) DeleteAccountDrivenUserEnrollmentAccessGroupByName(targetName string) error { - target, err := c.GetAccountDrivenUserEnrollmentAccessGroupByName(targetName) - if err != nil { - return fmt.Errorf(errMsgFailedGetByName, "ADUE access group", targetName, err) - } - - err = c.DeleteAccountDrivenUserEnrollmentAccessGroupByID(target.ID) - - if err != nil { - return fmt.Errorf(errMsgFailedDeleteByName, "ADUE access group", targetName, err) - } - - return nil -} diff --git a/sdk/jamfpro/jamfproapi_adue_token_settings.go b/sdk/jamfpro/jamfproapi_adue_token_settings.go deleted file mode 100644 index c84bab743..000000000 --- a/sdk/jamfpro/jamfproapi_adue_token_settings.go +++ /dev/null @@ -1,53 +0,0 @@ -// jamfproapi_account_driven_user_enrollment_token_settings.go -// Jamf Pro Api - Enrollment -// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-enrollment-history -// Jamf Pro API requires the structs to support a JSON data structure. - -package jamfpro - -import "fmt" - -const uriUserEnrollmentTokenSettings = "/api/v1/adue-session-token-settings" - -// structs - -type ResourceADUETokenSettings struct { - Enabled bool `json:"enabled"` - ExpirationIntervalDays int `json:"expirationIntervalDays,omitempty"` - ExpirationIntervalSeconds int `json:"expirationIntervalSeconds,omitempty"` -} - -// CRUD - -func (c *Client) GetADUESessionTokenSettings() (*ResourceADUETokenSettings, error) { - endpoint := uriUserEnrollmentTokenSettings - var out ResourceADUETokenSettings - - resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out) - if err != nil { - return nil, fmt.Errorf(errMsgFailedGet, "ADUE token settings", err) - } - - if resp != nil && resp.Body != nil { - defer resp.Body.Close() - } - - return &out, nil - -} - -func (c *Client) UpdateADUESessionTokenSettings(updatedSettings ResourceADUETokenSettings) (*ResourceADUETokenSettings, error) { - endpoint := uriUserEnrollmentTokenSettings - var out ResourceADUETokenSettings - - resp, err := c.HTTP.DoRequest("PUT", endpoint, updatedSettings, &out) - if err != nil { - return nil, fmt.Errorf(errMsgFailedUpdate, "ADUE token settings", err) - } - - if resp != nil && resp.Body != nil { - defer resp.Body.Close() - } - - return &out, nil -} diff --git a/sdk/jamfpro/jamfproapi_cloud_idp.go b/sdk/jamfpro/jamfproapi_cloud_idp.go new file mode 100644 index 000000000..6c04d7c7e --- /dev/null +++ b/sdk/jamfpro/jamfproapi_cloud_idp.go @@ -0,0 +1,79 @@ +// jamfproapi_cloud_idp.go +// Jamf Pro Api - Cloud Identity Provider +// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-cloud-idp +// Jamf Pro API requires the structs to support a JSON data structure. + +package jamfpro + +import ( + "fmt" + + "github.com/mitchellh/mapstructure" +) + +// Endpoints +const uriCloudIdp = "/api/v1/cloud-idp" + +// Response + +// ResponseCloudIdentityProvidersList struct for cloud identity providers list +type ResponseCloudIdentityProvidersList struct { + TotalCount int `json:"totalCount"` + Results []ResourceCloudIdentityProvider `json:"results"` +} + +// Resource + +// ResourceCloudIdentityProvider struct for cloud identity provider +type ResourceCloudIdentityProvider struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + Enabled bool `json:"enabled"` + ProviderName string `json:"providerName"` +} + +// GetCloudIdentityProviders retrieves all cloud identity provider configurations +func (c *Client) GetCloudIdentityProviders(sort_filter string) (*ResponseCloudIdentityProvidersList, error) { + endpoint := uriCloudIdp + resp, err := c.DoPaginatedGet(endpoint, standardPageSize, 0, sort_filter) + if err != nil { + return nil, fmt.Errorf(errMsgFailedPaginatedGet, "cloud identity providers", err) + } + + var OutStruct ResponseCloudIdentityProvidersList + OutStruct.TotalCount = resp.Size + for _, value := range resp.Results { + var newObj ResourceCloudIdentityProvider + err := mapstructure.Decode(value, &newObj) + if err != nil { + return nil, fmt.Errorf(errMsgFailedMapstruct, "cloud identity provider", err) + } + OutStruct.Results = append(OutStruct.Results, newObj) + } + + return &OutStruct, nil +} + +// ResourceCloudIdentityProviderDetails represents a single cloud identity provider configuration +type ResourceCloudIdentityProviderDetails struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + ProviderName string `json:"providerName"` +} + +// GetCloudIdentityProviderConfigurationByID retrieves a specific cloud identity provider configuration by its ID +func (c *Client) GetCloudIdentityProviderConfigurationByID(id string) (*ResourceCloudIdentityProviderDetails, error) { + endpoint := fmt.Sprintf("%s/%s", uriCloudIdp, id) + + var cloudIdp ResourceCloudIdentityProviderDetails + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &cloudIdp) + if err != nil { + return nil, fmt.Errorf(errMsgFailedGetByID, "cloud identity provider", id, err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &cloudIdp, nil +} diff --git a/sdk/jamfpro/jamfproapi_declarative_device_management.go b/sdk/jamfpro/jamfproapi_declarative_device_management.go index 1cda94027..52d5de8d1 100644 --- a/sdk/jamfpro/jamfproapi_declarative_device_management.go +++ b/sdk/jamfpro/jamfproapi_declarative_device_management.go @@ -11,20 +11,6 @@ import ( const uriDeclarativeDeviceManagement = "/api/v1/ddm" -// ResponseError represents the structure of an error response from the API -type ResponseError struct { - HTTPStatus int `json:"httpStatus"` - Errors []ErrorInstance `json:"errors"` -} - -// ErrorInstance represents a single error in the error response -type ErrorInstance struct { - Code string `json:"code"` - Field string `json:"field"` - Description string `json:"description"` - ID string `json:"id"` -} - // ResponseStatusItems represents the response structure for status items. type ResponseStatusItems struct { StatusItems []StatusItem `json:"statusItems"` diff --git a/sdk/jamfpro/jamfproapi_enrollment.go b/sdk/jamfpro/jamfproapi_enrollment.go new file mode 100644 index 000000000..24f863923 --- /dev/null +++ b/sdk/jamfpro/jamfproapi_enrollment.go @@ -0,0 +1,425 @@ +// jamfproapi_enrollment.go +// Jamf Pro Api - Enrollment +// api reference: https://developer.jamf.com/jamf-pro/reference/put_v4-enrollment +// Jamf Pro API requires the structs to support a JSON data structure. + +package jamfpro + +import ( + "encoding/json" + "fmt" + + "github.com/mitchellh/mapstructure" +) + +const uriEnrollmentV3 = "/api/v3/enrollment" +const uriEnrollmentV4 = "/api/v4/enrollment" + +// List + +// ResponseAccountDrivenUserEnrollmentAccessGroups represents the structure of the response for a list of access groups + +type ResponseAccountDrivenUserEnrollmentAccessGroupsList struct { + TotalCount int `json:"totalCount"` + Results []ResourceAccountDrivenUserEnrollmentAccessGroup `json:"results"` +} + +type ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate struct { + ID string `json:"id"` + Href string `json:"href"` +} + +// Request + +// RequestDeleteMultipleLanguages represents the request body for deleting multiple languages +type RequestDeleteMultipleLanguages struct { + IDs []string `json:"ids"` +} + +// Resource + +type ResourceAccountDrivenUserEnrollmentAccessGroup struct { + ID string `json:"id"` + GroupID string `json:"groupId"` + LdapServerID string `json:"ldapServerId"` + Name string `json:"name"` + SiteID string `json:"siteId"` + EnterpriseEnrollmentEnabled bool `json:"enterpriseEnrollmentEnabled"` + PersonalEnrollmentEnabled bool `json:"personalEnrollmentEnabled"` + AccountDrivenUserEnrollmentEnabled bool `json:"accountDrivenUserEnrollmentEnabled"` + RequireEula bool `json:"requireEula"` +} + +type ResourceEnrollment struct { + InstallSingleProfile bool `json:"installSingleProfile"` + SigningMdmProfileEnabled bool `json:"signingMdmProfileEnabled"` + MdmSigningCertificate *ResourceEnrollmentCertificate `json:"mdmSigningCertificate"` + RestrictReenrollment bool `json:"restrictReenrollment"` + FlushLocationInformation bool `json:"flushLocationInformation"` + FlushLocationHistoryInformation bool `json:"flushLocationHistoryInformation"` + FlushPolicyHistory bool `json:"flushPolicyHistory"` + FlushExtensionAttributes bool `json:"flushExtensionAttributes"` + FlushSoftwareUpdatePlans bool `json:"flushSoftwareUpdatePlans"` + FlushMdmCommandsOnReenroll string `json:"flushMdmCommandsOnReenroll"` + MacOsEnterpriseEnrollmentEnabled bool `json:"macOsEnterpriseEnrollmentEnabled"` + ManagementUsername string `json:"managementUsername"` + CreateManagementAccount bool `json:"createManagementAccount"` + HideManagementAccount bool `json:"hideManagementAccount"` + AllowSshOnlyManagementAccount bool `json:"allowSshOnlyManagementAccount"` + EnsureSshRunning bool `json:"ensureSshRunning"` + LaunchSelfService bool `json:"launchSelfService"` + SignQuickAdd bool `json:"signQuickAdd"` + DeveloperCertificateIdentity *ResourceEnrollmentCertificate `json:"developerCertificateIdentity"` + DeveloperCertificateIdentityDetails ResourceCertificateDetails `json:"developerCertificateIdentityDetails"` + MdmSigningCertificateDetails ResourceCertificateDetails `json:"mdmSigningCertificateDetails"` + IosEnterpriseEnrollmentEnabled bool `json:"iosEnterpriseEnrollmentEnabled"` + IosPersonalEnrollmentEnabled bool `json:"iosPersonalEnrollmentEnabled"` + PersonalDeviceEnrollmentType string `json:"personalDeviceEnrollmentType"` + AccountDrivenUserEnrollmentEnabled bool `json:"accountDrivenUserEnrollmentEnabled"` + AccountDrivenDeviceIosEnrollmentEnabled bool `json:"accountDrivenDeviceIosEnrollmentEnabled"` + AccountDrivenDeviceMacosEnrollmentEnabled bool `json:"accountDrivenDeviceMacosEnrollmentEnabled"` + AccountDrivenUserVisionosEnrollmentEnabled bool `json:"accountDrivenUserVisionosEnrollmentEnabled"` + AccountDrivenDeviceVisionosEnrollmentEnabled bool `json:"accountDrivenDeviceVisionosEnrollmentEnabled"` +} + +// Resource struct for enrollment language messaging +type ResourceEnrollmentLanguage struct { + LanguageCode string `json:"languageCode"` + Name string `json:"name"` + Title string `json:"title"` + LoginDescription string `json:"loginDescription"` + Username string `json:"username"` + Password string `json:"password"` + LoginButton string `json:"loginButton"` + DeviceClassDescription string `json:"deviceClassDescription"` + DeviceClassPersonal string `json:"deviceClassPersonal"` + DeviceClassPersonalDescription string `json:"deviceClassPersonalDescription"` + DeviceClassEnterprise string `json:"deviceClassEnterprise"` + DeviceClassEnterpriseDescription string `json:"deviceClassEnterpriseDescription"` + DeviceClassButton string `json:"deviceClassButton"` + PersonalEula string `json:"personalEula"` + EnterpriseEula string `json:"enterpriseEula"` + EulaButton string `json:"eulaButton"` + SiteDescription string `json:"siteDescription"` + CertificateText string `json:"certificateText"` + CertificateButton string `json:"certificateButton"` + CertificateProfileName string `json:"certificateProfileName"` + CertificateProfileDescription string `json:"certificateProfileDescription"` + PersonalText string `json:"personalText"` + PersonalButton string `json:"personalButton"` + PersonalProfileName string `json:"personalProfileName"` + PersonalProfileDescription string `json:"personalProfileDescription"` + UserEnrollmentText string `json:"userEnrollmentText"` + UserEnrollmentButton string `json:"userEnrollmentButton"` + UserEnrollmentProfileName string `json:"userEnrollmentProfileName"` + UserEnrollmentProfileDescription string `json:"userEnrollmentProfileDescription"` + EnterpriseText string `json:"enterpriseText"` + EnterpriseButton string `json:"enterpriseButton"` + EnterpriseProfileName string `json:"enterpriseProfileName"` + EnterpriseProfileDescription string `json:"enterpriseProfileDescription"` + EnterprisePending string `json:"enterprisePending"` + QuickAddText string `json:"quickAddText"` + QuickAddButton string `json:"quickAddButton"` + QuickAddName string `json:"quickAddName"` + QuickAddPending string `json:"quickAddPending"` + CompleteMessage string `json:"completeMessage"` + FailedMessage string `json:"failedMessage"` + TryAgainButton string `json:"tryAgainButton"` + CheckNowButton string `json:"checkNowButton"` + CheckEnrollmentMessage string `json:"checkEnrollmentMessage"` + LogoutButton string `json:"logoutButton"` +} + +type ResourceEnrollmentCertificate struct { + Filename string `json:"filename"` + KeystorePassword string `json:"keystorePassword,omitempty"` + IdentityKeystore string `json:"identityKeystore,omitempty"` + Md5Sum string `json:"md5Sum,omitempty"` +} + +type ResourceCertificateDetails struct { + Subject string `json:"subject"` + SerialNumber string `json:"serialNumber"` +} + +// Resource struct for language codes +type ResourceLanguageCode struct { + Value string `json:"value"` + Name string `json:"name"` +} + +// CRUD + +// GetAccountDrivenUserEnrollmentAccessGroups fetches all ADUE access groups +func (c *Client) GetAccountDrivenUserEnrollmentAccessGroups(sort_filter string) (*ResponseAccountDrivenUserEnrollmentAccessGroupsList, error) { + endpoint := fmt.Sprintf("%s/access-groups", uriEnrollmentV3) + resp, err := c.DoPaginatedGet(endpoint, standardPageSize, 0, sort_filter) + if err != nil { + return nil, fmt.Errorf(errMsgFailedPaginatedGet, "ADUE Access Group List", err) + } + + var OutStruct ResponseAccountDrivenUserEnrollmentAccessGroupsList + OutStruct.TotalCount = resp.Size + for _, value := range resp.Results { + var newObj ResourceAccountDrivenUserEnrollmentAccessGroup + err := mapstructure.Decode(value, &newObj) + if err != nil { + return nil, fmt.Errorf(errMsgFailedMapstruct, "ADUE Access Group List", err) + } + OutStruct.Results = append(OutStruct.Results, newObj) + } + + return &OutStruct, nil +} + +// GetAccountDrivenUserEnrollmentAccessGroupByID retrieves an Account Driven User Enrollment Access Group by its ID +func (c *Client) GetAccountDrivenUserEnrollmentAccessGroupByID(id string) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { + endpoint := fmt.Sprintf("%s/access-groups/%s", uriEnrollmentV3, id) + + var ADUEGroup ResourceAccountDrivenUserEnrollmentAccessGroup + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &ADUEGroup) + + if err != nil { + return nil, fmt.Errorf(errMsgFailedGetByID, "ADUE Access Group", id, err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &ADUEGroup, nil +} + +// GetAccountDrivenUserEnrollmentAccessGroupByName retrieves an Account Driven User Enrollment Access Group by its name +func (c *Client) GetAccountDrivenUserEnrollmentAccessGroupByName(name string) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { + accessGroupsList, err := c.GetAccountDrivenUserEnrollmentAccessGroups("") + if err != nil { + return nil, fmt.Errorf(errMsgFailedPaginatedGet, "ADUE access group", err) + } + + for _, group := range accessGroupsList.Results { + if group.Name == name { + return &group, nil + } + } + + return nil, fmt.Errorf(errMsgFailedGetByName, "ADUE access group", name, errMsgNoName) +} + +// CreateAccountDrivenUserEnrollmentAccessGroup creates a new ADUE access group +func (c *Client) CreateAccountDrivenUserEnrollmentAccessGroup(script *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate, error) { + endpoint := uriEnrollmentV3 + var out ResponseAccountDrivenUserEnrollmentAccessGroupCreateAndUpdate + + resp, err := c.HTTP.DoRequest("POST", endpoint, script, &out) + if err != nil { + return nil, fmt.Errorf(errMsgFailedCreate, "ADUE access group", err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &out, nil +} + +// UpdateAccountDrivenUserEnrollmentAccessGroupByID updates an ADUE access group by resource ID +func (c *Client) UpdateAccountDrivenUserEnrollmentAccessGroupByID(id string, groupUpdate *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { + endpoint := fmt.Sprintf("%s/access-groups/%s", uriEnrollmentV3, id) + var out ResourceAccountDrivenUserEnrollmentAccessGroup + + resp, err := c.HTTP.DoRequest("PUT", endpoint, groupUpdate, &out) + if err != nil { + return nil, fmt.Errorf(errMsgFailedUpdateByID, "ADUE Access Group", id, err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &out, nil +} + +// UpdateAccountDrivenUserEnrollmentAccessGroupByName updates an ADUE access group by resource name +func (c *Client) UpdateAccountDrivenUserEnrollmentAccessGroupByName(targetName string, groupUpdate *ResourceAccountDrivenUserEnrollmentAccessGroup) (*ResourceAccountDrivenUserEnrollmentAccessGroup, error) { + target, err := c.GetAccountDrivenUserEnrollmentAccessGroupByName(targetName) + + if err != nil { + return nil, fmt.Errorf(errMsgFailedGetByName, "ADUE access group", targetName, err) + } + + resp, err := c.UpdateAccountDrivenUserEnrollmentAccessGroupByID(target.ID, groupUpdate) + if err != nil { + return nil, fmt.Errorf(errMsgFailedUpdateByName, "ADUE access group", targetName, err) + } + + return resp, nil +} + +// DeleteAccountDrivenUserEnrollmentAccessGroupByID deletes an ADUE access group with given id +func (c *Client) DeleteAccountDrivenUserEnrollmentAccessGroupByID(id string) error { + endpoint := fmt.Sprintf("%s/access-groups/%s", uriEnrollmentV3, id) + resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil) + + if err != nil || resp.StatusCode != 204 { + return fmt.Errorf(errMsgFailedDeleteByID, "ADUE access group", id, err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return nil +} + +// DeleteAccountDrivenUserEnrollmentAccessGroupByName deletes an ADUE access group with given name, leverages GetAccountDrivenUserEnrollmentAccessGroupByName +func (c *Client) DeleteAccountDrivenUserEnrollmentAccessGroupByName(targetName string) error { + target, err := c.GetAccountDrivenUserEnrollmentAccessGroupByName(targetName) + if err != nil { + return fmt.Errorf(errMsgFailedGetByName, "ADUE access group", targetName, err) + } + + err = c.DeleteAccountDrivenUserEnrollmentAccessGroupByID(target.ID) + + if err != nil { + return fmt.Errorf(errMsgFailedDeleteByName, "ADUE access group", targetName, err) + } + + return nil +} + +// GetEnrollment retrieves the current enrollment configuration +func (c *Client) GetEnrollment() (*ResourceEnrollment, error) { + endpoint := uriEnrollmentV4 + var enrollment ResourceEnrollment + + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &enrollment) + if err != nil { + return nil, fmt.Errorf("failed to get enrollment configuration: %v", err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &enrollment, nil +} + +// UpdateEnrollment updates the enrollment configuration +func (c *Client) UpdateEnrollment(enrollmentUpdate *ResourceEnrollment) (*ResourceEnrollment, error) { + endpoint := uriEnrollmentV4 + var out ResourceEnrollment + + resp, err := c.HTTP.DoRequest("PUT", endpoint, enrollmentUpdate, &out) + if err != nil { + return nil, fmt.Errorf("failed to update enrollment configuration: %v", err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &out, nil +} + +// GetEnrollmentMessageByLanguageID retrieves the enrollment language messaging for a specific language ID +func (c *Client) GetEnrollmentMessageByLanguageID(languageId string) (*ResourceEnrollmentLanguage, error) { + endpoint := fmt.Sprintf("%s/languages/%s", uriEnrollmentV3, languageId) + var languageMsg ResourceEnrollmentLanguage + + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &languageMsg) + if err != nil { + return nil, fmt.Errorf("failed to get enrollment language messaging for language ID '%s': %v", languageId, err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &languageMsg, nil +} + +// UpdateEnrollmentMessageByLanguageID updates the enrollment messaging for a specific language ID +func (c *Client) UpdateEnrollmentMessageByLanguageID(languageId string, enrollmentMessage *ResourceEnrollmentLanguage) (*ResourceEnrollmentLanguage, error) { + endpoint := fmt.Sprintf("%s/languages/%s", uriEnrollmentV3, languageId) + var updatedMessage ResourceEnrollmentLanguage + + resp, err := c.HTTP.DoRequest("PUT", endpoint, enrollmentMessage, &updatedMessage) + if err != nil { + return nil, fmt.Errorf("failed to update enrollment language messaging for language ID '%s': %v", languageId, err) + } + + if resp != nil { + defer resp.Body.Close() + } + + return &updatedMessage, nil +} + +// DeleteEnrollmentMessageByLanguageID deletes the enrollment messaging for a specific language ID +func (c *Client) DeleteEnrollmentMessageByLanguageID(languageId string) error { + endpoint := fmt.Sprintf("%s/languages/%s", uriEnrollmentV3, languageId) + + resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil) + if err != nil { + return fmt.Errorf(errMsgFailedDeleteByID, "enrollment language message", languageId, err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + var respErr ResponseError + if err := json.NewDecoder(resp.Body).Decode(&respErr); err == nil { + if respErr.HTTPStatus != 0 { + return fmt.Errorf("deletion failed for enrollment language '%s' with status %d: %v", languageId, respErr.HTTPStatus, respErr.Errors) + } + } + + return nil +} + +// DeleteMultipleEnrollmentMessagesByLanguageIDs deletes multiple enrollment language messages by their IDs +func (c *Client) DeleteMultipleEnrollmentMessagesByLanguageIDs(languageIds []string) error { + endpoint := fmt.Sprintf("%s/languages/delete-multiple", uriEnrollmentV3) + + // Create request body + request := RequestDeleteMultipleLanguages{ + IDs: languageIds, + } + + resp, err := c.HTTP.DoRequest("POST", endpoint, request, nil) + if err != nil { + return fmt.Errorf(errMsgFailedDelete, "multiple enrollment language messages", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + var respErr ResponseError + if err := json.NewDecoder(resp.Body).Decode(&respErr); err == nil { + if respErr.HTTPStatus != 0 { + return fmt.Errorf("deletion failed for multiple enrollment languages with status %d: %v", respErr.HTTPStatus, respErr.Errors) + } + } + + return nil +} + +// GetEnrollmentLanguageCodes retrieves the list of available languages and their ISO 639-1 codes +func (c *Client) GetEnrollmentLanguageCodes() ([]ResourceLanguageCode, error) { + endpoint := fmt.Sprintf("%s/language-codes", uriEnrollmentV3) + var languageCodes []ResourceLanguageCode + + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &languageCodes) + if err != nil { + return nil, fmt.Errorf("failed to get enrollment language codes: %v", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return languageCodes, nil +} diff --git a/sdk/jamfpro/jamfproapi_enrollment_customizations.go b/sdk/jamfpro/jamfproapi_enrollment_customizations.go index 665039c79..9687a353c 100644 --- a/sdk/jamfpro/jamfproapi_enrollment_customizations.go +++ b/sdk/jamfpro/jamfproapi_enrollment_customizations.go @@ -7,6 +7,7 @@ package jamfpro import ( "fmt" + "net/http" "github.com/mitchellh/mapstructure" ) @@ -29,6 +30,10 @@ type ResponseEnrollmentCustomizationCreate struct { Href string `json:"href"` } +type ResponseEnrollmentCustomizationUpload struct { + Url string `json:"url"` +} + // Resource type ResourceEnrollmentCustomization struct { @@ -51,7 +56,6 @@ type EnrollmentCustomizationSubsetBrandingSettings struct { // CRUD -// TODO Upload an image - https://developer.jamf.com/jamf-pro/reference/post_v2-enrollment-customizations-images // TODO Download an image - https://developer.jamf.com/jamf-pro/reference/get_v2-enrollment-customizations-images-id // Returns paginated list of Enrollment Customization @@ -151,3 +155,39 @@ func (c *Client) DeleteEnrollmentCustomizationByID(id string) error { return nil } + +// UploadEnrollmentCustomizationsImage uploads an enrollment image file using the custom multipart format +func (c *Client) UploadEnrollmentCustomizationsImage(filePath string) (*ResponseEnrollmentCustomizationUpload, error) { + endpoint := fmt.Sprintf("%s/images", uriEnrollmentCustomizationSettings) + + files := map[string][]string{ + "file": {filePath}, + } + + formFields := map[string]string{} + contentTypes := map[string]string{ + "file": "image/png", + } + headersMap := map[string]http.Header{} + + var response ResponseEnrollmentCustomizationUpload + resp, err := c.HTTP.DoMultiPartRequest( + http.MethodPost, + endpoint, + files, + formFields, + contentTypes, + headersMap, + "byte", + &response, + ) + + if err != nil { + return nil, fmt.Errorf("failed to upload icon: %v", err) + } + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &response, nil +} diff --git a/sdk/jamfpro/jamfproapi_enrollment_settings.go b/sdk/jamfpro/jamfproapi_enrollment_settings.go new file mode 100644 index 000000000..1ba088825 --- /dev/null +++ b/sdk/jamfpro/jamfproapi_enrollment_settings.go @@ -0,0 +1,111 @@ +// jamfproapi_account_driven_user_enrollment_token_settings.go +// Jamf Pro Api - Enrollment +// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-enrollment-history +// Jamf Pro API requires the structs to support a JSON data structure. + +package jamfpro + +import "fmt" + +const uriUserEnrollmentTokenSettings = "/api/v1/adue-session-token-settings" +const uriEnrollmentSettings = "/api/v4/enrollment" + +// Resource + +type ResourceADUETokenSettings struct { + Enabled bool `json:"enabled"` + ExpirationIntervalDays int `json:"expirationIntervalDays,omitempty"` + ExpirationIntervalSeconds int `json:"expirationIntervalSeconds,omitempty"` +} + +type EnrollmentSubsetCertificateSettings struct { + InstallSingleProfile bool `json:"installSingleProfile"` + SigningMdmProfileEnabled bool `json:"signingMdmProfileEnabled"` + MdmSigningCertificate *EnrollmentSubsetCertificate `json:"mdmSigningCertificate"` + MdmSigningCertificateDetails EnrollmentSubsetCertificateDetails `json:"mdmSigningCertificateDetails"` + RestrictReenrollment bool `json:"restrictReenrollment"` + FlushLocationInformation bool `json:"flushLocationInformation"` + FlushLocationHistoryInformation bool `json:"flushLocationHistoryInformation"` + FlushPolicyHistory bool `json:"flushPolicyHistory"` + FlushExtensionAttributes bool `json:"flushExtensionAttributes"` + FlushMdmCommandsOnReenroll string `json:"flushMdmCommandsOnReenroll"` + MacOsEnterpriseEnrollmentEnabled bool `json:"macOsEnterpriseEnrollmentEnabled"` + ManagementUsername string `json:"managementUsername"` + ManagementPasswordSet bool `json:"managementPasswordSet"` + PasswordType *string `json:"passwordType"` + RandomPasswordLength int `json:"randomPasswordLength"` + CreateManagementAccount bool `json:"createManagementAccount"` + HideManagementAccount bool `json:"hideManagementAccount"` + AllowSshOnlyManagementAccount bool `json:"allowSshOnlyManagementAccount"` + EnsureSshRunning bool `json:"ensureSshRunning"` + LaunchSelfService bool `json:"launchSelfService"` + SignQuickAdd bool `json:"signQuickAdd"` + DeveloperCertificateIdentity *EnrollmentSubsetCertificate `json:"developerCertificateIdentity"` + DeveloperCertificateIdentityDetails EnrollmentSubsetCertificateDetails `json:"developerCertificateIdentityDetails"` + IosEnterpriseEnrollmentEnabled bool `json:"iosEnterpriseEnrollmentEnabled"` + IosPersonalEnrollmentEnabled bool `json:"iosPersonalEnrollmentEnabled"` + PersonalDeviceEnrollmentType string `json:"personalDeviceEnrollmentType"` + AccountDrivenUserEnrollmentEnabled bool `json:"accountDrivenUserEnrollmentEnabled"` +} + +type EnrollmentSubsetCertificate struct { + Filename string `json:"filename"` + Md5Sum string `json:"md5Sum"` +} + +type EnrollmentSubsetCertificateDetails struct { + Subject string `json:"subject"` + SerialNumber string `json:"serialNumber"` +} + +// CRUD + +func (c *Client) GetADUESessionTokenSettings() (*ResourceADUETokenSettings, error) { + endpoint := uriUserEnrollmentTokenSettings + var out ResourceADUETokenSettings + + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out) + if err != nil { + return nil, fmt.Errorf(errMsgFailedGet, "ADUE token settings", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &out, nil + +} + +func (c *Client) UpdateADUESessionTokenSettings(updatedSettings ResourceADUETokenSettings) (*ResourceADUETokenSettings, error) { + endpoint := uriUserEnrollmentTokenSettings + var out ResourceADUETokenSettings + + resp, err := c.HTTP.DoRequest("PUT", endpoint, updatedSettings, &out) + if err != nil { + return nil, fmt.Errorf(errMsgFailedUpdate, "ADUE token settings", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &out, nil +} + +// GetEnrollmentSettings retrieves the enrollment settings from the Jamf Pro server. +func (c *Client) GetEnrollmentSettings() (*EnrollmentSubsetCertificateSettings, error) { + endpoint := uriEnrollmentSettings + var out EnrollmentSubsetCertificateSettings + + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out) + if err != nil { + return nil, fmt.Errorf(errMsgFailedGet, "enrollment settings", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &out, nil +} diff --git a/sdk/jamfpro/jamfproapi_jamf_pro_system_initialization.go b/sdk/jamfpro/jamfproapi_jamf_pro_system_initialization.go new file mode 100644 index 000000000..effba8e13 --- /dev/null +++ b/sdk/jamfpro/jamfproapi_jamf_pro_system_initialization.go @@ -0,0 +1,81 @@ +// jamfproapi_jamf_pro_system_initialization.go +// Jamf Pro Api - JAMF system initialization +// api reference: https://developer.jamf.com/jamf-pro/reference/post_v1-system-initialize +// Jamf Pro API requires the structs to support an JSON data structure. + +package jamfpro + +import ( + "encoding/json" + "fmt" +) + +const uriSystemInitialize = "/api/v1/system/initialize" +const uriInitializeDatabaseConnection = "/api/v1/system/initialize-database-connection" + +// Request struct for database password initialization +type ResourceDatabasePassword struct { + Password string `json:"password"` +} + +// Request Struct +type ResourceSystemInitialize struct { + ActivationCode string `json:"activationCode"` + InstitutionName string `json:"institutionName"` + EulaAccepted bool `json:"eulaAccepted"` + Username string `json:"username"` + Password string `json:"password"` + Email string `json:"email,omitempty"` + JssUrl string `json:"jssUrl"` +} + +// InitializeJamfProServer initializes a fresh Jamf Pro Server installation +func (c *Client) InitializeJamfProServer(systemConfig *ResourceSystemInitialize) error { + endpoint := uriSystemInitialize + + resp, err := c.HTTP.DoRequest("POST", endpoint, systemConfig, nil) + if err != nil { + return fmt.Errorf("failed to initialize Jamf Pro system: %v", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + var errorResponse ResponseError + if err := json.NewDecoder(resp.Body).Decode(&errorResponse); err == nil { + if errorResponse.HTTPStatus != 0 { + return fmt.Errorf("system initialization failed with status %d: %v", errorResponse.HTTPStatus, errorResponse.Errors) + } + } + + return nil +} + +// InitializeDatabaseConnection sets up the database password during startup +func (c *Client) InitializeDatabaseConnection(password string) error { + endpoint := uriInitializeDatabaseConnection + + // Create request payload + dbConfig := ResourceDatabasePassword{ + Password: password, + } + + resp, err := c.HTTP.DoRequest("POST", endpoint, dbConfig, nil) + if err != nil { + return fmt.Errorf("failed to initialize database connection: %v", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + var errorResponse ResponseError + if err := json.NewDecoder(resp.Body).Decode(&errorResponse); err == nil { + if errorResponse.HTTPStatus != 0 { + return fmt.Errorf("database initialization failed with status %d: %v", errorResponse.HTTPStatus, errorResponse.Errors) + } + } + + return nil +} diff --git a/sdk/jamfpro/jamfproapi_self_service_branding_upload.go b/sdk/jamfpro/jamfproapi_self_service_branding_upload.go new file mode 100644 index 000000000..0c0c69aab --- /dev/null +++ b/sdk/jamfpro/jamfproapi_self_service_branding_upload.go @@ -0,0 +1,54 @@ +// jamfproapi_self_service.go +// Jamf Pro Api - Self Service BrandingImages +// api reference: https://developer.jamf.com/jamf-pro/reference/post_self-service-branding-images +// Jamf Pro API requires the structs to support an JSON data structure. + +package jamfpro + +import ( + "fmt" + "net/http" +) + +// Constants for API endpoints +const uriSelfService = "/api/self-service/branding/images" + +// Resource +type ResourceSelfServiceBranding struct { + ID int `json:"id"` + URL string `json:"url"` + Name string `json:"name"` +} + +// Response + +// ResponseSelfServiceBranding represents the response from the branding upload endpoint +type ResponseSelfServiceBranding struct { + ID int `json:"id"` + URL string `json:"url"` +} + +// UploadSelfServiceBrandingImage uploads an branding image file using the custom multipart format +func (c *Client) UploadSelfServiceBrandingImage(filePath string) (*ResponseSelfServiceBranding, error) { + files := map[string][]string{ + "file": {filePath}, + } + + formFields := map[string]string{} + contentTypes := map[string]string{ + "file": "image/png", + } + headersMap := map[string]http.Header{} + + var response ResponseSelfServiceBranding + resp, err := c.HTTP.DoMultiPartRequest(http.MethodPost, uriSelfService, files, formFields, contentTypes, headersMap, "byte", &response) + + if err != nil { + return nil, fmt.Errorf("failed to upload icon: %v", err) + } + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &response, nil +} diff --git a/sdk/jamfpro/jamfproapi_startup_status.go b/sdk/jamfpro/jamfproapi_startup_status.go new file mode 100644 index 000000000..03b02e983 --- /dev/null +++ b/sdk/jamfpro/jamfproapi_startup_status.go @@ -0,0 +1,45 @@ +// jamfproapi_startup_status.go +// Jamf Pro Api - Startup Status +// api reference: https://developer.jamf.com/jamf-pro/reference/get_startup-status +// Jamf Pro API requires the structs to support a JSON data structure. + +package jamfpro + +import ( + "fmt" +) + +const uriStartupStatus = "/api/startup-status" + +// Resource structure +type ResourceStartupStatus struct { + Step string `json:"step"` + StepCode string `json:"stepCode"` + StepParam string `json:"stepParam"` + Percentage int `json:"percentage"` + Warning string `json:"warning"` + WarningCode string `json:"warningCode"` + WarningParam string `json:"warningParam"` + Error string `json:"error"` + ErrorCode string `json:"errorCode"` + SetupAssistantNecessary bool `json:"setupAssistantNecessary"` +} + +// CRUD + +// GetStartupStatus retrieves the status of the Jamf Pro server using API. +func (c *Client) GetStartupStatus() (*ResourceStartupStatus, error) { + endpoint := uriStartupStatus + + var jamfProStatus ResourceStartupStatus + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &jamfProStatus) + if err != nil { + return nil, fmt.Errorf("failed to get Jamf Pro status informations: %v", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &jamfProStatus, nil +} diff --git a/sdk/jamfpro/shared_models.go b/sdk/jamfpro/shared_models.go index 9b49be778..9cc379d0c 100644 --- a/sdk/jamfpro/shared_models.go +++ b/sdk/jamfpro/shared_models.go @@ -94,3 +94,17 @@ type SharedResourceErrorDetail struct { Description string `json:"description"` ID string `json:"id"` } + +// ResponseError represents the structure of an error response from the API +type ResponseError struct { + HTTPStatus int `json:"httpStatus"` + Errors []ErrorInstance `json:"errors"` +} + +// ErrorInstance represents a single error in the error response +type ErrorInstance struct { + Code string `json:"code"` + Field string `json:"field"` + Description string `json:"description"` + ID string `json:"id"` +}