-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_cache_settings.go
83 lines (65 loc) · 3.04 KB
/
jamfproapi_cache_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
// jamfapi_cache_settings.go
// Jamf Pro Api - Cache Settings
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-cache-settings
// Jamf Pro API requires the structs to support a JSON data structure.
package jamfpro
import (
"encoding/json"
"fmt"
)
const uriCacheSettings = "/api/v1/cache-settings"
// Resource
// ResponseCacheSettings represents the JSON response for cache settings.
type ResourceCacheSettings struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CacheType string `json:"cacheType"`
TimeToLiveSeconds int `json:"timeToLiveSeconds"`
TimeToIdleSeconds int `json:"timeToIdleSeconds"`
DirectoryTimeToLiveSeconds int `json:"directoryTimeToLiveSeconds,omitempty"`
EhcacheMaxBytesLocalHeap string `json:"ehcacheMaxBytesLocalHeap,omitempty"`
CacheUniqueId string `json:"cacheUniqueId"`
Elasticache bool `json:"elasticache,omitempty"`
MemcachedEndpoints []CacheSettingsSubsetMemcachedEndpoints `json:"memcachedEndpoints"`
}
// Subsets
type CacheSettingsSubsetMemcachedEndpoints struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
HostName string `json:"hostName,omitempty"`
Port int `json:"port,omitempty"`
Enabled bool `json:"enabled,omitempty"`
JSSCacheConfigurationID int `json:"jssCacheConfigurationId,omitempty"`
}
// CRUD
// GetCacheSettings gets the current cache settings.
func (c *Client) GetCacheSettings() (*ResourceCacheSettings, error) {
endpoint := uriCacheSettings
var cacheSettings ResourceCacheSettings
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &cacheSettings)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "cache settings", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &cacheSettings, nil
}
// UpdateCacheSettings updates the cache settings.
func (c *Client) UpdateCacheSettings(cacheSettingsUpdate *ResourceCacheSettings) (*ResourceCacheSettings, error) {
endpoint := uriCacheSettings
requestBody, err := json.Marshal(cacheSettingsUpdate)
if err != nil {
return nil, fmt.Errorf(errMsgFailedJsonMarshal, "cache settings", err)
}
var updatedSettings ResourceCacheSettings
resp, err := c.HTTP.DoRequest("PUT", endpoint, requestBody, &updatedSettings)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdate, "cache settings", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedSettings, nil
}
// Please note that the Create and Delete functions are not implemented here as cache settings typically only allow retrieval and update operations.