Skip to content

unravelin/jamf-api-client-go

 
 

Repository files navigation

jamf-api-client-go

This repository contains an unoffical Go API client for Jamf REST API's.

To see what functionality is available in the current API client release, please see the API Coverage doc.

Disclaimers

  • The API client remains in active development and has no affiliation to Jamf
  • This is not an official Jamf API client
  • The client is not formally supported by Datadog and the code is available as-is

Contribution is welcome and appreciated! 🚀 💜

Usage

Classic API Authentication

If you server version requires Bearer Token Authentication you can pass the WithTokenAuth() option to your client constructor

import  jamf "github.com/DataDog/jamf-api-client-go/classic"

// Create a client instance to interact with API and enable bearer token authentication
j, err := jamf.NewClient("https://jamf.example.com", "YOUR_API_USER", "YOUR_USERS_PASSWORD_HERE", nil, jamf.WithTokenAuth())
if err != nil {
  os.Exit(1)
}

Full Example

import  jamf "github.com/DataDog/jamf-api-client-go/classic"

// You can optionally setup a custom HTTP client to use which can
// include any settings you desire. If you would like to use the 
// default client configuration just pass nil. This will default 
// to a client that is simply configured with a timeout of 1 minute
myCustomHTTPClient := &http.Client{
  Timeout: time.Minute,
}

// Create a client instance to interact with API
j, err := jamf.NewClient("https://jamf.example.com", "YOUR_API_USER", "YOUR_USERS_PASSWORD_HERE", myCustomHTTPClient)
if err != nil {
  fmt.Println(err.Error())
  os.Exit(1)
}

// Example: Get All Computers
computers, err := j.Computers()
if err != nil {
  os.Exit(1)
}

// Example: Create Script
newScript := &jamf.ScriptContents{
  Name: "Script with API Creation",
}
s, err := j.CreateScript(newScript)
if err != nil {
  os.Exit(1)
}

// Example: Get Script Details
scriptDetails, err := j.ScriptDetails(37)
if err != nil {
  os.Exit(1)
}

More examples available here

Tests

Unit tests should exist for all endpoints and pass successfully prior to being checked into the main branch

go test -v ./... or make test

Alternatively, make pr-prep can be run to execute all tests, formatting, and linting

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.8%
  • Makefile 1.2%