From 0749ffe97e1e423832983b79815412d61df990c9 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:06:40 +0100 Subject: [PATCH 1/3] Refactor removed profile_uuid from examples as it's not required and missleading --- .../CreateComputerPrestageMinimumConfig.go | 1 - .../GetComputerPrestageByID/GetComputerPrestageByID.go | 2 +- .../UpdateComputerPrestageByID.go | 7 +++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go index 52fd365b..3beacc77 100644 --- a/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go +++ b/examples/computer_prestages/CreateComputerPrestageMinimumConfig/CreateComputerPrestageMinimumConfig.go @@ -92,7 +92,6 @@ func main() { EnableRecoveryLock: jamfpro.FalsePtr(), RecoveryLockPasswordType: "MANUAL", RotateRecoveryLockPassword: jamfpro.FalsePtr(), - ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", VersionLock: 0, // Not required for creates AccountSettings: jamfpro.ComputerPrestageSubsetAccountSettings{ diff --git a/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go b/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go index 04f70cd3..268919dc 100644 --- a/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go +++ b/examples/computer_prestages/GetComputerPrestageByID/GetComputerPrestageByID.go @@ -19,7 +19,7 @@ func main() { } // ID of the computer prestage you want to retrieve - prestageID := "61" // Replace with the actual ID + prestageID := "82" // Replace with the actual ID // Call the GetComputerPrestageByID function prestage, err := client.GetComputerPrestageByID(prestageID) diff --git a/examples/computer_prestages/UpdateComputerPrestageByID/UpdateComputerPrestageByID.go b/examples/computer_prestages/UpdateComputerPrestageByID/UpdateComputerPrestageByID.go index a5ff425f..e4a166fc 100644 --- a/examples/computer_prestages/UpdateComputerPrestageByID/UpdateComputerPrestageByID.go +++ b/examples/computer_prestages/UpdateComputerPrestageByID/UpdateComputerPrestageByID.go @@ -19,7 +19,7 @@ func main() { } // The ID of the computer prestage you want to update - prestageID := "61" + prestageID := "83" // First, get the current prestage to obtain the current version lock currentPrestage, err := client.GetComputerPrestageByID(prestageID) @@ -32,12 +32,12 @@ func main() { DisplayName: "jamfpro-sdk-example-computerPrestageMinimum-config", Mandatory: jamfpro.TruePtr(), MDMRemovable: jamfpro.TruePtr(), - SupportPhoneNumber: "111-222-3333", + SupportPhoneNumber: "111-222-3344", SupportEmailAddress: "email@company.com", Department: "department name", DefaultPrestage: jamfpro.FalsePtr(), EnrollmentSiteId: "-1", - KeepExistingSiteMembership: jamfpro.FalsePtr(), + KeepExistingSiteMembership: jamfpro.TruePtr(), KeepExistingLocationInformation: jamfpro.FalsePtr(), RequireAuthentication: jamfpro.FalsePtr(), AuthenticationPrompt: "hello welcome to your enterprise managed macOS device", @@ -53,7 +53,6 @@ func main() { EnableRecoveryLock: jamfpro.FalsePtr(), RecoveryLockPasswordType: "MANUAL", RotateRecoveryLockPassword: jamfpro.FalsePtr(), - ProfileUuid: "0386E7C8D455A040106850A8A2033968", SiteId: "-1", VersionLock: currentPrestage.VersionLock, } From 6fe35417b67d3a60590d6e43c22fd542191e8df4 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:45:14 +0100 Subject: [PATCH 2/3] Refactor authentication examples to use client configuration file and environment variables --- .../example_client_setup_with_configfile.go | 1 + .../example_client_setup_with_env_vars.go | 32 +++++++----- .../example_client_setup_with_manual_conf.go | 51 ++++++++++--------- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/examples/_templates/authentication/example_client_setup_with_configfile.go b/examples/_templates/authentication/example_client_setup_with_configfile.go index edd93abf..bc68ee2e 100644 --- a/examples/_templates/authentication/example_client_setup_with_configfile.go +++ b/examples/_templates/authentication/example_client_setup_with_configfile.go @@ -1,3 +1,4 @@ +// This example demonstrates how to initialize the Jamf Pro client using the client configuration file. package main import ( diff --git a/examples/_templates/authentication/example_client_setup_with_env_vars.go b/examples/_templates/authentication/example_client_setup_with_env_vars.go index f9a2ad52..17fd931e 100644 --- a/examples/_templates/authentication/example_client_setup_with_env_vars.go +++ b/examples/_templates/authentication/example_client_setup_with_env_vars.go @@ -1,3 +1,4 @@ +// This example demonstrates how to initialize the Jamf Pro client using configurations loaded from environment variables. package main import ( @@ -11,25 +12,30 @@ import ( Ensure environment variables are set before running in this mode. You will need to set the following environment variables: +export LOG_LEVEL="warning" +export HIDE_SENSITIVE_DATA="true" +export INSTANCE_DOMAIN="your-instance-domain" +export AUTH_METHOD="oauth2" export CLIENT_ID="your-client-id" export CLIENT_SECRET="your-client-secret" -export INSTANCE_NAME="your-instance-name" -export OVERRIDE_BASE_DOMAIN="" -export API_TYPE="jamfpro" -export LOG_LEVEL="LogLevelDebug" -export LOG_OUTPUT_FORMAT="console" -export LOG_CONSOLE_SEPARATOR=" " -export HIDE_SENSITIVE_DATA="true" +export BASIC_AUTH_USERNAME="your-basic-auth-username" +export BASIC_AUTH_PASSWORD="your-basic-auth-password" +export JAMF_LOAD_BALANCER_LOCK="true" export MAX_RETRY_ATTEMPTS="3" -export ENABLE_DYNAMIC_RATE_LIMITING="true" -export MAX_CONCURRENT_REQUESTS="5" -export TOKEN_REFRESH_BUFFER_PERIOD="5m" -export TOTAL_RETRY_DURATION="5m" -export CUSTOM_TIMEOUT="10s" +export ENABLE_DYNAMIC_RATE_LIMITING="false" +export MAX_CONCURRENT_REQUESTS="1" +export TOKEN_REFRESH_BUFFER_PERIOD_SECONDS="300" +export TOTAL_RETRY_DURATION_SECONDS="60" +export CUSTOM_TIMEOUT_SECONDS="60" +export FOLLOW_REDIRECTS="true" +export MAX_REDIRECTS="5" +export ENABLE_CONCURRENCY_MANAGEMENT="true" +export CUSTOM_COOKIES="" +export MANDATORY_REQUEST_DELAY_MILLISECONDS="0" +export RETRY_ELIGIABLE_REQUESTS="true" */ func main() { - // Initialize the Jamf Pro client using configurations loaded from environment variables client, err := jamfpro.BuildClientWithEnv() if err != nil { diff --git a/examples/_templates/authentication/example_client_setup_with_manual_conf.go b/examples/_templates/authentication/example_client_setup_with_manual_conf.go index 2c163479..0ec1a16d 100644 --- a/examples/_templates/authentication/example_client_setup_with_manual_conf.go +++ b/examples/_templates/authentication/example_client_setup_with_manual_conf.go @@ -1,37 +1,40 @@ +// this file is used to demonstrate how to set up the client with a manual configuration package main import ( "fmt" "log" - "time" - "github.com/deploymenttheory/go-api-http-client/httpclient" "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" ) func main() { - // Manually define the client configuration - config := httpclient.ClientConfig{ - Environment: httpclient.EnvironmentConfig{ - InstanceName: "your-instance-name", - OverrideBaseDomain: "", // Only required if you are not on jamfcloud.com - APIType: "jamfpro", // Required to specify the API type - }, - Auth: httpclient.AuthConfig{ - ClientID: "your-client-id", - ClientSecret: "your-client-secret", - }, - ClientOptions: httpclient.ClientOptions{ - LogLevel: "LogLevelDebug", - LogOutputFormat: "console", - HideSensitiveData: true, - MaxRetryAttempts: 5, - EnableDynamicRateLimiting: true, - MaxConcurrentRequests: 10, - TokenRefreshBufferPeriod: 5 * time.Minute, - TotalRetryDuration: 60 * time.Second, - CustomTimeout: 30 * time.Second, - }, + // Define the configuration based on the new ConfigContainer struct + config := &jamfpro.ConfigContainer{ + LogLevel: "warning", + LogExportPath: "", // Set this if you want to export logs to a file + HideSensitiveData: true, + + InstanceDomain: "your-instance-domain", + AuthMethod: "oauth2", // Use "basic" for basic authentication + ClientID: "your-client-id", + ClientSecret: "your-client-secret", + Username: "", // Set this if using basic auth + Password: "", // Set this if using basic auth + JamfLoadBalancerLock: true, + + CustomCookies: []jamfpro.CustomCookie{}, + MaxRetryAttempts: 3, + MaxConcurrentRequests: 1, + EnableDynamicRateLimiting: false, + CustomTimeout: 60, // in seconds + TokenRefreshBufferPeriod: 300, // in seconds + TotalRetryDuration: 60, // in seconds + FollowRedirects: true, + MaxRedirects: 5, + EnableConcurrencyManagement: true, + MandatoryRequestDelay: 0, // in milliseconds + RetryEligiableRequests: true, } // Initialize the Jamf Pro client with the given configuration From aa4b801934e31551c3ee39746e89a29e03d610cd Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:08:40 +0100 Subject: [PATCH 3/3] chore: Update go-api-http-client dependency to v0.2.12 --- ...ppCatalogAppInstallerTermsAndConditions.go | 27 ++++++++++ ...logAppInstallerTermsAndConditionsStatus.go | 33 ++++++++++++ go.mod | 2 +- go.sum | 4 +- sdk/jamfpro/jamfproapi_app_installers.go | 52 ++++++++++++++++--- 5 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 examples/jamf_app_catalog_app_installers/AcceptJamfAppCatalogAppInstallerTermsAndConditions/AcceptJamfAppCatalogAppInstallerTermsAndConditions.go create mode 100644 examples/jamf_app_catalog_app_installers/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus.go diff --git a/examples/jamf_app_catalog_app_installers/AcceptJamfAppCatalogAppInstallerTermsAndConditions/AcceptJamfAppCatalogAppInstallerTermsAndConditions.go b/examples/jamf_app_catalog_app_installers/AcceptJamfAppCatalogAppInstallerTermsAndConditions/AcceptJamfAppCatalogAppInstallerTermsAndConditions.go new file mode 100644 index 00000000..8021b4d3 --- /dev/null +++ b/examples/jamf_app_catalog_app_installers/AcceptJamfAppCatalogAppInstallerTermsAndConditions/AcceptJamfAppCatalogAppInstallerTermsAndConditions.go @@ -0,0 +1,27 @@ +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) + } + + // Accept the terms and conditions + err = client.AcceptJamfAppCatalogAppInstallerTermsAndConditions() + if err != nil { + log.Fatalf("Error: %v", err) + } + + fmt.Println("Successfully accepted Jamf App Catalog App Installer terms and conditions.") +} diff --git a/examples/jamf_app_catalog_app_installers/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus.go b/examples/jamf_app_catalog_app_installers/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus.go new file mode 100644 index 00000000..0f9ef8f1 --- /dev/null +++ b/examples/jamf_app_catalog_app_installers/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus/GetJamfAppCatalogAppInstallerTermsAndConditionsStatus.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) + } + + // Fetch t&c status + status, err := client.GetJamfAppCatalogAppInstallerTermsAndConditionsStatus() + if err != nil { + log.Fatalf("Error fetching Terms And Conditions Status: %v", err) + } + + // Pretty print the fetched Terms And Conditions Status using JSON marshaling + statusJSON, err := json.MarshalIndent(status, "", " ") // Indent with 4 spaces + if err != nil { + log.Fatalf("Error marshaling Terms And Conditions Status data: %v", err) + } + fmt.Println("Fetched Terms And Conditions Status:", string(statusJSON)) +} diff --git a/go.mod b/go.mod index d4465322..eec95dd7 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.4 // Deploymenttheory require ( - github.com/deploymenttheory/go-api-http-client v0.2.11 + github.com/deploymenttheory/go-api-http-client v0.2.12 github.com/deploymenttheory/go-api-http-client-integrations v0.0.11 ) diff --git a/go.sum b/go.sum index cf761b9a..21f533ef 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,8 @@ github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deploymenttheory/go-api-http-client v0.2.11 h1:hEVxXX60cUxRqKkJBHADC/S91+iCPYdBIwkT6stexTY= -github.com/deploymenttheory/go-api-http-client v0.2.11/go.mod h1:LKDnBcieS6CyikZjTKPpziVdxnTwzBHE6Hx1cuWRcuU= +github.com/deploymenttheory/go-api-http-client v0.2.12 h1:ZPnxbF9/S3EBTx8aFzRcofyChT/+AXmRm4xnyoCNK+0= +github.com/deploymenttheory/go-api-http-client v0.2.12/go.mod h1:LKDnBcieS6CyikZjTKPpziVdxnTwzBHE6Hx1cuWRcuU= github.com/deploymenttheory/go-api-http-client-integrations v0.0.11 h1:1jRrAeD6iGXw7DDccoYTre0XS9bVbCAk3lmFCO43Z28= github.com/deploymenttheory/go-api-http-client-integrations v0.0.11/go.mod h1:FQPNu+QaAyq9XWSjItJo82ABvkiGwdOlt73Qm6vp3MU= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= diff --git a/sdk/jamfpro/jamfproapi_app_installers.go b/sdk/jamfpro/jamfproapi_app_installers.go index 0e91ee52..48d379d0 100644 --- a/sdk/jamfpro/jamfproapi_app_installers.go +++ b/sdk/jamfpro/jamfproapi_app_installers.go @@ -28,6 +28,11 @@ type ResponseJamfAppCatalogDeploymentCreateAndUpdate struct { Href string `json:"href"` } +type ResponseJamfAppCatalogDeploymentTermsAndConditionsStatus struct { + Accepted bool `json:"accepted"` + AcceptanceTime string `json:"acceptanceTime"` +} + // Resource type ResourceJamfAppCatalogAppInstaller struct { @@ -61,13 +66,12 @@ type JamfAppCatalogAppInstallerSubsetMediaSource struct { // Struct which represents AppInstallers object JSON from Pro API type ResourceJamfAppCatalogDeployment struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - Enabled *bool `json:"enabled"` - AppTitleId string `json:"appTitleId,omitempty"` - DeploymentType string `json:"deploymentType,omitempty"` - UpdateBehavior string `json:"updateBehavior,omitempty"` - // TODO why is this not the object? + ID string `json:"id"` + Name string `json:"name,omitempty"` + Enabled *bool `json:"enabled"` + AppTitleId string `json:"appTitleId,omitempty"` + DeploymentType string `json:"deploymentType,omitempty"` + UpdateBehavior string `json:"updateBehavior,omitempty"` CategoryId string `json:"categoryId,omitempty"` SiteId string `json:"siteId,omitempty"` SmartGroupId string `json:"smartGroupId,omitempty"` @@ -110,6 +114,40 @@ type JamfAppCatalogDeploymentSubsetCategory struct { // CRUD +// GetJamfAppCatalogAppInstallerTermsAndConditionsStatus returns the terms and conditions status for the Jamf App Catalog +func (c *Client) GetJamfAppCatalogAppInstallerTermsAndConditionsStatus() (*ResponseJamfAppCatalogDeploymentTermsAndConditionsStatus, error) { + endpoint := fmt.Sprintf("%s/terms-and-conditions", uriJamfAppCatalogAppInstaller) + + var globalSettings ResponseJamfAppCatalogDeploymentTermsAndConditionsStatus + resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &globalSettings) + if err != nil { + return nil, fmt.Errorf(errMsgFailedGet, "printers", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return &globalSettings, nil +} + +// AcceptJamfAppCatalogAppInstallerTermsAndConditions accepts the terms and conditions for the Jamf App Catalog +// This is required on an account by account basis. +func (c *Client) AcceptJamfAppCatalogAppInstallerTermsAndConditions() error { + endpoint := fmt.Sprintf("%s/terms-and-conditions", uriJamfAppCatalogAppInstaller) + + resp, err := c.HTTP.DoRequest("POST", endpoint, nil, nil) + if err != nil { + return fmt.Errorf("failed to accept terms and conditions: %v", err) + } + + if resp != nil && resp.Body != nil { + defer resp.Body.Close() + } + + return nil +} + // Gets full list of Get Jamf App Catalog App Installer Titles & handles pagination func (c *Client) GetJamfAppCatalogAppInstallerTitles(sort_filter string) (*ResponseJamfAppCatalogTitleList, error) { resp, err := c.DoPaginatedGet(