Skip to content

Commit

Permalink
Merge pull request #478 from deploymenttheory/bugfix-computerprestages
Browse files Browse the repository at this point in the history
Feature - added sdk funcs for accepting and getting app installer t&c's status
  • Loading branch information
ShocOne authored Aug 29, 2024
2 parents 23eef7a + aa4b801 commit d6b9302
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This example demonstrates how to initialize the Jamf Pro client using the client configuration file.
package main

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This example demonstrates how to initialize the Jamf Pro client using configurations loaded from environment variables.
package main

import (
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 protected]",
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",
Expand All @@ -53,7 +53,6 @@ func main() {
EnableRecoveryLock: jamfpro.FalsePtr(),
RecoveryLockPasswordType: "MANUAL",
RotateRecoveryLockPassword: jamfpro.FalsePtr(),
ProfileUuid: "0386E7C8D455A040106850A8A2033968",
SiteId: "-1",
VersionLock: currentPrestage.VersionLock,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.")
}
Original file line number Diff line number Diff line change
@@ -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))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
52 changes: 45 additions & 7 deletions sdk/jamfpro/jamfproapi_app_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d6b9302

Please sign in to comment.