Skip to content

Commit f7a7adf

Browse files
authored
Merge pull request #24 from deploymenttheory/dev
Dev
2 parents 16497bb + 59fa72a commit f7a7adf

File tree

13 files changed

+286
-91
lines changed

13 files changed

+286
-91
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ This document tracks the progress of API endpoint coverage tests. As endpoints a
167167
- [ ] ✅ DELETE `/groupid/{id}` - DeleteAccountGroupByID deletes an existing Jamf Pro Account Group by ID
168168
- [ ] ✅ DELETE `/groupname/{username}` - DeleteAccountGroupByName deletes an existing Jamf Pro Account Group by Name
169169

170+
### Activation Code - /JSSResource/activationcode
171+
172+
- [ ] ✅ GET `/JSSResource/activationcode` - GetActivationCode retrieves the current activation code and organization name.
173+
- [ ] ✅ PUT `/JSSResource/activationcode` - UpdateActivationCode updates the activation code with a new organization name and code.
174+
170175
### Jamf Pro API Integrations - /api/v1/api-integrations
171176

172177
- [ ] ✅ GET `/api/v1/api-integrations` - GetApiIntegrations fetches all API integrations.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
// Load the client OAuth credentials from the configuration file
15+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
18+
}
19+
20+
// Configuration for Jamf Pro
21+
config := jamfpro.Config{
22+
InstanceName: authConfig.InstanceName,
23+
DebugMode: true,
24+
Logger: jamfpro.NewDefaultLogger(),
25+
ClientID: authConfig.ClientID,
26+
ClientSecret: authConfig.ClientSecret,
27+
}
28+
29+
// Create a new Jamf Pro client instance
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
// Get the activation code
36+
activationCode, err := client.GetActivationCode()
37+
if err != nil {
38+
fmt.Printf("Error getting activation code: %v\n", err)
39+
return
40+
}
41+
42+
fmt.Printf("Organization Name: %s\n", activationCode.OrganizationName)
43+
fmt.Printf("Activation Code: %s\n", activationCode.Code)
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
13+
14+
// Load the client OAuth credentials from the configuration file
15+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
18+
}
19+
20+
// Configuration for Jamf Pro
21+
config := jamfpro.Config{
22+
InstanceName: authConfig.InstanceName,
23+
DebugMode: true,
24+
Logger: jamfpro.NewDefaultLogger(),
25+
ClientID: authConfig.ClientID,
26+
ClientSecret: authConfig.ClientSecret,
27+
}
28+
29+
// Create a new Jamf Pro client instance
30+
client, err := jamfpro.NewClient(config)
31+
if err != nil {
32+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
33+
}
34+
35+
// Update the activation code
36+
err = client.UpdateActivationCode("Organization Name", "ABCD-1234-A1B2-AAAA-BBBB-CCCC-DDDD-EEEE")
37+
if err != nil {
38+
fmt.Printf("Error updating activation code: %v\n", err)
39+
return
40+
}
41+
42+
fmt.Println("Activation code updated successfully")
43+
}

examples/computer_groups/CreateSmartComputerGroup/CreateSmartComputerGroup.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ func main() {
3434
}
3535

3636
// Sample data for creating a new computer group (replace with actual data as needed)
37-
newSmartGroup := &jamfpro.ComputerGroupRequest{
37+
newSmartGroup := &jamfpro.ResponseComputerGroup{
3838
Name: "NewGroupNameBySDKWithnoSiteset",
3939
IsSmart: true,
40-
Site: jamfpro.Site{ID: -1, Name: "None"}, // not required in req as can be handled in func and set to none.
41-
Criteria: []jamfpro.ComputerGroupCriterion{
40+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
41+
Criteria: []jamfpro.CriterionContainer{
4242
{
43-
Name: "Last Inventory Update",
44-
Priority: 0,
45-
AndOr: jamfpro.And,
46-
SearchType: "more than x days ago",
47-
SearchValue: "7",
43+
Size: 1,
44+
Criterion: jamfpro.ComputerGroupCriterion{
45+
Name: "Last Inventory Update",
46+
Priority: 0,
47+
AndOr: jamfpro.And,
48+
SearchType: "more than x days ago",
49+
SearchValue: "7",
50+
},
4851
},
4952
},
5053
}

examples/computer_groups/CreateStaticComputerGroup/CreateStaticComputerGroup.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,34 @@ func main() {
3434
}
3535

3636
// Define the computers for the static group
37-
computers := []jamfpro.ComputerGroupComputerItem{
37+
computers := []jamfpro.ComputerContainer{
3838
{
39-
ID: 2,
40-
Name: "MacBook Pro",
41-
MacAddress: "",
42-
AltMacAddress: "",
43-
SerialNumber: "D2FHXH22QB",
39+
Size: 1,
40+
Computer: jamfpro.ComputerGroupComputerItem{
41+
ID: 2,
42+
Name: "MacBook Pro",
43+
MacAddress: "",
44+
AltMacAddress: "",
45+
SerialNumber: "D2FHXH22QB",
46+
},
4447
},
4548
{
46-
ID: 6,
47-
Name: "MacBook Pro",
48-
MacAddress: "",
49-
AltMacAddress: "",
50-
SerialNumber: "LT6M4DTF88",
49+
Size: 1,
50+
Computer: jamfpro.ComputerGroupComputerItem{
51+
ID: 6,
52+
Name: "MacBook Pro",
53+
MacAddress: "",
54+
AltMacAddress: "",
55+
SerialNumber: "LT6M4DTF88",
56+
},
5157
},
5258
}
5359

5460
// Create a new static computer group
55-
newStaticGroup := &jamfpro.ComputerGroupRequest{
61+
newStaticGroup := &jamfpro.ResponseComputerGroup{
5662
Name: "SDK Static Group Test",
5763
IsSmart: false,
58-
Site: jamfpro.Site{ID: -1, Name: "None"},
64+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
5965
Computers: computers,
6066
}
6167

examples/computer_groups/UpdateSmartComputerGroupByID/UpdateSmartComputerGroupByID.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ func main() {
3434
}
3535

3636
// Define the computer group details for update
37-
groupUpdate := &jamfpro.ComputerGroupRequest{
37+
groupUpdate := &jamfpro.ResponseComputerGroup{
3838
Name: "UpdatedGroupName",
3939
IsSmart: true,
40-
Criteria: []jamfpro.ComputerGroupCriterion{
40+
Criteria: []jamfpro.CriterionContainer{
4141
{
42-
Name: "Last Inventory Update",
43-
Priority: 0,
44-
AndOr: jamfpro.And,
45-
SearchType: "more than x days ago",
46-
SearchValue: "7",
42+
Size: 1,
43+
Criterion: jamfpro.ComputerGroupCriterion{
44+
Name: "Last Inventory Update",
45+
Priority: 0,
46+
AndOr: jamfpro.And,
47+
SearchType: "more than x days ago",
48+
SearchValue: "7",
49+
},
4750
},
4851
},
4952
}

examples/computer_groups/UpdateSmartComputerGroupByName/UpdateSmartComputerGroupByName.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ func main() {
3434
}
3535

3636
// Define the computer group name and details for update
37-
groupName := "NewGroupNameBySDK"
38-
groupUpdate := &jamfpro.ComputerGroupRequest{
39-
Name: "UpdatedNewGroupNameBySDK",
37+
groupName := "NewGroupNameBySDKWithnoSiteset"
38+
groupUpdate := &jamfpro.ResponseComputerGroup{
39+
Name: "UpdatedGroupNameBySDKWithnoSiteset",
4040
IsSmart: true,
41-
Criteria: []jamfpro.ComputerGroupCriterion{
41+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
42+
Criteria: []jamfpro.CriterionContainer{
4243
{
43-
Name: "Last Inventory Update",
44-
Priority: 0,
45-
AndOr: jamfpro.And,
46-
SearchType: "more than x days ago",
47-
SearchValue: "7",
44+
Size: 1,
45+
Criterion: jamfpro.ComputerGroupCriterion{
46+
Name: "Last Inventory Update",
47+
Priority: 0,
48+
AndOr: jamfpro.And,
49+
SearchType: "more than x days ago",
50+
SearchValue: "7",
51+
},
4852
},
4953
},
5054
}

examples/computer_groups/UpdateStaticComputerGroupByID/UpdateStaticComputerGroupByID.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,34 @@ func main() {
3737
groupID := 49 // Replace with your actual group ID
3838

3939
// Define the updated computers for the static group
40-
updatedComputers := []jamfpro.ComputerGroupComputerItem{
40+
updatedComputers := []jamfpro.ComputerContainer{
4141
{
42-
ID: 2,
43-
Name: "MacBook Pro",
44-
MacAddress: "",
45-
AltMacAddress: "",
46-
SerialNumber: "D2FCKL22FH",
42+
Size: 1,
43+
Computer: jamfpro.ComputerGroupComputerItem{
44+
ID: 2,
45+
Name: "MacBook Pro",
46+
MacAddress: "",
47+
AltMacAddress: "",
48+
SerialNumber: "D2FHXH22QB",
49+
},
50+
},
51+
{
52+
Size: 1,
53+
Computer: jamfpro.ComputerGroupComputerItem{
54+
ID: 6,
55+
Name: "MacBook Pro",
56+
MacAddress: "",
57+
AltMacAddress: "",
58+
SerialNumber: "LT6M4DTF88",
59+
},
4760
},
48-
// ... add more updated computers if needed
4961
}
5062

5163
// Create the updated static computer group data
52-
updatedStaticGroup := &jamfpro.ComputerGroupRequest{
64+
updatedStaticGroup := &jamfpro.ResponseComputerGroup{
5365
Name: "Updated Static Group Name",
5466
IsSmart: false,
55-
Site: jamfpro.Site{ID: -1, Name: "None"},
67+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
5668
Computers: updatedComputers,
5769
}
5870

examples/computer_groups/UpdateStaticComputerGroupByName/UpdateStaticComputerGroupByName.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,34 @@ func main() {
3737
groupName := "Updated Static Group Name" // Replace with your actual group name
3838

3939
// Define the updated computers for the static group
40-
updatedComputers := []jamfpro.ComputerGroupComputerItem{
40+
updatedComputers := []jamfpro.ComputerContainer{
4141
{
42-
ID: 2,
43-
Name: "MacBook Pro",
44-
MacAddress: "",
45-
AltMacAddress: "",
46-
SerialNumber: "D2FCXH22QW",
42+
Size: 1,
43+
Computer: jamfpro.ComputerGroupComputerItem{
44+
ID: 2,
45+
Name: "MacBook Pro",
46+
MacAddress: "",
47+
AltMacAddress: "",
48+
SerialNumber: "D2FHXH22QB",
49+
},
50+
},
51+
{
52+
Size: 1,
53+
Computer: jamfpro.ComputerGroupComputerItem{
54+
ID: 6,
55+
Name: "MacBook Pro",
56+
MacAddress: "",
57+
AltMacAddress: "",
58+
SerialNumber: "LT6M4DTF88",
59+
},
4760
},
48-
// ... add more updated computers if needed
4961
}
5062

5163
// Create the updated static computer group data
52-
updatedStaticGroup := &jamfpro.ComputerGroupRequest{
64+
updatedStaticGroup := &jamfpro.ResponseComputerGroup{
5365
Name: "Static Group Name",
5466
IsSmart: false,
55-
Site: jamfpro.Site{ID: -1, Name: "None"},
67+
Site: jamfpro.ComputerGroupSite{ID: -1, Name: "None"},
5668
Computers: updatedComputers,
5769
}
5870

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// classicapi_activation_code.go
2+
// Jamf Pro Classic Api - activationcode
3+
// api reference: https://developer.jamf.com/jamf-pro/reference/activationcode
4+
// Classic API requires the structs to support an XML data structure.
5+
6+
package jamfpro
7+
8+
import (
9+
"encoding/xml"
10+
"fmt"
11+
)
12+
13+
const uriAPIActivationCode = "/JSSResource/activationcode"
14+
15+
// ResponseActivationCode represents the structure of the response for an activation code.
16+
type ResponseActivationCode struct {
17+
OrganizationName string `xml:"organization_name"`
18+
Code string `xml:"code"`
19+
}
20+
21+
// GetActivationCode retrieves the activation code.
22+
func (c *Client) GetActivationCode() (*ResponseActivationCode, error) {
23+
endpoint := uriAPIActivationCode
24+
25+
var activationCode ResponseActivationCode
26+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &activationCode)
27+
if err != nil {
28+
return nil, fmt.Errorf("failed to fetch activation code: %v", err)
29+
}
30+
31+
if resp != nil && resp.Body != nil {
32+
defer resp.Body.Close()
33+
}
34+
35+
return &activationCode, nil
36+
}
37+
38+
// UpdateActivationCode updates the activation code.
39+
func (c *Client) UpdateActivationCode(organizationName, code string) error {
40+
endpoint := uriAPIActivationCode
41+
42+
requestBody := struct {
43+
XMLName xml.Name `xml:"activation_code"`
44+
ResponseActivationCode
45+
}{
46+
ResponseActivationCode: ResponseActivationCode{
47+
OrganizationName: organizationName,
48+
Code: code,
49+
},
50+
}
51+
52+
_, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, nil)
53+
if err != nil {
54+
return fmt.Errorf("failed to update activation code: %v", err)
55+
}
56+
57+
return nil
58+
}

0 commit comments

Comments
 (0)