-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from deploymenttheory/dev
Dev
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
examples/jamf_api_privileges/GetAPIRolePrivByName/GetAPIRolePrivByName.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 inside the main function | ||
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json" | ||
|
||
// Load the client OAuth credentials from the configuration file | ||
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath) | ||
if err != nil { | ||
log.Fatalf("Failed to load client OAuth configuration: %v", err) | ||
} | ||
|
||
// Configuration for the jamfpro | ||
config := jamfpro.Config{ | ||
InstanceName: authConfig.InstanceName, | ||
DebugMode: true, | ||
Logger: jamfpro.NewDefaultLogger(), | ||
ClientID: authConfig.ClientID, | ||
ClientSecret: authConfig.ClientSecret, | ||
} | ||
|
||
// Create a new jamfpro client instance | ||
client, err := jamfpro.NewClient(config) | ||
if err != nil { | ||
log.Fatalf("Failed to create Jamf Pro client: %v", err) | ||
} | ||
|
||
// Fetch API role privileges by name | ||
name := "Read API Roles" // Replace with the privilege name you want to search for | ||
limit := 15 // Replace with your desired limit for results | ||
apiPrivileges, err := client.GetJamfAPIPrivilegesByName(name, limit) | ||
if err != nil { | ||
log.Fatalf("Error fetching API role privileges by name: %v", err) | ||
} | ||
|
||
// Pretty print the fetched API role privileges using JSON marshaling | ||
privilegesJSON, err := json.MarshalIndent(apiPrivileges, "", " ") // Indent with 4 spaces | ||
if err != nil { | ||
log.Fatalf("Error marshaling API role privileges data: %v", err) | ||
} | ||
fmt.Println("Fetched API Role Privileges by Name:", string(privilegesJSON)) | ||
} |
48 changes: 48 additions & 0 deletions
48
examples/jamf_api_privileges/GetJamfAPIPrivileges/GetJamfAPIPrivileges.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 inside the main function | ||
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json" | ||
|
||
// Load the client OAuth credentials from the configuration file | ||
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath) | ||
if err != nil { | ||
log.Fatalf("Failed to load client OAuth configuration: %v", err) | ||
} | ||
|
||
// Configuration for the jamfpro | ||
config := jamfpro.Config{ | ||
InstanceName: authConfig.InstanceName, | ||
DebugMode: true, | ||
Logger: jamfpro.NewDefaultLogger(), | ||
ClientID: authConfig.ClientID, | ||
ClientSecret: authConfig.ClientSecret, | ||
} | ||
|
||
// Create a new jamfpro client instance | ||
client, err := jamfpro.NewClient(config) | ||
if err != nil { | ||
log.Fatalf("Failed to create Jamf Pro client: %v", err) | ||
} | ||
|
||
// Fetch API role privileges | ||
apiPrivileges, err := client.GetJamfAPIPrivileges() | ||
if err != nil { | ||
log.Fatalf("Error fetching API role privileges: %v", err) | ||
} | ||
|
||
// Pretty print the fetched API role privileges using JSON marshaling | ||
privilegesJSON, err := json.MarshalIndent(apiPrivileges, "", " ") // Indent with 4 spaces | ||
if err != nil { | ||
log.Fatalf("Error marshaling API role privileges data: %v", err) | ||
} | ||
fmt.Println("Fetched API Role Privileges:", string(privilegesJSON)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// jamfproapi_api_role_privileges.go | ||
// Jamf Pro Api - API Role Privileges | ||
// API reference: https://developer.jamf.com/jamf-pro/reference/api-role-privileges | ||
// Jamf Pro API requires the structs to support a JSON data structure. | ||
|
||
package jamfpro | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
const uriApiRolePrivileges = "/api/v1/api-role-privileges" | ||
|
||
// ResponseApiRolePrivileges represents the structure of the response for fetching API role privileges | ||
type ResponseApiRolePrivileges struct { | ||
Privileges []string `json:"privileges"` | ||
} | ||
|
||
// GetJamfAPIPrivileges fetches a list of Jamf API role privileges | ||
func (c *Client) GetJamfAPIPrivileges() (*ResponseApiRolePrivileges, error) { | ||
var privilegesList ResponseApiRolePrivileges | ||
resp, err := c.HTTP.DoRequest("GET", uriApiRolePrivileges, nil, &privilegesList) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch Jamf API role privileges: %v", err) | ||
} | ||
|
||
if resp != nil && resp.Body != nil { | ||
defer resp.Body.Close() | ||
} | ||
|
||
return &privilegesList, nil | ||
} | ||
|
||
// GetJamfAPIPrivilegesByName fetches a list of Jamf API role privileges by name | ||
func (c *Client) GetJamfAPIPrivilegesByName(name string, limit int) (*ResponseApiRolePrivileges, error) { | ||
// Encode the name parameter to handle special characters | ||
encodedName := url.QueryEscape(name) | ||
|
||
// Construct the URL with the provided name and limit | ||
endpoint := fmt.Sprintf(uriApiRolePrivileges+"/search?name=%s&limit=%d", encodedName, limit) | ||
|
||
var privilegesList ResponseApiRolePrivileges | ||
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &privilegesList) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch Jamf API role privileges by name: %v", err) | ||
} | ||
|
||
if resp != nil && resp.Body != nil { | ||
defer resp.Body.Close() | ||
} | ||
|
||
return &privilegesList, nil | ||
} |