go-api-sdk-jamfpro

module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2023 License: MIT

README

Getting Started with go-api-sdk-jamfpro

This guide will help you get started with go-api-sdk-jamfpro, a Go SDK for interfacing with Jamf Pro.

Prerequisites

Ensure you have Go installed and set up on your system. If not, follow the instructions on the official Go website.

Installation

Install the go-api-sdk-jamfpro package using go get:

go get github.com/deploymenttheory/go-api-sdk-jamfpro

Usage

sample code: examples

Configuring the HTTP Client

To effectively use the go-api-sdk-jamfpro SDK, you'll need to set up and configure the HTTP client. Here's a step-by-step guide:

1. Setting Constants

At the start of your main program, define some constants that will be used to configure the client:

const (
	maxConcurrentRequestsAllowed = 5 // Maximum allowed concurrent requests.
	defaultTokenLifespan         = 30 * time.Minute
	defaultBufferPeriod          = 5 * time.Minute
)

These constants are used to set the maximum number of concurrent requests the client can make, the lifespan of the token, and a buffer period.

  1. Loading OAuth Credentials OAuth credentials are essential for authenticating with the Jamf Pro API. Store these credentials in a JSON file for secure and easy access. The structure of the clientauth.json should be:
{
  "baseURL": "your_jamf_pro_url",
  "clientID": "your_client_id",
  "clientSecret": "your_client_secret"
}

Replace your_jamf_pro_url, your_client_id, and your_client_secret with your actual credentials.

In your Go program, load these credentials using:

configFilePath := "path_to_your/clientauth.json"
authConfig, err := http_client.LoadClientAuthConfig(configFilePath)
if err != nil {
	log.Fatalf("Failed to load client OAuth configuration: %v", err)
}
  1. Configuring the HTTP Client With the OAuth credentials loaded, you can now configure the HTTP client:
config := http_client.Config{
	DebugMode:             true,
	Logger:                http_client.NewDefaultLogger(),
	MaxConcurrentRequests: maxConcurrentRequestsAllowed,
	TokenLifespan:         defaultTokenLifespan,
	BufferPeriod:          defaultBufferPeriod,
}

Here, the DebugMode is set to true, which means the client will print debug information. The Logger uses the SDK's default logger. The other fields are set using the constants we defined earlier.

  1. Initializing the Jamf Pro Client Once the HTTP client is configured, initialize the Jamf Pro client:
client := jamfpro.NewClient(authConfig.BaseURL, config)

Then, set the OAuth credentials for the client's HTTP client:

oAuthCreds := http_client.OAuthCredentials{
	ClientID:     authConfig.ClientID,
	ClientSecret: authConfig.ClientSecret,
}
client.HTTP.SetOAuthCredentials(oAuthCreds)

With these steps, the HTTP client will be fully set up and ready to make requests to the Jamf Pro API. You can then proceed to use the client to perform various actions as demonstrated in the sample code provided.

Note: Remember to always keep your OAuth credentials confidential and never expose them in your code or public repositories. Using configuration files like clientauth.json and .gitignore-ing them is a good practice to ensure they're not accidentally committed.

Go SDK for Jamf Pro API Progress Tracker

API Coverage Progress

Date: Oct-2023 Maintainer: [ShocOne]

Overview

This document tracks the progress of API endpoint coverage tests. As endpoints are tested, they will be marked as covered.

Coverage Legend

  • ✅ - Covered
  • ❌ - Not Covered
  • ⚠️ - Partially Covered

Endpoints

Accounts - /JSSResource/accounts

  • ✅ GET /userid/{id} - GetAccountByID retrieves the Account by its ID
  • ✅ GET /username/{username} - GetAccountByName retrieves the Account by its name
  • ✅ GET / - GetAccounts retrieves all user accounts
  • ✅ GET /groupid/{id} - GetAccountGroupByID retrieves the Account Group by its ID
  • ✅ GET /groupname/{id} - GetAccountGroupByName retrieves the Account Group by its name
  • ✅ POST / - CreateAccount creates a new Jamf Pro Account.
  • ✅ POST /groupid/0 - CreateAccountGroup creates a new Jamf Pro Account Group.
  • ✅ PUT /userid/{id} - UpdateAccountByID updates an existing Jamf Pro Account by ID
  • ✅ PUT /username/{id} - UpdateAccountByName updates an existing Jamf Pro Account by Name
  • ✅ PUT /groupid/{id} - UpdateAccountGroupByID updates an existing Jamf Pro Account Group by ID
  • ✅ PUT /groupname/{id} - UpdateAccountGroupByName updates an existing Jamf Pro Account Group by Name
  • ✅ DELETE /userid/{id} - DeleteAccountByID deletes an existing Jamf Pro Account by ID
  • ✅ DELETE /username/{username} - DeleteAccountByName deletes an existing Jamf Pro Account by Name
  • ✅ DELETE /groupid/{id} - DeleteAccountGroupByID deletes an existing Jamf Pro Account Group by ID
  • ✅ DELETE /groupname/{username} - DeleteAccountGroupByName deletes an existing Jamf Pro Account Group by Name

Activation Code - /JSSResource/activationcode

  • ✅ GET /JSSResource/activationcode - GetActivationCode retrieves the current activation code.
  • ✅ PUT /JSSResource/activationcode - UpdateActivationCode updates the activation code.

Allowed File Extensions - /JSSResource/allowedfileextensions

  • ✅ GET /JSSResource/allowedfileextensions - GetAllowedFileExtensions retrieves all allowed file extensions
  • ✅ GET /JSSResource/allowedfileextensions/id/{id} - GetAllowedFileExtensionByID retrieves the allowed file extension by its ID
  • ✅ GET /JSSResource/allowedfileextensions/extension/{extensionName} - GetAllowedFileExtensionByName retrieves the allowed file extension by its name
  • ✅ POST /JSSResource/allowedfileextensions/id/0 - CreateAllowedFileExtension creates a new allowed file extension
  • ❌ PUT /JSSResource/allowedfileextensions/id/{id} - UpdateAllowedFileExtensionByID (API doesn't support update)
  • ✅ DELETE /JSSResource/allowedfileextensions/id/{id} - DeleteAllowedFileExtensionByID deletes an existing allowed file extension by ID
  • ✅ DELETE /JSSResource/allowedfileextensions/extension/{extensionName} - DeleteAllowedFileExtensionByNameByID deletes an existing allowed file extension by resolving its name to an ID

Departments - /JSSResource/departments

  • ✅ GET /id/{id} - GetDepartmentByID retrieves the Department by its ID.
  • ✅ GET /name/{name} - GetDepartmentByName retrieves the Department by its name.
  • ✅ GET / - GetDepartments retrieves all departments.
  • ✅ POST / - CreateDepartment creates a new Department.
  • ✅ PUT /id/{id} - UpdateDepartmentByID updates an existing Department by its ID.
  • ✅ PUT /name/{name} - UpdateDepartmentByName updates an existing Department by its name.
  • ✅ DELETE /id/{id} - DeleteDepartmentByID deletes an existing Department by its ID.
  • ✅ DELETE /name/{name} - DeleteDepartmentByName deletes an existing Department by its name.

macOS Configuration Profiles - /JSSResource/osxconfigurationprofiles

  • ✅ GET /JSSResource/osxconfigurationprofiles - GetMacOSConfigurationProfiles retrieves all macOS configuration profiles.
  • ✅ GET /JSSResource/osxconfigurationprofiles/id/{id} - GetMacOSConfigurationProfileByID retrieves the macOS configuration profile by its ID.
  • ✅ GET /JSSResource/osxconfigurationprofiles/name/{name} - GetMacOSConfigurationProfileByName retrieves the macOS configuration profile by its name.
  • ✅ POST /JSSResource/osxconfigurationprofiles/id/0 - CreateMacOSConfigurationProfile creates a new macOS configuration profile.
  • ✅ PUT /JSSResource/osxconfigurationprofiles/id/{id} - UpdateMacOSConfigurationProfileByID updates an existing macOS configuration profile by ID.
  • ✅ PUT /JSSResource/osxconfigurationprofiles/name/{name} - UpdateMacOSConfigurationProfileByName updates an existing macOS configuration profile by its name.
  • ✅ DELETE /JSSResource/osxconfigurationprofiles/id/{id} - DeleteMacOSConfigurationProfileByID deletes an existing macOS configuration profile by ID.
  • ✅ DELETE /JSSResource/osxconfigurationprofiles/name/{name} - DeleteMacOSConfigurationProfileByName deletes an existing macOS configuration profile by its name.

SSO Failover - /api/v1/sso/failover/generate

  • ✅ GET /api/v1/sso/failover - GetSSOFailoverSettings retrieves the current failover settings
  • ✅ PUT /api/v1/sso/failover/generate - UpdateFailoverUrl updates failover url, by changing failover key to new one, and returns new failover settings

Progress Summary

  • Total Endpoints: 188
  • Covered: 6
  • Not Covered: 0
  • Partially Covered: 0

Notes

  • No preview api endpoints will be covered by this sdk. Only generally available endpoints will be covered.

Directories

Path Synopsis
Migration
examples/JCDS2 command
jamfpro
jcds2.go Jamf Pro Api Work in progress.
jcds2.go Jamf Pro Api Work in progress.
deprecated
apiclient
clientHelpers.go For utility/helper functions to support from the main package
clientHelpers.go For utility/helper functions to support from the main package
examples
concurrency/OauthConcurrentSessionTester command
concurrency_tester.go
concurrency_tester.go
sdk
http_client
http_client.go
http_client.go
jamfpro
classicapi_computer_groups.go Jamf Pro Classic Api - Computer Groups api reference: https://developer.jamf.com/jamf-pro/reference/computergroups Classic API requires the structs to support an XML data structure.
classicapi_computer_groups.go Jamf Pro Classic Api - Computer Groups api reference: https://developer.jamf.com/jamf-pro/reference/computergroups Classic API requires the structs to support an XML data structure.
utils
utilities.go For utility/helper functions to support from the main package
utilities.go For utility/helper functions to support from the main package

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL