-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_cache_settings.go
78 lines (63 loc) · 2.86 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
// 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"
// ResponseCacheSettings represents the JSON response for cache settings.
type ResponseCacheSettings 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 []MemcachedEndpoint `json:"memcachedEndpoints"`
}
// MemcachedEndpoint represents an individual memcached endpoint in the cache settings.
type MemcachedEndpoint 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"`
}
// GetCacheSettings gets the current cache settings.
func (c *Client) GetCacheSettings() (*ResponseCacheSettings, error) {
endpoint := uriCacheSettings
var cacheSettings ResponseCacheSettings
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &cacheSettings)
if err != nil {
return nil, fmt.Errorf("failed to fetch cache settings: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &cacheSettings, nil
}
// UpdateCacheSettings updates the cache settings.
func (c *Client) UpdateCacheSettings(settings *ResponseCacheSettings) (*ResponseCacheSettings, error) {
endpoint := uriCacheSettings
requestBody, err := json.Marshal(settings)
if err != nil {
return nil, fmt.Errorf("failed to marshal cache settings: %v", err)
}
var updatedSettings ResponseCacheSettings
resp, err := c.HTTP.DoRequest("PUT", endpoint, requestBody, &updatedSettings)
if err != nil {
return nil, fmt.Errorf("failed to update cache settings: %v", 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.