-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_computer_inventory_collection_settings.go
129 lines (104 loc) · 5.3 KB
/
jamfproapi_computer_inventory_collection_settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// jamfproapi_computer_inventory_collection_settings.go
// Jamf Pro Api - Computer Inventory Collection Settings
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-computer-inventory-collection-settings
// Jamf Pro API requires the structs to support a JSON data structure.
package jamfpro
import (
"encoding/json"
"fmt"
)
const uriComputerInventoryCollectionSettings = "/api/v1/computer-inventory-collection-settings"
type InventoryCollectionPreference struct {
MonitorApplicationUsage bool `json:"monitorApplicationUsage"`
IncludeFonts bool `json:"includeFonts"`
IncludePlugins bool `json:"includePlugins"`
IncludePackages bool `json:"includePackages"`
IncludeSoftwareUpdates bool `json:"includeSoftwareUpdates"`
IncludeSoftwareId bool `json:"includeSoftwareId"`
IncludeAccounts bool `json:"includeAccounts"`
CalculateSizes bool `json:"calculateSizes"`
IncludeHiddenAccounts bool `json:"includeHiddenAccounts"`
IncludePrinters bool `json:"includePrinters"`
IncludeServices bool `json:"includeServices"`
CollectSyncedMobileDeviceInfo bool `json:"collectSyncedMobileDeviceInfo"`
UpdateLdapInfoOnComputerInventorySubmissions bool `json:"updateLdapInfoOnComputerInventorySubmissions"`
MonitorBeacons bool `json:"monitorBeacons"`
AllowChangingUserAndLocation bool `json:"allowChangingUserAndLocation"`
UseUnixUserPaths bool `json:"useUnixUserPaths"`
CollectUnmanagedCertificates bool `json:"collectUnmanagedCertificates"`
}
type PathItem struct {
ID string `json:"id"`
Path string `json:"path"`
}
// ComputerInventoryCollectionSettingsCustomPath defines the request body for creating a custom path.
type ComputerInventoryCollectionSettingsCustomPath struct {
Scope string `json:"scope"`
Path string `json:"path"`
}
type ResponseComputerInventoryCollectionSettings struct {
ComputerInventoryCollectionPreferences InventoryCollectionPreference `json:"computerInventoryCollectionPreferences"`
ApplicationPaths []PathItem `json:"applicationPaths"`
FontPaths []PathItem `json:"fontPaths"`
PluginPaths []PathItem `json:"pluginPaths"`
}
func (c *Client) GetComputerInventoryCollectionSettings() (*ResponseComputerInventoryCollectionSettings, error) {
endpoint := uriComputerInventoryCollectionSettings
var settings ResponseComputerInventoryCollectionSettings
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &settings)
if err != nil {
return nil, fmt.Errorf("failed to fetch computer inventory collection settings: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &settings, nil
}
// UpdateComputerInventoryCollectionSettings updates the computer inventory collection settings.
func (c *Client) UpdateComputerInventoryCollectionSettings(settings *ResponseComputerInventoryCollectionSettings) (*ResponseComputerInventoryCollectionSettings, error) {
endpoint := uriComputerInventoryCollectionSettings
// Marshal the settings into JSON for the request body
requestBody, err := json.Marshal(settings)
if err != nil {
return nil, fmt.Errorf("failed to marshal settings: %v", err)
}
// Perform the PATCH request
resp, err := c.HTTP.DoRequest("PATCH", endpoint, requestBody, nil)
if err != nil {
return nil, fmt.Errorf("failed to update computer inventory collection settings: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
// Read the response body into the same settings struct
if err := json.NewDecoder(resp.Body).Decode(&settings); err != nil {
return nil, fmt.Errorf("failed to decode response body: %v", err)
}
return settings, nil
}
// CreateComputerInventoryCollectionSettingsCustomPath creates a custom path for computer inventory collection settings.
func (c *Client) CreateComputerInventoryCollectionSettingsCustomPath(customPath *ComputerInventoryCollectionSettingsCustomPath) (*ComputerInventoryCollectionSettingsCustomPath, error) {
endpoint := fmt.Sprintf("%s/custom-path", uriComputerInventoryCollectionSettings)
var response ComputerInventoryCollectionSettingsCustomPath
resp, err := c.HTTP.DoRequest("POST", endpoint, customPath, &response)
if err != nil {
return nil, fmt.Errorf("failed to create computer inventory collection settings custom path: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// DeleteComputerInventoryCollectionSettingsCustomPathByID deletes a custom path by ID.
func (c *Client) DeleteComputerInventoryCollectionSettingsCustomPathByID(id string) error {
endpoint := fmt.Sprintf("%s/custom-path/%s", uriComputerInventoryCollectionSettings, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete computer inventory collection settings custom path: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
// Success, no error
return nil
}